Compiler#

Module: iqm.cpc.compiler.compiler

class iqm.cpc.compiler.compiler.Compiler(*, dut_label, loading_rules, chip_topology, software_version_set_id, component_mapping, station_control_settings, controller_mapping=None, gate_definitions=None, observation_handler=None, circuit_stages=None, pulse_stages=None, final_stages=None, pp_stages=None, compiler_options=None, name='IQM Compiler')#

Bases: object

Compile quantum circuits into jobs that can be submitted to a quantum computer.

Parameters:
  • dut_label (str) – DUT label of the chip being used.

  • loading_rules (Sequence[RuleType]) – Observation loading rules.

  • chip_topology (ChipTopology) – Physical layout and connectivity of the quantum chip.

  • software_version_set_id (int) – An integer ID representing the software versions in the current python environment.

  • component_mapping (dict[str, str] | None) – Mapping of logical QPU component names to physical QPU component names. None means the identity mapping.

  • station_control_settings (SettingNode) – Settings representing the device and station controllers.

  • controller_mapping (dict[str, dict[str, str]] | None) – Dictionary that maps physical QPU component names to their device controller names. The dictionary is of the form: {<component_name>: {<operation_name>: <controller name>}}, where operation is one of the following: “drive”, “readout”, “flux” (not all components have all operations supported).

  • gate_definitions (dict[str, QuantumOp] | None) – Names of quantum operations mapped to their definitions, see QuantumOp.

  • observation_handler (ObservationHandlerBase | None) – Observation handler.

  • circuit_stages (list[CompilationStage] | None) – Compilation stages to use in processing gate-level (and above) circuits. None means none. Note that meaningful circuit compilation requires at least some stages. These stages are sweepable in the compilation loop via their stage settings.

  • pulse_stages (list[CompilationStage] | None) – Compilation stages to use in processing TimeBox-level (and below) circuits. None means none. Note that meaningful circuit compilation requires at least some stages. These stages are sweepable in the compilation loop via their stage settings.

  • final_stages (list[CompilationStage] | None) – Compilation stages to use in creating the final run request. These stages are not sweepable.

  • pp_stages (list[CompilationStage] | None) – Post-processing stages to use.

  • compiler_options (CompilerOptions | None) – General options to define the compiler behaviour.

  • name (str) – The name of this compiler.

Methods

add_implementation

Adds a new implementation for a quantum operation (gate).

compile

Run all compiler stages.

compiler_context

Return initial compiler context dictionary.

finalize

Run self.final_stages, i.e. finalize the payload to be sent for execution..

get_settings

Retrieves and modifies settings for Compiler.

post_process

Run self.pp_stages.

run_stages

Run the circuit- and pulses-level stages on the given data.

set_default_implementation

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

Displays an interactive HTML representation of the compiler stages.

get_settings(circuits=None, timeboxes=None, circuit_stages=None, pulse_stages=None, final_stages=None, qubits=None, couplers=None, computational_resonators=None)#

Retrieves and modifies settings for Compiler.

Parameters:
  • circuits (Any | None) – Circuit-level input to be compiled.

  • timeboxes (Any | None) – TimeBox-level input to be compiled. Either circuits or timeboxes must be provided.

  • circuit_stages (list[CompilationStage] | None) – Circuit-level (and above) compilation stages. If not provided, self.circuit_stages will be used.

  • pulse_stages (list[CompilationStage] | None) – TimeBox-level (and below) compilation stages. If not provided, self.pulse_stages will be used.

  • final_stages (list[CompilationStage] | None) – Station-control job finalization stages. If not provided, self.final_stages will be used.

  • qubits (list[str] | None) – Names of the qubits to get the settings for.

  • couplers (list[str] | None) – Names of the couplers to get the settings for.

  • computational_resonators (list[str] | None) – Names of the computational resonators to get the settings for..

Returns:

The settings tree.

Return type:

SettingNode

compiler_context(components, settings, **kwargs)#

Return initial compiler context dictionary.

Used automatically by compile().

Parameters:
Return type:

dict[str, Any]

compile(circuits=None, timeboxes=None, components=None, settings=None, sweeps=None, context=None)#

Run all compiler stages.

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

Parameters:
  • circuits (Any | None) – Circuit-level input to be compiled.

  • timeboxes (Any | None) – TimeBox-level input to be compiled. Either circuits or timeboxes must be provided. If this argument is provided, the stages in self.circuit_stages will not be run.

  • components (list[str] | list[tuple[str, ...]] | list[list[tuple[str, ...]]] | None) – Apply the circuits on these active components. If logical component names are used, self.component_mapping must contain logic for mapping them into physical ones. If components is None, the active components used in the circuits can be automatically resolved in a compiler pass.

  • settings (SettingNode | None) – The settings tree to use. If None, the default settings tree will be generated.

  • sweeps (list[tuple[Sweep, ...]] | None) – The sweeps to perform in the job. If None, the job will consist of one trivial sweep spot.

  • context (dict[str, Any] | None) – Custom initial compiler context dictionary. Contents are updated into the default context given by compiler_context().

Returns:

Compiled `data, final context.

Return type:

tuple[Any, dict[str, Any]]

run_stages(data, context, stages=None, sweeps=None)#

Run the circuit- and pulses-level stages on the given data.

Circuit- and pulse-level stages can be swept as per the provided sweeps. The provided hard sweeps determine the dimensions of the final Playlist such that one segment (circuit) is generated per hard sweep spot.

Parameters:
  • data (Any) – The data to compile.

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

  • sweeps (list[tuple[Sweep, ...]] | None) – Sweeps to run on data.

  • stages (list[CompilationStage] | None) – compilation stages to be run on data. If not provided, self.circuit stages + self.pulse_stages will be used. Each stage may make modifications to context before it is passed to the next stage.

  • sweeps – Sweeps to run on data. Can contain both hard- and soft sweeps.

Returns:

Processed data, final context.

Return type:

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

finalize(data, context, stages=None)#

Run self.final_stages, i.e. finalize the payload to be sent for execution.

The final stages are not sweepable but their settings can be changed.

Parameters:
  • data (Any) – The circuit data for the final stages.

  • context (dict[str, Any]) – The compiler context.

  • stages (list[CompilationStage] | None) – The final stages to be run on data. If not provided, uses self.final_stages.

Returns:

The finalized payload to be sent for execution and the compiler context.

Return type:

tuple[Any, dict[str, Any]]

post_process(data, context, stages=None)#

Run self.pp_stages.

Post-processing stages are not sweepable and their settings cannot be changed, but one may still pass stateful effects via the context.

Parameters:
  • context (dict[str, Any]) – The compiler context.

  • data (Any) – The circuit data for the final stages.

  • stages (list[CompilationStage] | None) – The final stages to be run on data. If not provided, uses self.final_stages.

Returns:

Human-readable result data and the compiler context.

Return type:

tuple[Any, dict[str, Any]]

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

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

show_stages(pass_name=None)#

Displays an interactive HTML representation of the compiler stages.

Parameters:

pass_name (str | None)

Return type:

Any

Inheritance

Inheritance diagram of iqm.cpc.compiler.compiler.Compiler