iqm.cpc.compiler.compiler.Compiler#
- class iqm.cpc.compiler.compiler.Compiler(*, calibration_set, chip_topology, channel_properties, component_channels, component_mapping=None, options=CircuitExecutionOptions(measurement_mode=<MeasurementMode.ALL: 'all'>, heralding_mode=<HeraldingMode.NONE: 'none'>, dd_mode=<DDMode.DISABLED: 'disabled'>, dd_strategy=None, circuit_boundary_mode=<CircuitBoundaryMode.ALL: 'all'>, move_gate_validation=<MoveGateValidationMode.STRICT: 'strict'>, move_gate_frame_tracking=<MoveGateFrameTrackingMode.FULL: 'full'>, active_reset_cycles=None), stages=None, strict=False)#
Bases:
object
Stateful object that contains a calibration set, a schedule builder, and a set of compilation stages.
The compiler’s state does not include the data to be compiled.
- Parameters:
calibration_set (CalibrationSet) – Calibration data.
chip_topology (ChipTopology) – Physical layout and connectivity of the quantum chip.
channel_properties (dict[str, ChannelProperties]) – Channel properties.
component_channels (dict[str, dict[str, str]]) – Mapping between components and their control channels.
component_mapping (dict[str, str] | None) – Custom mapping of components. Defaults to None.
options (CircuitExecutionOptions) – Circuit execution options. Defaults to STANDARD_CIRCUIT_EXECUTION_OPTIONS.
stages (list[CompilationStage] | None) – List of compilation stages. Defaults to None. Note that in the absence of stages, the compiler will not be ready to compile circuits.
strict (bool) – If True, raises CalibrationError on calibration validation failures. If False, only logs warnings. Defaults to False.
- Raises:
CalibrationError – When strict=True and calibration validation fails during compiler initialization.
Attributes
Registered quantum gates.
Methods
_refresh
()Refresh the compiler by re-creating the ScheduleBuilder and validating the calibration.
add_implementation
(op_name, impl_name, ...)Adds a new implementation of a quantum operation (gate).
Update the current local calibration set with calibration values for a specific gate/implementation/locus.
build_settings
(context, shots)Build the settings for the execution.
compile
(data[, context])Run all compiler stages.
Return initial compiler context dictionary.
Returns a copy of the current local calibration set.
Prints all implementations of all currently known quantum operations (gates), including parameters
Prints all implementation of a particular quantum operation (gate).
ready
()Check if the compiler is ready to compile circuits.
set_calibration
(calibration)Sets the current calibration set to a given calibration set, then refreshes the compiler.
set_default_implementation
(gate_name, ...)Set the default implementation of a gate.
Set the default implementation for a gate for a specific loci.
show_stages
([full])Print the stages and passes defined in the compiler.
- get_calibration()#
Returns a copy of the current local calibration set.
- set_calibration(calibration)#
Sets the current calibration set to a given calibration set, then refreshes the compiler.
- set_default_implementation(gate_name, implementation_name)#
Set the default implementation of a gate.
- set_default_implementation_for_loci(gate_name, implementation_name, loci)#
Set the default implementation for a gate for a specific loci.
- amend_calibration_for_gate_implementation(gate_name, impl_name, locus, params)#
Update the current local calibration set with calibration values for a specific gate/implementation/locus.
The calibration values are given as a dictionary of parameter names and their values. This method refreshes the compiler after amending the calibration set.
- Parameters:
gate_name (str) – Name of the gate to which the calibration values are applied.
impl_name (str) – Name of the implementation of the gate to which the calibration values are applied.
locus (tuple[str, ...]) – Locus of the gate to which the calibration values are applied.
params (dict[str, Any]) – Updated parameter names and their values.
- Return type:
None
- add_implementation(op_name, impl_name, implementation, *, set_as_default=False, overwrite=False, quantum_op_specs=None)#
Adds a new implementation of a quantum operation (gate).
Refreshes the compiler after adding a new implementation.
- Parameters:
op_name (str) – The gate name for which to register a new implementation.
impl_name (str) – The “human-readable” name with which the new gate implementation will be found e.g. in settings.
implementation (type[GateImplementation]) – The python class of the new gate implementation to be added.
set_as_default (bool) – Whether to set the new implementation as the default implementation for the gate.
overwrite (bool) – If True, allows replacing any existing implementation of the same name.
quantum_op_specs (QuantumOp | dict | None) – The quantum operation this gate represents. If a QuantumOp is given, it is used as is. If None is given and the same gate has been registered before, the previously registered properties are used. Otherwise, the given dict values are given to the constructor of
QuantumOp
. For any missing constructor values, some defaults suitable for a 1-QB gate are used.
- Return type:
None
- ready()#
Check if the compiler is ready to compile circuits. The compiler is ready if at least one stage is defined, and all the stages are non-empty.
- Return type:
- print_all_implementations_trees()#
Prints all implementations of all currently known quantum operations (gates), including parameters
- Return type:
None
- print_implementations_trees(op)#
Prints all implementation of a particular quantum operation (gate).
- Parameters:
op (QuantumOp) – Quantum operation (gate) to print implementations of.
- Return type:
None
- show_stages(full=False)#
Print the stages and passes defined in the compiler.
- Parameters:
full (bool) – Iff True, also print the docstring of each pass function.
- Return type:
None
- compiler_context()#
Return initial compiler context dictionary. Used automatically by
Compiler.compile()
.
- compile(data, context=None)#
Run all compiler stages. Initial context will be derived from
Compiler.compiler_context()
unless a custom context dictionary is provided.
- build_settings(context, shots)#
Build the settings for the execution. Updates context[“circuit_metrics”] with schedule_duration and min_execution_time.