Skip to content

loqs.backends.reps

Gate/instrument operation representation classes.

An operation representation (OperationRep) describes how a gate or instrument (mid-circuit measurement) operation should be applied to a state: e.g. as a unitary matrix, a set of Kraus operators, or a STIM circuit string. GateRep and InstrumentRep are the abstract base classes for gate-level and instrument-level representations, respectively; each concrete subclass (e.g. UnitaryGateRep, KrausGateRep, ZBasisProjectionInstrumentRep) carries its own descriptive, named payload field(s) rather than a single untyped rep attribute paired with an enum tag.

convert() converts a raw, unwrapped payload or an already-constructed OperationRep into a requested target class (or the closest of several candidate classes), via matches/from_raw and/or a shortest-path search over a registry of pairwise numeric/structural converters between concrete classes (e.g. UnitaryGateRep to PTMGateRep to KrausGateRep).

StimCircuitPayloadMixin factors out the storage/construction logic shared by StimCircuitGateRep and StimCircuitInstrumentRep, which otherwise sit in unrelated branches of the GateRep/ InstrumentRep hierarchy but wrap the exact same STIM circuit-string payload shape.

STANDARD_GATE_UNITARIES is a small, fixed set of well-known single/two-qubit gate unitaries (used internally to build the N-qubit Pauli basis the pure-numpy GateRep conversions are built on), exposed publicly so other callers needing common gate matrices don't need a second hand-copied set.