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: object

What produced the numbers — makes every vector self-describing.

device: str | None = None
gateset: str | None = None
modeler: str | None = None
opt_level: str | None = None
router: str | None = None
stage: Stage
synthesis: str | None = None
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: object

Estimate resources of a block or command stream, stage by stage.

Stages produced: LOGICAL always; OPTIMIZED when a gateset is given; ROUTED and TARGET when a device with an architecture is also given (routing requires the rebase, so device implies gateset); SYNTHESIZED when synthesis_epsilon is given (requires the Clifford+T+Rz gate set — the Clifford+T+Rz intermediate gridsynth consumes). The modeler runs 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: Protocol

Fills modeled fields of a final-stage ResourceVector.

model(commands: Sequence[Command], vector: ResourceVector) ResourceVector[source]
property name: str
class qarp.resources.ResourceReport(stages: dict[Stage, ResourceVector])[source]

Bases: Mapping[Stage, ResourceVector]

Per-stage vectors in pipeline order; final is the last stage.

property final: ResourceVector
property stages: tuple[Stage, ...]
to_dict() dict[str, Any][source]
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: object

One stage snapshot of a circuit’s resources.

n_qubits is the logical width before routing and the physical device width at ROUTED/TARGET. n_gates counts 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_gates at every stage. swap_count is router-inserted overhead, defined only at ROUTED (user-authored SWAPs appear in op_histogram and n_2q at every stage).

depth: int
extras: dict[str, float]
classmethod from_dict(d: dict[str, Any]) ResourceVector[source]
n_1q: int
n_2q: int
n_3q_plus: int
n_gates: int
n_measurements: int
n_qubits: int
n_resets: int
op_histogram: dict[str, int]
provenance: Provenance
swap_count: int | None
t_count: int | None
t_count_modeled: float | None = None
to_dict() dict[str, Any][source]

Wire format (schema pinned by test_vector.py’s golden test).

with_model(*, modeler: str, t_count_modeled: float | None, extras: dict[str, float]) ResourceVector[source]

Copy with modeler-filled fields set (the only sanctioned mutation).

class qarp.resources.Stage(*values)[source]

Bases: str, Enum

Compilation stage a ResourceVector snapshot 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_qubits overrides the inferred width (needed for idle qubits: the DAG infers max-wire+1, a block or device may be wider). swap_count is populated only when provenance.stage is Stage.ROUTED; t_count only when no parametric, opaque, or width >= 3 MCZ unitary 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 epsilon of 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 to m·ε for m synthesized rotations. Raises ValueError on 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