pytket.routing

class pytket.routing.Architecture

The base architecture class, describing the connectivity of qubits on a device.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket.routing.Architecture, connections: List[Tuple[int, int]]) -> None

The constructor for an architecture with connectivity between qubits.

Parameters

connections – A list of pairs representing qubit indices that can perform two-qubit operations

  1. __init__(self: pytket.routing.Architecture, connections: List[Tuple[pytket.circuit.Node, pytket.circuit.Node]]) -> None

The constructor for an architecture with connectivity between qubits.

Parameters

connections – A list of pairs representing Nodes that can perform two-qubit operations

static from_dict(arg0: json) pytket.routing.Architecture

Construct Architecture instance from JSON serializable dict representation of the Architecture.

to_dict(self: pytket.routing.Architecture) json

Return a JSON serializable dict representation of the Architecture. :return: dict containing nodes and links.

property coupling

Returns the coupling map of the Architecture as UnitIDs.

property nodes

Returns all nodes of architecture as UnitID objects.

class pytket.routing.FullyConnected

Architecture class for number of qubits connected to every other qubit.

__init__(self: pytket.routing.FullyConnected, nodes: int) None

The constructor for a FullyConnected Architecture with some undirected connectivity between qubits.

:param number of qubits

class pytket.routing.GraphPlacement

The GraphPlacement class, contains methods for getting maps between Circuit Qubits and Architecture Nodes and for relabelling Circuit Qubits.

__init__(self: pytket.routing.GraphPlacement, arc: pytket.routing.Architecture) None

The constructor for a GraphPlacement object. The Architecture object describes the connectivity between qubits.

Parameters

arc – An Architecture object.

modify_config(self: pytket.routing.GraphPlacement, **kwargs) None

Overides default Placement parameters to given values. Timeout is in milliseconds :param **kwargs: Parameters for placement: (int)depth_limit=5, (int)max_interaction_edges=edges in the device graph, (int)max_matches=10000, (int)contraction_ratio=10, (int)timeout=60000.

class pytket.routing.LinePlacement

The LinePlacement class, contains methods for getting maps between Circuit Qubits and Architecture Nodes and for relabelling Circuit Qubits.

__init__(self: pytket.routing.LinePlacement, arc: pytket.routing.Architecture) None

The constructor for a LinePlacement object. The Architecture object describes the connectivity between qubits.

Parameters

arc – An Architecture object.

class pytket.routing.NoiseAwarePlacement

The NoiseAwarePlacement class, contains methods for getting maps between Circuit Qubits and Architecture Nodes and for relabelling Circuit Qubits. It uses gate error rates and readout errors to find the best placement map.

__init__(self: pytket.routing.NoiseAwarePlacement, arc: pytket.routing.Architecture, node_errors: Dict[pytket.circuit.Node, float] = {}, link_errors: Dict[Tuple[pytket.circuit.Node, pytket.circuit.Node], float] = {}, readout_errors: Dict[pytket.circuit.Node, float] = {}) None

The constructor for a NoiseAwarePlacement object. The Architecture object describes the connectivity between qubits. The dictionaries passed as parameters indicate the average gate errors for single- and two-qubit gates as well as readout errors. If no error is given for a given node or pair of nodes, the fidelity is assumed to be 1.

Parameters
  • arc – An Architecture object

  • node_errors – a dictionary mapping nodes in the architecture to average single-qubit gate errors

  • link_errors – a dictionary mapping pairs of nodes in the architecture to average two-qubit gate errors

  • readout_errors – a dictionary mapping nodes in the architecture to average measurement readout errors.

modify_config(self: pytket.routing.NoiseAwarePlacement, **kwargs) None

Overides default Placement parameters to given values. Timeout is in milliseconds :param **kwargs: Parameters for placement: (int)depth_limit=5, (int)max_interaction_edges=edges in the device graph, (int)max_matches=10000, (int)contraction_ratio=10, (int)timeout=60000.

class pytket.routing.Placement

The base Placement class, contains methods for getting maps between Circuit Qubits and Architecture Nodes and for relabelling Circuit Qubits.

