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, convert_terminal_measurements=True), stages=None, pp_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]) – Control channel properties for the station.
component_channels (dict[str, dict[str, str]]) – Mapping from QPU component name to a mapping from
('drive', 'flux', 'readout')
to the name of the control channel responsible for that function of the component.component_mapping (dict[str, str] | None) – Mapping of logical QPU component names to physical QPU component names.
None
means the identity mapping.options (CircuitExecutionOptions) – Circuit execution options. Defaults to STANDARD_CIRCUIT_EXECUTION_OPTIONS.
stages (Collection[CompilationStage] | None) – Compilation stages to use.
None
means none. Note that meaningful circuit compilation requires at least some stages.pp_stages (Collection[CompilationStage] | None) – Post-processing stages to use.
None
means none.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 for 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.
postprocess
(data[, context])Run all post-processing stages.
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.
run_stages
(stages, data, context)Run the given stages in given order on the given data.
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, impl_class, *, set_as_default=False, overwrite=False, quantum_op=None)#
Adds a new implementation for a quantum operation (gate).
Refreshes the compiler after adding a new implementation.
- Parameters:
op_name (str) – The name of the quantum operation for which to register a new implementation.
impl_name (str) – The “human-readable” name with which the new implementation will be found e.g. in settings.
impl_class (type[GateImplementation]) – The class of the new implementation to be added.
set_as_default (bool) – Whether to set the new implementation as the default implementation for the operation.
overwrite (bool) – If True, replaces any existing implementation of the same name for the operation.
quantum_op (QuantumOp | 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. Existing operations cannot be replaced or modified.
- 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
- compile(data, context=None)#
Run all compiler stages.
Initial context will be derived using
compiler_context()
unless a custom context dictionary is provided.
- postprocess(data, context=None)#
Run all post-processing stages.
Initial context will be derived using
compiler_context()
unless a custom context dictionary is provided.
- run_stages(stages, data, context)#
Run the given stages in given order on the given data.
- Parameters:
stages (Collection[CompilationStage]) – Stages to run on
data
.context (dict[str, Any]) – Additional information that is passed to the first stage. Each stage may make modifications to
context
before it is passed to the next stage.
- Returns:
Processed data, final context.
- Return type:
- build_settings(context, shots)#
Build the settings for the execution. Updates context[“circuit_metrics”] with schedule_duration and min_execution_time.