RoutingStar#

class iqm.qaoa.transpiler.star.star.RoutingStar(problem_bqm, qpu, initial_mapping=None)[source]#

Bases: Routing

This class represents a routing of a QAOA phase separator on the star topology.

The main difference from the parent class Routing is that RoutingStar doesn’t use Layer for its layers. The layers in RoutingStar are much simpler (just one gate in each layer). Here a layer is just a tuple containing a string describing the gate and an integer describing the HardQubit involved.

Parameters:
  • problem_bqm (BinaryQuadraticModel) – The optimization problem represented as BinaryQuadraticModel.

  • qpu (StarQPU) – The QPU representing the hardware qubit topology.

  • initial_mapping (Mapping | None) – The starting mapping of the logical-to-hardware qubits.

Attributes

Methods

apply_directed_int(target)

Apply interaction between the resonator and an outer qubit.

apply_move_in(qubit)

Apply move gate (to move a qubit into the resonator).

apply_move_out(qubit)

Apply move gate (to move a qubit out of the resonator).

build_qiskit(betas, gammas)

Build the entire QAOA circuit in qiskit.

count_move_gates()

Counts the number of move gates in the routing.

draw()

Plot all layers of the routing in batches of 9.

apply_move_in(qubit)[source]#

Apply move gate (to move a qubit into the resonator).

Parameters:

qubit (int) – The HardQubit whose logical qubit is moved to the central resonator.

Raises:
  • ValueError – If the central resonator is already occupied by a logical qubit (so a different logical qubit can’t be moved there).

  • ValueError – If the target qubit doesn’t contain a logical qubit.

Return type:

None

apply_move_out(qubit)[source]#

Apply move gate (to move a qubit out of the resonator).

Parameters:

qubit (int) – The HardQubit where the logical qubit from the resonator is moved to.

Raises:
  • ValueError – If the central resonator is empty, so nothing can’t be moved out of it.

  • ValueError – If the target qubit is already occupied by a different logical qubit.

Return type:

None

apply_directed_int(target)[source]#

Apply interaction between the resonator and an outer qubit.

The resonator doesn’t support single-qubit gates, so the interaction has to be decomposed in such a way that the single-qubit rotation is applied to the outer target qubit.

Parameters:

target (int) – The HardQubit that interacts with the central qubit.

Raises:
  • ValueError – If the resonator is empty (so no interaction can be done).

  • ValueError – If the target qubit doesn’t correspond to any logical qubit.

Return type:

None

count_move_gates()[source]#

Counts the number of move gates in the routing.

Counts both ‘move_in’ and ‘move_out’ gates in the routing. In theory, each ‘move_in’ gate should be followed by a corresponding ‘move_out’ gate, but this counts the gates separately because there might be as of yet unforseen situations in which this won’t be true anymore.

Returns:

The number of ‘move_in’ and ‘move_out’ gates in the entire routing.

Return type:

int

build_qiskit(betas, gammas)[source]#

Build the entire QAOA circuit in qiskit.

The RoutingStar object contains all the information needed to create the phase separator part of the QAOA circuit. This method builds the rest of the circuit from it, i.e.:

  1. It initializes the qubits in the \(| + >\) state by applying the Hadamard gate to all of them.

  2. It goes through the routing layers and applies the corresponding interactions (or move gates).

  3. It applies local fields.

  4. It applies the driver.

  5. It repeats steps 2-4 until it uses up all betas and gammas.

  6. It applies the measurements and a barrier before them.

Parameters:
  • betas (list[float]) – The QAOA parameters to be used in the driver (RX gate).

  • gammas (list[float]) – The QAOA parameters to be used in the phase separator (RZ and RZZ gates).

Returns:

A complete QAOA QuantumCircuit.

Return type:

QuantumCircuit

draw()[source]#

Plot all layers of the routing in batches of 9.

This creates a series of plots that are shown on the screen. Each plot contains 9 layers arranged in a 3x3 grid. Each layer is drawn using a custom procedure. It has the shape of the QPU topology with edges colored based on what is happening on them in the given layer.

  • Teal highlight if a ‘move_in’ gate is applied.

  • Plum highlight if a ‘move_out’ gate is applied.

  • Green highlight if an ‘int’ gate is applied.

  • No highlight (black) if nothing is happening along the edge.

Raises:

ValueError – If the first element of the layers is neither of ‘int’, ‘move_in’ or ‘move_out’.

Return type:

None