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_swappingallows 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
BinaryQuadraticModeldescription of the problem, necessary to create an instance ofRouting.qpu (QPU) – The QPU, necessary to create an instance of
Routingand to get the topology of the qubits. Theqpualso 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 toFalse, the line swapping strategy is not used at all (raising an error in case the grid swapping strategy fails). If set toNone(the default), the line swapping strategy is used as a fallback in case the grid swapping strategy fails.
- Returns:
A
Routingobject containing the routing created by using swap networks.- Raises:
TypeError – If the QPU’s layout doesn’t have integer coordinates and
do_line_swappingisFalse. 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_swappingisFalse
- Warns:
UserWarning – If the QPU’s layout doesn’t have integer coordinates and
do_line_swappingisNone. 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: