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

gates

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).

amend_calibration_for_gate_implementation(...)

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.

compiler_context()

Return initial compiler context dictionary.

get_calibration()

Returns a copy of the current local calibration set.

postprocess(data[, context])

Run all post-processing stages.

print_all_implementations_trees()

Prints all implementations of all currently known quantum operations (gates), including parameters.

print_implementations_trees(op)

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_default_implementation_for_loci(...)

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.

Return type:

dict[str, bool | str | int | float | complex | ndarray]

set_calibration(calibration)#

Sets the current calibration set to a given calibration set, then refreshes the compiler.

Parameters:

calibration (dict[str, bool | str | int | float | complex | ndarray]) – The calibration set to be set as the current calibration set.

Return type:

None

property gates: dict[str, QuantumOp]#

Registered quantum gates.

set_default_implementation(gate_name, implementation_name)#

Set the default implementation of a gate.

Parameters:
  • gate_name (str) – Name of the gate.

  • implementation_name (str) – Name of the implementation to set as the default.

Return type:

None

set_default_implementation_for_loci(gate_name, implementation_name, loci)#

Set the default implementation for a gate for a specific loci.

Parameters:
  • gate_name (str) – Name of the gate.

  • implementation_name (str) – Name of the implementation to set as the default for loci.

  • loci (Iterable[tuple[str, ...]]) – Loci of the gate for which to set implementation_name as the default.

Return type:

None

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:

bool

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 compile().

Return type:

dict[str, Any]

compile(data, context=None)#

Run all compiler stages.

Initial context will be derived using compiler_context() unless a custom context dictionary is provided.

Parameters:
  • data (Iterable[Any]) – Circuits to be compiled.

  • context (dict[str, Any] | None) – Custom initial compiler context dictionary.

Returns:

Compiled data, final context.

Return type:

tuple[Iterable[Any], dict[str, Any]]

postprocess(data, context=None)#

Run all post-processing stages.

Initial context will be derived using compiler_context() unless a custom context dictionary is provided.

Parameters:
  • data (Iterable[Any]) – Any data, e.g. execution results derived from Pulla.execute()

  • context (dict[str, Any] | None) – Custom initial compiler context dictionary.

Returns:

Postprocessed data, final context.

Return type:

tuple[Iterable[Any], dict[str, Any]]

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.

  • data (Iterable[Any]) – The data to be processed.

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

tuple[Iterable[Any], dict[str, Any]]

build_settings(context, shots)#

Build the settings for the execution. Updates context[“circuit_metrics”] with schedule_duration and min_execution_time.

Parameters:
  • context (dict[str, Any]) – A dictionary containing the necessary data for building the settings.

  • shots (int) – The number of shots to be executed.

Returns:

A dictionary containing the settings for the execution. context: The updated context.

Return type:

settings