QMBackend

class QMBackend(machine: QuamRoot, channel_mapping: Dict[QiskitChannel, QuAMChannel] | None = None, init_macro: Callable | None = None, qmm: QuantumMachinesManager | CloudQuantumMachinesManager | None = None, name: str | None = None, **fields)[source][source]

Bases: BackendV2

Qiskit backend for Quantum Machines (QuAM).

Represents at the Qiskit level all available operations and qubit properties of a Quantum Abstract Machine (QuAM) instance. The QuAM instance must expose active_qubits, active_qubit_pairs, and per-qubit/pair macros.

Initialize the QM backend.

Parameters:
  • machine – The QuAM instance to wrap.

  • channel_mapping – Optional mapping from Qiskit Pulse channels (DriveChannel, ControlChannel, MeasureChannel, …) to QuAM channels. Used only when Qiskit Pulse is installed (Qiskit < 2.0) to convert Pulse schedules into parametric QUA macros (schedules must have fixed durations).

  • init_macro – Optional QUA macro invoked at the start of each program to initialize the QPU.

  • qmm – Optional QuantumMachinesManager or CloudQuantumMachinesManager. Inferred from the machine when omitted.

  • name – Optional backend name. Defaults to the network backend name or "QMBackend".

  • fields – Optional keyword overrides for default run options: shots (1024), compiler_options, simulate, memory (False), skip_reset (False), meas_level (MeasLevel.CLASSIFIED), meas_return (MeasReturnType.AVERAGE), timeout (60 seconds), and max_circuits (30).

property target: Target

A qiskit.transpiler.Target object for the backend.

Return type:

Target

property custom_instructions: Dict[str, Instruction]

Get the custom instructions for the backend (those that are part of the target but not in the standard Qiskit gate set, inferred from the available macros)

property qubit_dict: Dict[str, int]

Get the qubit dictionary for the backend

property qubit_pair_dict: Dict[str, Tuple[int, int]]

Get the qubit pair dictionary for the backend

get_qubit_index(qubit: str | Qubit) → int[source][source]

Get the index of the given qubit or qubit name in Quam.

Parameters:

qubit – The qubit or qubit name

Returns:

The index of the given qubit or qubit name in Quam

get_qubit_pair_indices(qubit_pair: str | QubitPair) → Tuple[int, int][source][source]

Get the indices of the given qubit pair or qubit pair name in Quam.

Parameters:

qubit_pair – The qubit pair or qubit pair name

Returns:

The indices of the given qubit pair or qubit pair name in Quam

get_qubit(qubit: int | str) → Qubit[source][source]

Get the Qubit object for a qubit index or name.

Parameters:

qubit – Qubit index or name.

Returns:

The corresponding Qubit.

get_qubit_pair(qubits: str | Tuple[int | str | Qubit, int | str | Qubit]) → QubitPair[source][source]

Get the QubitPair for two qubit indices or names.

Parameters:

qubits – Qubit pair name, or a pair of qubit indices, names, or Qubit objects.

Returns:

The corresponding QubitPair.

property qubit_mapping: QubitsMapping

Build the qubit to quantum elements mapping for the backend. Should be of the form {qubit_index: (quantum_element1, quantum_element2, …)}

property qubit_index_dict

Returns a dictionary mapping qubit indices (Qiskit numbering) to corresponding Qubit objects (based on the active_qubits attribute of QuAM instance)

property qmm: QuantumMachinesManager | CloudQuantumMachinesManager

Returns the QuantumMachinesManager instance. Gets a new QuantumMachinesManager instance if none is already set.

property qm: QuantumMachine | CloudQuantumMachine

Returns the QuantumMachine instance. Gets a new QuantumMachine instance if none is already set, using the current QM config.

close_all_qms()[source][source]

Close all QuantumMachines managed by the QuantumMachinesManager

property qm_config: FullQuaConfig

Returns the QUA configuration for the backend

property max_circuits

Maximum number of circuits (or PUBs for Primitives) packed into a single QUA program.

backend.run, QMSamplerV2, and QMEstimatorV2 all split larger batches into several queued QUA programs whose results are stitched back transparently.

Must be a positive integer (>= 1). Defaults to 30. Can be updated at any time via backend.set_options(max_circuits=N). Primitive run_options["max_circuits"] and backend.run(..., max_circuits=N) override this value for that job only and do not change this property.

property meas_map: List[List[int]]

Retrieve the measurement map for the backend.

run(run_input: QuantumCircuit | List[QuantumCircuit], **options) → QMJob[source][source]

Run one or more QuantumCircuit objects on the QM backend.

This method now delegates the heavy lifting (circuit validation, compilation to QUA, job submission and result assembly) to the QMJob interface, keeping the public behaviour identical while centralising execution logic in the job layer.

Parameters:
  • run_input – The QuantumCircuit (or list thereof) to run on the backend.

  • options – Backend run options (shots, simulate, compiler options, etc.).

Returns:

A QMJob (or CloudQMJob for IQCC cloud backends) instance.

update_target(input_type: InputType | None = None)[source][source]

Synchronize Target object with _operation_mapping_QUA.

