uniqc.algorithms.workflows.classical_shadow_workflow module

High-level classical-shadow workflow.

Wraps uniqc.algorithms.core.measurement.classical_shadow.classical_shadow() and shadow_expectation() so that the user can request multiple Pauli expectations from a single shadow dataset in one call.

class uniqc.algorithms.workflows.classical_shadow_workflow.ShadowWorkflowResult(snapshots, expectations=<factory>, n_snapshots=0)[source]

Bases: object

Outcome of run_classical_shadow_workflow().

Variables:
Parameters:
expectations: dict[str, float]
n_snapshots: int = 0
snapshots: list[ShadowSnapshot]
uniqc.algorithms.workflows.classical_shadow_workflow.run_classical_shadow_workflow(circuit, pauli_observables, *, shots=1000, n_shadow=None, qubits=None)[source]

Collect a classical-shadow dataset and estimate multiple observables.

Parameters:
  • circuit (Circuit) – Quantum circuit. Must contain measurements on every qubit that participates in any of pauli_observables.

  • pauli_observables (Sequence[str]) – Pauli strings to estimate. All must have the same length and that length must equal the circuit’s qubit count.

  • shots (int) – Shots per snapshot forwarded to classical_shadow.

  • n_shadow (int | None) – Optional number of distinct snapshots forwarded to classical_shadow. None defaults to that function’s built-in default.

  • qubits (list[int] | None) – Optional qubit subset forwarded to classical_shadow.

Returns:

ShadowWorkflowResult with both the raw snapshots and the per-observable estimates.

Return type:

ShadowWorkflowResult

Example

>>> from uniqc.circuit_builder import Circuit
>>> from uniqc.algorithms.workflows import classical_shadow_workflow as csw
>>> c = Circuit(); c.h(0); c.cx(0, 1); c.measure(0); c.measure(1)
>>> r = csw.run_classical_shadow_workflow(
...     c, ["ZZ", "XX"], shots=500
... )
>>> abs(r.expectations["ZZ"] - 1.0) < 0.5
True
uniqc.algorithms.workflows.classical_shadow_workflow.run_classical_shadow_workflow_example()[source]

Bell-state shadow estimation for ZZ and XX observables.

Return type:

ShadowWorkflowResult