frontier.utils.quantumcircuit
Classes
|
Translate a |
|
Configuration options that control how a |
|
In-memory representation of a quantum circuit. |
|
Data container for a (possibly parameterized) quantum gate. |
|
A controlled or otherwise two‑qubit gate. |
- class QasmEmitter(options: QasmEmitterOptions)[source]
Bases:
objectTranslate a
QuantumCircuitinto OpenQASM source code.- Responsibilities:
Header emission (version + includes)
Register declarations
Gate translation & parameter formatting
Measurements and resets
- emit(circuit: QuantumCircuit) str[source]
Generate a full QASM program for
circuit.- Returns:
The QASM source code as a single string.
- class QasmEmitterOptions(format: str = 'qasm2', target_sdk: str | None = None, includes: str | Sequence[str] | None = None, float_precision: int = 6, custom_template: Dict[str, Any] | None = None)[source]
Bases:
objectConfiguration options that control how a
QasmEmittertranslates aQuantumCircuitinto OpenQASM source.- format
OpenQASM version to target. Supported values are
"qasm2"and"qasm3".- Type:
str
- target_sdk
Optional SDK dialect for gate aliases. If provided, it adjusts emitted gate names to match that SDK. Supported values:
"qiskit","braket","tket", or"custom".Nonemeans use the format’s default aliasing.- Type:
str | None
- includes
Optional include file(s). May be a single string path or a sequence of paths. If
target_sdkis one of the known SDKs, this is automatically populated with sensible defaults for the selectedformat.- Type:
str | collections.abc.Sequence[str] | None
- float_precision
Number of decimal places when formatting floating parameters in QASM output.
- Type:
int
- custom_template
Optional mapping of internal gate names to the desired QASM names that overrides the selected format/SDK template.
- Type:
Dict[str, Any] | None
- map
(Computed) Effective internal-gate → QASM-gate alias mapping.
- Type:
Dict[str, str]
- class QuantumCircuit(number_of_qubits: int = 0, number_of_classical_bits: int = 0)[source]
Bases:
objectIn-memory representation of a quantum circuit.
The circuit stores qubit/bit registers plus an ordered list of gate operations, measurements, and resets. Convenience helpers are provided to append common gates and to export the circuit to OpenQASM.
- number_of_qubits
Total number of qubits in the circuit.
- number_of_classical_bits
Total number of classical bits in the circuit.
- gate_list
Ordered list of gate objects.
- measurements
(qubit, cbit)pairs describing where measurement outcomes are stored.
- reset_operations
Indices of qubits that are reset.
- add_classical_bits(additional_classical_bits: int) None[source]
Increase the number of classical bits by
additional_classical_bits.
- add_cx_gate(control_qubit: int, target_qubit: int) None[source]
Append a controlled-X (CNOT) with
control_qubit → target_qubit.
- add_cy_gate(control_qubit: int, target_qubit: int) None[source]
Append a controlled-Y with
control_qubit → target_qubit.
- add_cz_gate(control_qubit: int, target_qubit: int) None[source]
Append a controlled-Z with
control_qubit → target_qubit.
- add_measurement(qubit: int | Sequence[int], classical_bit: int | Sequence[int]) None[source]
Append measurement(s).
Supports scalar ints, lists/tuples, numpy arrays, and range().
- Rules:
If both are sequences, they must have equal length (pairwise mapping).
If qubit is a sequence and classical_bit is scalar, classical_bit is reused.
If qubit is scalar and classical_bit is sequence, classical_bit must be length 1 (or you can decide to error).
- add_qubits(additional_qubits: int) None[source]
Increase the number of qubits by
additional_qubits.
- add_swap_gate(qubit_one: int, qubit_two: int) None[source]
Append a SWAP gate between
qubit_oneandqubit_two.Notes
Internally this is modeled as a two-qubit gate and emitted as
swap q[qubit_one], q[qubit_two];in QASM.
- add_u_gate(qubit: int, theta: float, phi: float, lambda_parameter: float) None[source]
Append a general single-qubit unitary gate
u(theta, phi, lambda).- Parameters:
qubit – Target qubit.
theta – First Euler angle.
phi – Second Euler angle.
lambda_parameter – Third Euler angle.
- display_gate_descriptions() None[source]
Print a short description for each supported internal gate name.
- draw_circuit_diagram(max_length: int = 20) None[source]
Print a simple ASCII diagram of the circuit.
The diagram is split into vertical blocks if any line exceeds
max_lengthgate-units.- Parameters:
max_length – Maximum number of gate-units per block.
- single_qubit_gate_count() int[source]
Return the number of single-qubit gate applications in the circuit.
- to_qasm(emitter_options: QasmEmitterOptions | None = None, *, format: str = 'qasm2', target_sdk: str | None = None, **kwargs: Any) str[source]
Generate OpenQASM code for the circuit.
- Parameters:
emitter_options – Pre-configured options. If omitted, a new
QasmEmitterOptionsis created fromformat,target_sdkand any extrakwargs.format – QASM format used when building the default options.
target_sdk – Optional SDK aliasing used when building default options.
**kwargs – Passed to
QasmEmitterOptions.
- Returns:
The QASM program as a multi-line
str.
- class QuantumGate(name: str, target_qubits: int | Sequence[int], parameters: float | Sequence[float] | None = None)[source]
Bases:
objectData container for a (possibly parameterized) quantum gate.
- name
Internal gate name (e.g.,
"x","rz","cx").- Type:
str
- target_qubits
Index/indices of the qubits this gate acts on.
- Type:
int | collections.abc.Sequence[int]
- parameters
Optional numeric parameter or sequence of parameters. Values are normalized to a list of
float.- Type:
float | collections.abc.Sequence[float] | None
- property is_two_qubit_gate: bool
False.- Type:
Return
Trueif this gate is multi-qubit/controlled. Base
- class TwoQubitQuantumGate(name: str, target_qubits: int | ~collections.abc.Sequence[int], parameters: float | ~collections.abc.Sequence[float] | None = None, control_qubits: int | ~collections.abc.Sequence[int] = <factory>)[source]
Bases:
QuantumGateA controlled or otherwise two‑qubit gate.
- control_qubits
Index/indices of control qubits. At least one is required.
- Type:
int | collections.abc.Sequence[int]
- property is_two_qubit_gate: bool
Return
Truefor this subclass.