__init__(self: pytket.routing.Placement, arc: pytket.routing.Architecture) None

The constructor for a Placement object. The Architecture object describes the connectivity between qubits.

Parameters

arc – An Architecture object.

get_placement_map(self: pytket.routing.Placement, circuit: pytket.circuit.Circuit) Dict[pytket.circuit.Qubit, pytket.circuit.Node]

Returns a map from logical to physical qubits that is Architecture appropriate for the given Circuit.

Parameters

circuit – The circuit a map is designed for.

Returns

dictionary mapping Qubit s to Node s

get_placement_maps(self: pytket.routing.Placement, circuit: pytket.circuit.Circuit) List[Dict[pytket.circuit.Qubit, pytket.circuit.Node]]

Returns a list of maps from logical to physical qubits that are Architecture appropriate for the given Circuit. Each map is estimated to given a similar SWAP overheard after routing.

Parameters

circuit – The circuit the maps are designed for.

Returns

list of dictionaries mapping Qubit s to Node s

place(self: pytket.routing.Placement, circuit: pytket.circuit.Circuit) bool

Relabels Circuit Qubits to Architecture Nodes and ‘unplaced’. For base Placement, all Qubits and labelled ‘unplaced’.

Parameters

circuit – The Circuit being relabelled.

static place_with_map(circuit: pytket.circuit.Circuit, qmap: Dict[pytket.circuit.Qubit, pytket.circuit.Node]) bool

Relabels Circuit Qubits to Architecture Nodes using given map.

Parameters
  • circuit – The circuit being relabelled

  • qmap – The map from logical to physical qubits to apply.

class pytket.routing.RingArch

Architecture class for number of qubits arranged in a ring.

__init__(self: pytket.routing.RingArch, nodes: int) None

The constructor for a RingArchitecture with some undirected connectivity between qubits.

:param number of qubits

class pytket.routing.SquareGrid

Architecture class for qubits arranged in a square lattice of given number of rows and columns. Qubits are arranged with qubits values increasing first along rows then along columns i.e. for a 3 x 3 grid:

0 1 2

3 4 5

6 7 8

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pytket.routing.SquareGrid, n_rows: int, n_columns: int) -> None

The constructor for a Square Grid architecture with some undirected connectivity between qubits.

Parameters
  • n_rows – The number of rows in the grid

  • n_columns – The number of columns in the grid

  1. __init__(self: pytket.routing.SquareGrid, n_rows: int, n_columns: int, n_layers: int) -> None

The constructor for a Square Grid architecture with some undirected connectivity between qubits.

Parameters
  • n_rows – The number of rows in the grid

  • n_columns – The number of columns in the grid

  • n_layers – The number of layers of grids

qind_to_squind(self: pytket.routing.SquareGrid, index: int) Tuple[int, int]

Converts a single qubit index to a (row,column) index for a square grid.

Parameters

index – The global qubit index

Returns

the corresponding grid index as a pair (row,column)

squind_to_qind(self: pytket.routing.SquareGrid, row: int, column: int) int

Converts a (row,column) index for a square grid to a single qubit index

Parameters
  • row – The given row index

  • column – The given column index

Returns

the corresponding global qubit index

pytket.routing.place_with_map(circuit: pytket.circuit.Circuit, qmap: Dict[pytket.circuit.Qubit, pytket.circuit.Node]) None

Relabels Circuit Qubits according to a map. If provided map is partial, remaining Circuit Qubits are left ‘unplaced’.

Parameters
  • circuit – The Circuit being relabelled.

  • qmap – The map from logical to physical qubits to apply.

pytket.routing.route(circuit: pytket.circuit.Circuit, architecture: pytket.routing.Architecture, **kwargs) pytket.circuit.Circuit

Routes the circuit subject to the connectivity of the input architecture, given configuration settings.

Parameters
  • circuit – The circuit to be routed.

  • architecture – A representation of the qubit connectivity constraints of the device.

  • **kwargs – Parameters for routing: (int)swap_lookahead=50, (int)bridge_lookahead=4, (int)bridge_interactions=2, (float)bridge_exponent=0,

Returns

the routed Circuit