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 of Layer objects, a Graph with the interactions not implemented yet and a Mapping object that represents the current status of mapping between hardware and logical qubits.

A router interacts with a Routing object by using the methods apply_swap() and apply_int(). Optionally also attempt_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 method apply_int() is called on those interactions, it is skipped.

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

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

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

Attributes

active_subgraph

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)

Build the QAOA circuit from the Routing (self) in qiskit.

count_swap_gates()

Counts the number of swap gates in all Layers so far.

draw()

Plot all Layers of the routing in batches of 9.

property active_subgraph: Graph#

The topology of the QPU that is being used in the routing.

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 Layers from the end and tries to apply a swap gate between the qubits defined in gate at the earliest possible Layer. That means, as early as possible without crossing any other swap or interaction acting on the same HardQubits.

Parameters:
  • gate (HardEdge) – An edge between two HardQubits where the swap should be applied.

  • attempt_int (bool) – Boolean saying whether an interaction gate should be combined with the swap.

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 Layers from the end and tries to apply an interaction gate between the qubits defined in gate at the earliest possible Layer. That means, as early as possible without crossing any other swap or interaction acting on the same HardQubits. If an interaction has strength 0, it isn’t added!

Parameters:

gate (HardEdge) – An edge between two HardQubits 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 HardQubits where the interaction should be applied.

Return type:

None

count_swap_gates()[source]#

Counts the number of swap gates in all Layers so far.

Return type:

int

build_qiskit(betas, gammas)[source]#

Build the QAOA circuit from the Routing (self) in qiskit.

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

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

  2. It applies the interactions by going through the Layers of the Routing.

  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 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 draw(). Therefore, it has the shape of the QPU topology with edges colored based on what is happening on them in the given Layer.

  • 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