sn_router

Contents

sn_router#

iqm.qaoa.transpiler.sn.sn.sn_router(problem_bqm, qpu, do_line_swapping=None)[source]#

The function that implements the ‘swap network’ swapping strategies.

Implements the swap network approach from [5]. If the input BQM is not all-to-all connected, dummy interactions (of strength 0) are added to make it all-to-all connected. By default, it implements the grid swapping strategy (adapted for a generic rectangle, not just a square as shown in the paper). The grid swapping strategy tries to find a sufficient rectangle in the provided Crystal QPU (square lattice topology required). If there is no rectangle of suitable size in the QPU, the default behavior is to switch to the line swapping strategy as a fallback (corresponding to a rectangle of width 1). The optional input boolean do_line_swapping allows to configure whether the line swapping strategy should be used preferentially instead of the grid strategy or not at all.

Parameters:
  • problem_bqm (BinaryQuadraticModel) – The BinaryQuadraticModel description of the problem, necessary to create an instance of Routing.

  • qpu (QPU) – The QPU, necessary to create an instance of Routing and to get the topology of the qubits. The qpu also needs to contain the layout of the qubits with integer coordinates as an attribute.

  • do_line_swapping (bool | None) – If set to True, the line swapping strategy is used instead of the grid swapping strategy. If set to False, the line swapping strategy is not used at all (raising an error in case the grid swapping strategy fails). If set to None (the default), the line swapping strategy is used as a fallback in case the grid swapping strategy fails.

Returns:

A Routing object containing the routing created by using swap networks.

Raises:
  • TypeError – If the QPU’s layout doesn’t have integer coordinates and do_line_swapping is False. Integer coordinates are necessary to correctly identify where the swap and interaction gates need to be applied in the grid swap network strategy.

  • RuntimeError – If the algorithm doesn’t find a sufficiently large rectangle of qubits in the QPU and do_line_swapping is False

Warns:

UserWarning – If the QPU’s layout doesn’t have integer coordinates and do_line_swapping is None. In this case, the algorithm immediately switches to the line swapping strategy because integer layout coordinates are necessary for the grid swapping strategy.

Return type:

Routing