qarp.resources¶
Resource metrics: compiled circuit → stage-explicit resource vectors.
from qarp.resources import estimate report = estimate(block, gateset=qx.clifford_t_rz_gateset(), device=dev) report[Stage.ROUTED].swap_count
The frozen, SCHEMA_VERSION-pinned wire format (ResourceVector,
Stage, Provenance), its producer (ResourceEstimator / estimate),
the ResourceModeler extension point (no in-tree implementer) and
ε-approximate Rz → Clifford+T synthesis (synthesize_clifford_t, optional
pygridsynth dependency). Public depth: flat. Submodules are private.
- class qarp.resources.Provenance(stage: Stage, gateset: str | None = None, opt_level: str | None = None, router: str | None = None, device: str | None = None, modeler: str | None = None, synthesis: str | None = None)[source]¶
Bases:
objectWhat produced the numbers — makes every vector self-describing.
- class qarp.resources.ResourceEstimator(*, gateset: GateSet | None = None, opt_level: OptLevel = OptLevel.O1, device: Device | None = None, router: RouterKind = RouterKind.Sabre, modeler: ResourceModeler | None = None, device_label: str | None = None, synthesis_epsilon: float | None = None)[source]¶
Bases:
objectEstimate resources of a block or command stream, stage by stage.
Stages produced: LOGICAL always; OPTIMIZED when a
gatesetis given; ROUTED and TARGET when adevicewith an architecture is also given (routing requires the rebase, sodeviceimpliesgateset); SYNTHESIZED whensynthesis_epsilonis given (requires the Clifford+T+Rz gate set — the Clifford+T+Rz intermediate gridsynth consumes). Themodelerruns on the final stage only, where the target-gate-set circuit is known.- estimate(source: Block | Sequence[Command]) ResourceReport[source]¶
- class qarp.resources.ResourceModeler(*args, **kwargs)[source]¶
Bases:
ProtocolFills modeled fields of a final-stage
ResourceVector.- model(commands: Sequence[Command], vector: ResourceVector) ResourceVector[source]¶
- class qarp.resources.ResourceReport(stages: dict[Stage, ResourceVector])[source]¶
Bases:
Mapping[Stage,ResourceVector]Per-stage vectors in pipeline order;
finalis the last stage.- property final: ResourceVector¶
- class qarp.resources.ResourceVector(n_qubits: int, depth: int, n_gates: int, n_1q: int, n_2q: int, n_3q_plus: int, n_measurements: int, n_resets: int, t_count: int | None, swap_count: int | None, op_histogram: dict[str, int], provenance: ~qarp.resources._vector.Provenance, t_count_modeled: float | None = None, extras: dict[str, float] = <factory>)[source]¶
Bases:
objectOne stage snapshot of a circuit’s resources.
n_qubitsis the logical width before routing and the physical device width at ROUTED/TARGET.n_gatescounts unitary operations only (barriers, global phases, branch markers, measurements and resets are excluded). The arity buckets partition it exactly:n_1q + n_2q + n_3q_plus == n_gatesat every stage.swap_countis router-inserted overhead, defined only at ROUTED (user-authored SWAPs appear inop_histogramandn_2qat every stage).- provenance: Provenance¶
- class qarp.resources.Stage(*values)[source]¶
-
Compilation stage a
ResourceVectorsnapshot describes.- LOGICAL = 'logical'¶
- OPTIMIZED = 'optimized'¶
- ROUTED = 'routed'¶
- SYNTHESIZED = 'synthesized'¶
- TARGET = 'target'¶
- qarp.resources.count_resources(source: Sequence[Command] | CircuitDAG, *, provenance: Provenance, n_qubits: int | None = None) ResourceVector[source]¶
Count a circuit snapshot into a
ResourceVector.n_qubitsoverrides the inferred width (needed for idle qubits: the DAG infers max-wire+1, a block or device may be wider).swap_countis populated only whenprovenance.stage is Stage.ROUTED;t_countonly when no parametric, opaque, or width >= 3MCZunitary remains. Gates inside branch regions count unconditionally (worst-case).
- qarp.resources.estimate(source: Block | Sequence[Command], *, gateset: GateSet | None = None, opt_level: OptLevel = OptLevel.O1, device: Device | None = None, router: RouterKind = RouterKind.Sabre, modeler: ResourceModeler | None = None, device_label: str | None = None, synthesis_epsilon: float | None = None) ResourceReport[source]¶
One-liner facade over
ResourceEstimator.
- qarp.resources.synthesize_clifford_t(commands: Sequence[Command], *, epsilon: float) list[Command][source]¶
Replace every Rz in a Clifford+T+Rz-format stream by a Clifford+T sequence.
Each output sequence is within
epsilonof its exact rotation in operator norm, global phase included; all other gates of the set pass through untouched, so the stream’s unitary is preserved tom·εformsynthesized rotations. RaisesValueErroron symbolic angles or on gates outside the Clifford+T+Rz gate set (rebase first).
- qarp.resources.SCHEMA_VERSION = 1¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4