mimiqcircuits.backends.compiled¶
Compiled-circuit types and the metadata they carry.
LocalBackend.compile() turns a Circuit into a
backend-specific CompiledCircuit. The compile step must be
pure: no randomness, no sampling. Per-trajectory random work belongs in
LocalBackend.prepare_trajectory().
Every compiled circuit carries a CompileMetadata, read through
its metadata attribute, for compile-time information such as
measurement analysis and qubit permutations.
Concrete types:
DefaultCompiledCircuitwraps an artifact as it is, for backends whose compile step returns the final form directly.CompiledParametricCircuitwraps a circuit that still has free symbolic parameters;LocalBackend.bind()resolves them.
Classes
|
Compile-time information carried by a |
Base class for the backend-specific form of a circuit. |
|
|
Compiled circuit that still has free symbolic parameters. |
|
Compiled circuit that wraps an artifact as it is. |
Exceptions
|
Error for a circuit with free symbolic parameters on a backend that does not declare the |
- class CompileMetadata(measures=<factory>, active_qubits=<factory>, qubit_flips=<factory>, initial_layout=None, final_layout=None, measure_action_counts=<factory>, prefix_endpoint=0)[source]¶
Bases:
objectCompile-time information carried by a
CompiledCircuit.Backends fill in the fields that apply to them and leave the others at their defaults. The execute driver of
LocalBackenddoes not read them.- measures¶
Measurement-analysis entries, one per classical bit, classifying it as unused, read directly, read flipped, or constant 0 or 1. Empty when no analysis ran.
- Type:
- active_qubits¶
Qubits that must be simulated; the others are known to be in
|0⟩when measured.
- initial_layout¶
Where the pass pipeline put each qubit of the input circuit before the first instruction, 0-based, or
Nonewhen the qubits keep their indices. SeePassResult.
- measure_action_counts¶
Number of bits in each measurement-analysis class, for debugging.
- prefix_endpoint¶
Index of the last instruction in the deterministic prefix, when the backend splits the circuit into a deterministic prefix and a random suffix;
0otherwise.- Type:
Examples
>>> from mimiqcircuits import * >>> from mimiqcircuits.backends import CompileMetadata >>> meta = CompileMetadata(active_qubits=[0, 1]) >>> meta.active_qubits, meta.final_layout ([0, 1], None)
- class CompiledCircuit[source]¶
Bases:
objectBase class for the backend-specific form of a circuit.
Returned by
LocalBackend.compile()and run byLocalBackend.evolve(). Backends subclass it to carry whatever they need: an MPO for an MPS simulator, a plainCircuitfor a state-vector simulator, and so on. Subclasses implementmetadataandsource;DefaultCompiledCircuitdoes both and fits most backends.- property metadata: CompileMetadata¶
The
CompileMetadataof this compiled circuit.
- property source¶
The backend-specific artifact wrapped by this compiled circuit (for example a
Circuitor an MPO).
- class DefaultCompiledCircuit(_source, _metadata=<factory>)[source]¶
Bases:
CompiledCircuitCompiled circuit that wraps an artifact as it is.
Use it when the backend’s compile step has nothing to lower, for example a state-vector simulator that runs the input
Circuitdirectly.- Parameters:
_metadata (CompileMetadata) – The
CompileMetadata, returned bymetadata. Defaults to an empty one.
Examples
>>> from mimiqcircuits import * >>> from mimiqcircuits.backends import DefaultCompiledCircuit >>> c = Circuit().push(GateH(), 0) >>> compiled = DefaultCompiledCircuit(c) >>> compiled.source is c True >>> compiled.metadata.active_qubits []
- property metadata: CompileMetadata¶
The
CompileMetadatagiven at construction.
- property source¶
The wrapped artifact.
- class CompiledParametricCircuit(_source, _metadata=<factory>)[source]¶
Bases:
CompiledCircuitCompiled circuit that still has free symbolic parameters.
A backend that declares the
"parametric"capability can return it fromLocalBackend.compile()for a symbolic circuit.LocalBackend.bind()resolves the parameters.- Parameters:
_source (Any) – The symbolic
Circuit, kept so thatLocalBackend.bind()can evaluate it._metadata (CompileMetadata) – The
CompileMetadata. Defaults to an empty one.
- property metadata: CompileMetadata¶
The
CompileMetadatagiven at construction.
- property source¶
The symbolic circuit.
- exception UnboundSymbolicError(backend_name)[source]¶
Bases:
ExceptionError for a circuit with free symbolic parameters on a backend that does not declare the
"parametric"capability.Backends raise it from
LocalBackend.compile().- Parameters:
backend_name (str) – Name of the backend, kept as
backend_name.