CircuitSynthesis#
Module: iqm.qaoa.transpiler.routing
- class iqm.qaoa.transpiler.routing.CircuitSynthesis(mapping)[source]#
Bases:
objectSynthesize a quantum circuit using parity-based interaction mapping.
The hardware-to-parity mapping is saved in an internal
ParityMapping.There are two main regimes to use the class:
If a diagonal Hamiltonian is known beforehand, only the method
cnot()is used for constructing the circuit. When a QiskitQuantumCircuitis created withbuild_qiskit(), RZ gates are included automatically based on the provided diagonal Hamiltonian (as aBinaryPolynomialobject).Alternatively, one may manually insert CNOT and RZ gates. The attribute
possible_intscontains a set of all possible interactions that could be implemented given the CNOT gates (so it can be used to construct a Hamiltonian). The attributeconstructed_hamiltonian_bpcontains the Hamiltonian that has been implicitly constructed by manually applying the RZ gates.
An external algorithm might be needed to determine the optimal placement of the CNOT gates.
- Parameters:
mapping (ParityMapping) – Initial parity mapping used to construct the circuit.
Attributes
Returns the list of all CNOT gates applied throughout the circuit synthesis process.
A flag signalling that the circuit synthesis is currently in the 'computing' mode.
Methods
Calling this ends the computing phase of the circuit synthesis and begins the uncomputing phase.
Build a full QAOA circuit from the synthesized parity-based circuit construction.
Builds the synthesized quantum circuit.
Adds a CNOT gate to the synthesized circuit.
Adds an RZ rotation gate associated with a parity interaction.
Adds CNOT gates to the circuit synthesis to uncompute the parity mapping back to
self.initial_mapping.- class CNOTStep(control, target, allow_interactions=True)[source]#
Bases:
objectA custom dataclass representing one CNOT step in the circuit synthesis.
- Parameters:
control (HardQubit)
target (HardQubit)
allow_interactions (bool)
- control#
The control qubit of the CNOT gate.
- Type:
HardQubit
- target#
The target qubit of the CNOT gate.
- Type:
HardQubit
- property computing: bool#
A flag signalling that the circuit synthesis is currently in the ‘computing’ mode.
- property cnot_list: list[CNOTStep]#
Returns the list of all CNOT gates applied throughout the circuit synthesis process.
- begin_uncompute()[source]#
Calling this ends the computing phase of the circuit synthesis and begins the uncomputing phase.
- Raises:
RuntimeError – If uncomputation has already begun previously.
- Return type:
None
- cnot(control, target, allow_int_after=True)[source]#
Adds a CNOT gate to the synthesized circuit.
Updates the internal parity mapping and records the interaction.
- Parameters:
control (HardQubit) – Control hardware qubit.
target (HardQubit) – Target hardware qubit.
allow_int_after (bool) – True iff interactions are allowed to take place immediately after the CNOT gate.
- Return type:
None
- rz(interaction, qubit, allow_overwrite=False)[source]#
Adds an RZ rotation gate associated with a parity interaction.
Also, adds an interaction term to the internal
BinaryPolynomialimplied by applying the RZ gate. This internalBinaryPolynomialmay be accessed by the attributeself.constructed_hamiltonian_bp.- Parameters:
interaction (float) –
The interaction strength corresponding to the RZ gate.
Warning
The input is the interaction strength corresponding to the RZ gate, i.e., the term that will be added to the Hamiltonian. The rotation angle of the RZ gate is this value times the γ QAOA angle.
qubit (HardQubit) – Hardware qubit on which the RZ gate is applied.
allow_overwrite (bool) – If
True, allows overwriting an existing interaction term in the internalBinaryPolynomial.
- Raises:
ValueError – If the interaction term already exists in the internal
BinaryPolynomialand overwrite is disabledValueError – If the qubit on which the RZ rotation acts carries no parity information.
RuntimeError – If attempted to place an RZ gate during uncomputation.
- Return type:
None
- uncompute_parities()[source]#
Adds CNOT gates to the circuit synthesis to uncompute the parity mapping back to
self.initial_mapping.Currently, the uncomputing is very primitive. It just mirrors the CNOTs that were added in the first half of the circuit.
- Return type:
None
- build_qiskit_phase_separator(gamma, interactions=None, show_parities=False, remove_cnots=False)[source]#
Builds the synthesized quantum circuit.
This only builds the synthesized part of the quantum circuit. For constructing the entire QAOA circuit, use
build_qiskit().The circuit is constructed using CNOT gates in the order in which the method
cnot()was called, acting on the respective qubits.If
interactionsis not provided, the circuit inserts an RZ gate wherever it was placed using therz()method.If
interactionsis provided, the circuit ignores the manually placed RZ gates (and raises a warning if some were manually placed). It then places RZ gates automatically whenever a qubit carries one of the parities frominteractions. A warning is raised if not allinteractionsare executed.
- Parameters:
gamma (float) – Global scaling factor for interaction strengths (e.g., a parameter of the QAOA ansatz).
interactions (BinaryPolynomial | None) – Optional Hamiltonian of interactions. If
None, uses internally constructed interactions. Thevarytpeof the interactions has to be"SPIN"and it is assumed that the quantum state \(|1\rangle\) corresponds to the value -1 in the polynomial (and \(|0\rangle\) corresponds to 1). This comes from seeing theBinaryPolynomialas describing a Hamiltonian made up of sums of products of the Z Pauli gate. The reason we don’t accept the input withvartype"BINARY"is that the conversion from"BINARY"to"SPIN"by default uses the opposite convention (where \(|1\rangle\) corresponds to the value 1 in the polynomial and \(|0\rangle\) to -1). This could lead to silent errors.show_parities (bool) – Iff set to
True, adds identity gates throughout the circuit whose labels show the parity encoded in the qubits.remove_cnots (bool) – Iff set to
True, the uncomputation is skipped and the computation happens in the opposite order. This saves 2-qubit gates, if this is the first phase seprator applied onto the initial state (which is presumably the \(|+\rangle\) state).
- Returns:
A Qiskit
QuantumCircuitimplementing the synthesized quantum circuit.- Raises:
ValueError – If the input
interactionshasvartypeset to"BINARY".ValueError – If
remove_cnotsis set toTrue, but the circuit synthesis contains no uncomputation.
- Return type:
- build_qiskit(betas, gammas, interactions=None, measurement=True, remove_cnots_first_layer=True)[source]#
Build a full QAOA circuit from the synthesized parity-based circuit construction.
This method assembles the complete QAOA circuit by repeatedly composing the parity-based phase separator (constructed via CNOT and RZ operations) with the mixer (RX rotations). It assumes that all parity transformations have been properly uncomputed before execution, i.e., the parity mapping has returned to the initial configuration up to a permutation of hardware qubits.
- Parameters:
betas (list[float]) – List of QAOA mixer angles (RX rotations).
interactions (BinaryPolynomial | None) – The problem Hamiltonian as a
BinaryPolynomialin SPIN representation.measurement (bool) – If
True, adds a measurement step.remove_cnots_first_layer (bool) – If
True, the first layer of QAOA swaps its computation and uncomputation. Then, the uncomputation step is completely removed, since it consists purely of CNOT gates applied directly onto the \(|+\rangle\) state, which has no effect.
- Returns:
A
QuantumCircuitimplementing the full synthesized QAOA circuit.- Raises:
ValueError – If
betasandgammasdo not have the same length.ValueError – If the parity mapping has not been fully uncomputed back to the initial state (up to permutation of hardware qubits).
- Return type:
Inheritance