This method performs a one-way sync from Target to _operation_mapping_QUA:

  1. Updates _operation_mapping_QUA from machine macros (incrementally).

  2. Syncs operations from Target to _operation_mapping_QUA, overwriting entries for the same operation (name, arity, qargs).

  3. Updates the calibration mapping.

The sync is additive (never removes operations) and Target entries take precedence over machine macros for the same identifier.

Parameters:

input_type – Input type for converting parameterized instructions to QUA variables. Required when the Target contains parameterized pulse schedules.

register_conditional_play(*pulse_names: str) → None[source][source]

Register a direct conditional play for each of pulse_names on every active qubit.

Each pulse is resolved using quam.components.Qubit.get_pulse(), which intentionally propagates QuAM’s missing-pulse and ambiguity errors. The generated QUA macro receives one Boolean argument and forwards it to quam.components.pulses.Pulse.play() as condition.

Call this before transpiling a circuit that uses qiskit.circuit.QuantumCircuit.conditional_play(). Registering several pulses in one call resolves and validates all of them before touching the Target, so a QuAM lookup error, or a pulse whose operation already exists in the Target without one of the active qubits, registers none of them. The qm-qasm operation mapping is then synchronized once. Calling this again for an already-registered pulse is safe and just refreshes its Target properties.

Parameters:

*pulse_names – QuAM pulse labels to register, e.g. "x180", "-y90".

Raises:

ValueError – if no pulse name is given, or QuAM cannot resolve a pulse uniquely on every active qubit.

quantum_circuit_to_qua(qc: QuantumCircuit, param_table: ParameterTable | Sequence[ParameterTable | Parameter] | Dict[str | QiskitParameter | ParameterVector | Var, Any] | None = None, *, table_by_ref: ParameterTable | Parameter | Sequence[ParameterTable | Parameter] | None = None) → QuaCircuitCompilation[source][source]

Convert a QuantumCircuit to a QUA program fragment.

Can be called inside an existing with program(): block or standalone. When called standalone, access the generated program via result.qua_program or result.result_program.dsl_program.

Parameters:
  • qc – The circuit to compile.

  • param_table – Parameter mapping copied into new QUA variables. Required when the circuit contains symbolic parameters or classical inputs that must be streamed during execution, unless those inputs are supplied in table_by_ref. Dictionary keys are circuit objects or their names: a whole ParameterVector (or its name) takes a full-length QUA array, which also binds elements exported as scalar inputs; a single element (or "name[i]") takes a scalar, and only binds an element exported as a scalar input. Undeclared tables are declared at this call site.

  • table_by_ref – Parameter tables and standalone parameters passed by reference to qm-qasm. Accepts one Parameter, one ParameterTable, or a sequence of either (no dict). Each must already be declared, and each value bound to an input must be a QUA variable, array, or array cell of the input’s dtype (fixed for a float input). The compiler uses that object directly, so assignments inside the OpenQASM program update it. Each circuit input comes from param_table or from table_by_ref, not both. Omit it to copy every binding into a new QUA variable.

Returns:

QuaCircuitCompilation wrapping the compilation result and wired measurement outputs.

Raises:
  • ValueError – if a circuit input has no binding, a binding of the wrong shape (scalar vs. array, array length), the same exported input is supplied in both param_table and table_by_ref, a table_by_ref table is not declared, or a table_by_ref value is not a QUA variable, array or array cell of the input’s dtype. Every problem is listed, naming the argument it came from. Inputs are matched by Qiskit object, so an input the exporter renamed (e.g. a vector x next to the x gate, exported as x_0) still binds to its table field.

  • TypeError – if param_table or table_by_ref is not one of the accepted types (a dict is accepted only by param_table).

property compiler: Compiler

The OpenQASM to QUA compiler.

_calibration_operation_mapping_QUA is keyed by operation_key() (a plain, value-equal tuple), not by OperationIdentifier – see that function’s docstring for why building the mapping with real OperationIdentifier keys throughout would silently duplicate rather than overwrite an existing operation. HardwareConfig itself does require real OperationIdentifier keys, so they are built fresh, once, right here – after the mapping is known to be correctly deduplicated, never before.

connect() → QuantumMachinesManager[source][source]

Connect to the Quantum Machines Manager

generate_config() → FullQuaConfig[source][source]

Generate the configuration for the Quantum Machine

property init_macro: Callable

The macro to be called at the beginning of the QUA program

property qubits: List[Qubit]

Retrieve the list of active qubits of the machine

property qubit_pairs: List[QubitPair]

Retrieve the list of active qubit pairs of the machine

property qm_qasm_basis_gates: List[str]

Retrieve the list of OpenQASM 3 basis gates supported by the backend

property qasm3_exporter: QMOpenQASM3Exporter

Retrieve the OpenQASM 3 exporter for the backend.

This is the sanctioned way to get a QMOpenQASM3Exporter configured for this backend’s basis gates – do not construct one directly. It performs no validation of its own against this backend’s Target: calling .dumps(qc) on the result will happily export a ConditionalPlay that was never registered (see register_conditional_play()), or one placed on a qubit this backend has no mapping for, producing OpenQASM 3 that later fails to lower to QUA. That check is quantum_circuit_to_qua()’s responsibility, not this exporter’s – prefer calling that instead of .dumps() directly unless you have already validated qc yourself.