Layer#

class iqm.qaoa.transpiler.routing.Layer(qpu, int_gates=None, swap_gates=None)[source]#

Bases: object

A class describing one layer of the QAOA phase separator, consisting of swap and interaction gates.

The class knows about the QPU topology (from qpu) and uses it to decide which gates are applicable. A Layer object contains an internal copy of the QPU graph iqm.qaoa.transpiler.quantum_hardware.QPU.hardware_graph, but with edges labelled based on whether an interaction or a swap occurs along that edge in this layer. Similarly, the nodes are labelled based on whether they’re “occupied” in the present layer.

Parameters:
  • qpu (QPU) – A QPU object, containing the underlying QPU topology.

  • int_gates (set[HardEdge] | None) – A set of HardEdge interaction gates to be implemented in the layer. Further interaction gates may be added to the layer by using apply_int_gate().

  • swap_gates (set[HardEdge] | None) – A set of HardEdge swap gates to be implemented in the layer. Further swap gates may be added to the layer by using apply_swap_gate().

Methods

_qbs_not_involved_in_other_gate(gate)

Are the two qubits involved in the proposed gate not already involved in other gates?

apply_int_gate(gate)

Apply an interaction gate if it is applicable within the given layer.

apply_swap_gate(gate)

Apply swap gate if it is applicable within the given layer.

draw([mapping, ax, show])

Plot a sketch of the QPU, coloring the physical couplers based on the gate applied.

int_gate_applicable(gate)

Can the proposed interaction gate be executed within the given layer?

swap_gate_applicable(gate)

Can the proposed swap gate be executed within the given layer?

int_gate_applicable(gate)[source]#

Can the proposed interaction gate be executed within the given layer?

Goes through a few checks:

  • If the required connection doesn’t exist in the QPU, return False.

  • If there is already a gate applied between these qubits, and it’s the swap gate, return True since the interaction gate can be combined with it. If it’s not a simple swap gate, return False.

  • Otherwise, check if either of the qubits is involved in other gates and return the outcome of that.

Parameters:

gate (HardEdge) – The pair of qubits for which we’re checking the applicability of an interaction gate.

Return type:

bool

apply_int_gate(gate)[source]#

Apply an interaction gate if it is applicable within the given layer.

Parameters:

gate (HardEdge) – The pair of qubits between which we apply the interaction gate.

Raises:

ValueError – If for whatever reason the interaction gate cannot be applied in this layer.

Return type:

None

swap_gate_applicable(gate)[source]#

Can the proposed swap gate be executed within the given layer?

Goes through a few checks:

  • If the required connection doesn’t exist in the QPU, return False.

  • If there is already a swap gate between these qubits, return True (since the new swap gate can cancel it).

  • If there is already an interaction gate between these qubits, return True (since the swap gate can combine with it).

  • Otherwise, check if either of the qubits is involved in other gates.

Parameters:

gate (HardEdge) – The pair of qubits for which we’re checking the applicability of a swap gate.

Return type:

bool

apply_swap_gate(gate)[source]#

Apply swap gate if it is applicable within the given layer.

Parameters:

gate (HardEdge) – The pair of qubits between which we apply the swap gate.

Raises:

ValueError – If for whatever reason the swap gate cannot be applied in this layer.

Return type:

None

draw(mapping=None, ax=None, show=True)[source]#

Plot a sketch of the QPU, coloring the physical couplers based on the gate applied.

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

The labels for the hardware qubits in the plot are the names of the associated logical qubits.

Parameters:
  • mapping (Mapping | None) – The Mapping object used.

  • ax (Axes | None) – matplotlib.axes.Axes object to specify where to draw the picture.

  • show (bool) – Boolean to specift if the plot is to be shown (or e.g., processed somehow).

Return type:

None