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

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

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.

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

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

Return type:

dict[str, Any]

compile(data, context=None)#

Run all compiler stages. Initial context will be derived from Compiler.compiler_context() unless a custom context dictionary is provided.

Parameters:
  • data (Iterable[Any]) – An iterable of circuits to be compiled.

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

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