CircuitSynthesis#

Module: iqm.qaoa.transpiler.routing

class iqm.qaoa.transpiler.routing.CircuitSynthesis(mapping)[source]#

Bases: object

Synthesize 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:

  1. If a diagonal Hamiltonian is known beforehand, only the method cnot() is used for constructing the circuit. When a Qiskit QuantumCircuit is created with build_qiskit(), RZ gates are included automatically based on the provided diagonal Hamiltonian (as a BinaryPolynomial object).

  2. Alternatively, one may manually insert CNOT and RZ gates. The attribute possible_ints contains a set of all possible interactions that could be implemented given the CNOT gates (so it can be used to construct a Hamiltonian). The attribute constructed_hamiltonian_bp contains 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

cnot_list

Returns the list of all CNOT gates applied throughout the circuit synthesis process.

computing

A flag signalling that the circuit synthesis is currently in the 'computing' mode.

Methods

begin_uncompute

Calling this ends the computing phase of the circuit synthesis and begins the uncomputing phase.

build_qiskit

Build a full QAOA circuit from the synthesized parity-based circuit construction.

build_qiskit_phase_separator

Builds the synthesized quantum circuit.

cnot

Adds a CNOT gate to the synthesized circuit.

rz

Adds an RZ rotation gate associated with a parity interaction.

uncompute_parities

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: object

A 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

allow_interactions#

True iff we permit the circuit synthesis algorithm to add RZ gates directly after this CNOT gate. This is useful for better control over the structure of the quantum circuit.

Type:

bool

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 BinaryPolynomial implied by applying the RZ gate. This internal BinaryPolynomial may be accessed by the attribute self.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 internal BinaryPolynomial.

Raises:
  • ValueError – If the interaction term already exists in the internal BinaryPolynomial and overwrite is disabled

  • ValueError – 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 interactions is not provided, the circuit inserts an RZ gate wherever it was placed using the rz() method.

  • If interactions is 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 from interactions. A warning is raised if not all interactions are 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. The varytpe of 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 the BinaryPolynomial as describing a Hamiltonian made up of sums of products of the Z Pauli gate. The reason we don’t accept the input with vartype "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 QuantumCircuit implementing the synthesized quantum circuit.

Raises:
  • ValueError – If the input interactions has vartype set to "BINARY".

  • ValueError – If remove_cnots is set to True, but the circuit synthesis contains no uncomputation.

Return type:

QuantumCircuit

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).

  • gammas (list[float]) – List of QAOA phase separator angles.

  • interactions (BinaryPolynomial | None) – The problem Hamiltonian as a BinaryPolynomial in 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 QuantumCircuit implementing the full synthesized QAOA circuit.

Raises:
  • ValueError – If betas and gammas do 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:

QuantumCircuit

Inheritance

Inheritance diagram of iqm.qaoa.transpiler.routing.CircuitSynthesis