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 thatRoutingStar
doesn’t useLayer
for its layers. The layers inRoutingStar
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 theHardQubit
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
.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:
- 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.:It initializes the qubits in the \(| + >\) state by applying the Hadamard gate to all of them.
It goes through the routing layers and applies the corresponding interactions (or move gates).
It applies local fields.
It applies the driver.
It repeats steps 2-4 until it uses up all
betas
andgammas
.It applies the measurements and a barrier before them.
- Parameters:
- Returns:
A complete QAOA
QuantumCircuit
.- Return type:
- 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