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:
BackendV2Qiskit 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/pairmacros.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
QuantumMachinesManagerorCloudQuantumMachinesManager. 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), andmax_circuits(30).
- property target: Target¶
A
qiskit.transpiler.Targetobject 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)
- 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.
- 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.
- 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, andQMEstimatorV2all 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). Primitiverun_options["max_circuits"]andbackend.run(..., max_circuits=N)override this value for that job only and do not change this property.
- run(run_input: QuantumCircuit | List[QuantumCircuit], **options) QMJob[source][source]¶
Run one or more
QuantumCircuitobjects on the QM backend.This method now delegates the heavy lifting (circuit validation, compilation to QUA, job submission and result assembly) to the
QMJobinterface, 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(orCloudQMJobfor 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:Updates
_operation_mapping_QUAfrom machine macros (incrementally).Syncs operations from Target to
_operation_mapping_QUA, overwriting entries for the same operation (name, arity, qargs).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_nameson 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 toquam.components.pulses.Pulse.play()ascondition.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
QuantumCircuitto a QUA program fragment.Can be called inside an existing
with program():block or standalone. When called standalone, access the generated program viaresult.qua_programorresult.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 wholeParameterVector(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, oneParameterTable, 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 (fixedfor a float input). The compiler uses that object directly, so assignments inside the OpenQASM program update it. Each circuit input comes fromparam_tableor fromtable_by_ref, not both. Omit it to copy every binding into a new QUA variable.
- Returns:
QuaCircuitCompilationwrapping 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_tableandtable_by_ref, atable_by_reftable is not declared, or atable_by_refvalue 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 vectorxnext to thexgate, exported asx_0) still binds to its table field.TypeError – if
param_tableortable_by_refis not one of the accepted types (a dict is accepted only byparam_table).
- property compiler: Compiler¶
The OpenQASM to QUA compiler.
_calibration_operation_mapping_QUAis keyed byoperation_key()(a plain, value-equal tuple), not byOperationIdentifier– see that function’s docstring for why building the mapping with realOperationIdentifierkeys throughout would silently duplicate rather than overwrite an existing operation.HardwareConfigitself does require realOperationIdentifierkeys, so they are built fresh, once, right here – after the mapping is known to be correctly deduplicated, never before.
- 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
QMOpenQASM3Exporterconfigured for this backend’s basis gates – do not construct one directly. It performs no validation of its own against this backend’sTarget: calling.dumps(qc)on the result will happily export aConditionalPlaythat was never registered (seeregister_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 isquantum_circuit_to_qua()’s responsibility, not this exporter’s – prefer calling that instead of.dumps()directly unless you have already validatedqcyourself.