Routing#
- class iqm.qaoa.transpiler.routing.Routing(problem_bqm, qpu, initial_mapping=None)[source]#
Bases:
object
This class represents a routing of a QAOA phase separator.
A
Routing
object is intended to be directly used by a router during routing (any router). To that end it maintains a list ofLayer
objects, aGraph
with the interactions not implemented yet and aMapping
object that represents the current status of mapping between hardware and logical qubits.A router interacts with a
Routing
object by using the methodsapply_swap()
andapply_int()
. Optionally alsoattempt_apply_int()
. If the problem BQM contains interactions of strength 0 (e.g., because of padding), those won’t be added into the list of layers. When the methodapply_int()
is called on those interactions, it is skipped.- Parameters:
Attributes
The topology of the QPU that is being used in the routing.
Methods
apply_int
(gate)Apply interaction gate at the earliest possible
Layer
, add a new layer if necessary.apply_swap
(gate[, attempt_int])Apply swap gate at the earliest possible
Layer
, add a new layer if needed.attempt_apply_int
(gate)This is a softer version of
apply_int()
.build_qiskit
(betas, gammas)Counts the number of swap gates in all
Layer
s so far.draw
()Plot all
Layer
s of the routing in batches of 9.- apply_swap(gate, attempt_int=False)[source]#
Apply swap gate at the earliest possible
Layer
, add a new layer if needed.Goes through the existing
Layer
s from the end and tries to apply a swap gate between the qubits defined ingate
at the earliest possibleLayer
. That means, as early as possible without crossing any other swap or interaction acting on the sameHardQubit
s.- Parameters:
- Raises:
ValueError – If there is no edge connecting the two hardware qubits in
gate
on the hardware graph.- Return type:
None
- apply_int(gate)[source]#
Apply interaction gate at the earliest possible
Layer
, add a new layer if necessary.Goes through the existing
Layer
s from the end and tries to apply an interaction gate between the qubits defined ingate
at the earliest possibleLayer
. That means, as early as possible without crossing any other swap or interaction acting on the sameHardQubit
s. If an interaction has strength 0, it isn’t added!- Parameters:
gate (HardEdge) – An edge between two
HardQubit
s where the interaction should be applied.- Raises:
ValueError – If there is no edge connecting the two hardware qubits in
gate
on the hardware graph.ValueError – If there is no interaction to be applied between the two corresponding logical qubits.
- Return type:
None
- attempt_apply_int(gate)[source]#
This is a softer version of
apply_int()
.It first checks if there is an interaction to be done and doesn’t do anything if there isn’t, as opposed to raising an error. This method is made for cases when it’s not clear whether an interaction has been applied between two logical qubits already.
- Parameters:
gate (HardEdge) – An edge between two
HardQubit
s where the interaction should be applied.- Return type:
None
- build_qiskit(betas, gammas)[source]#
Build the QAOA circuit from the
Routing
(self
) inqiskit
.The
Routing
(self
) 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 applies the interactions by going through the
Layer
s of theRouting
.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 barrier before them.
- Parameters:
- Returns:
A complete QAOA
QuantumCircuit
.- Return type:
- draw()[source]#
Plot all
Layer
s of the routing in batches of 9.This creates a series of plots that are shown on the screen. Each plot contains 9
Layer
s arranged in a 3x3 grid. EachLayer
is drawn usingdraw()
. Therefore, it has the shape of the QPU topology with edges colored based on what is happening on them in the givenLayer
.Yellow highlight if a combination of swap and int is applied.
Blue highlight if a swap gate is applied.
Green highlight if an interaction gate is applied.
No highlight (black) if nothing is happening along the edge.
- Return type:
None