pytket.placement

In order for the constraints of a Backend to be solved we must first assign device qubits to device-independent (or program) qubits. This module contains three placement methods to perform such an assignment.

For more on qubit placement (and routing in general) see the qubit mapping and routing tutorial and the corresponding entry in the user manual.

class pytket.placement.GraphPlacement

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

__init__(self: pytket.placement.GraphPlacement, arc: pytket.architecture.Architecture, maximum_matches: int = 1000, timeout: int = 1000, maximum_pattern_gates: int = 100, maximum_pattern_depth: int = 100) None

The constructor for a GraphPlacement object. The Architecture object describes the connectivity between qubits. To find a qubit to node assignment, this method constructs a pattern graph where vertices are Circuit qubits and edges mean a pair of qubits have an interaction in the circuit, and then tries to find a weighted subgraph monomorphsim to the architecture connectivity, or target, graph. Edges in the pattern graph are weighted by the circuit depth at which the interaction between a pair of qubit occurs. The number of edges added to the pattern graph is effected by the maximum_pattern_gates and maximum_pattern_depth arguments. If no subgraph monomorphism can be found, lower edge weights are removed from the pattern graph, are more edges are added to the target graph. Edges added to the pattern graph are weighted lower to reflect what the distance between the Nodes they are added between was on the original target graph.

Parameters:
  • arc – An Architecture object.

  • maximum_matches – The total number of weighted subgraph monomorphisms that can be found before matches are returned.

  • timeout – Total time in milliseconds before stopping search for monomorphisms.

  • maximum_pattern_gates – The upper bound on the number of circuit gates used to construct the pattern graph for finding subgraph monomorphisms.

  • maximum_pattern_depth – The upper bound on the circuit depth gates are added to the pattern graph to for finding subgraph monomorphisms.

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

Deprecated and no longer modifies parameters for finding solutions. Please create a new GraphPlacement object instead

class pytket.placement.LinePlacement

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

__init__(self: pytket.placement.LinePlacement, arc: pytket.architecture.Architecture, maximum_line_gates: int = 100, maximum_line_depth: int = 100) None

The constructor for a LinePlacement object. The Architecture object describes the connectivity between qubits. In this class, a reduced qubit interaction subgraph is constructed where each node has maximum outdegree 2 and does not construct a circle (i.e. lines). To place the Circuit, a Hamiltonian Path is found in the Architecture and this subgraph of lines is assigned along it.

Parameters:
  • arc – An Architecture object.

  • maximum_line_gates – maximum number of gates in the circuit considered when constructing lines for assigning to the graph

  • maximum_line_depth – maximum depth of circuit considered when constructing lines for assigning to the graph

class pytket.placement.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.placement.NoiseAwarePlacement, arc: pytket.architecture.Architecture, node_errors: dict[pytket.unit_id.Node, float] = {}, link_errors: dict[tuple[pytket.unit_id.Node, pytket.unit_id.Node], float] = {}, readout_errors: dict[pytket.unit_id.Node, float] = {}, maximum_matches: int = 1000, timeout: int = 1000, maximum_pattern_gates: int = 100, maximum_pattern_depth: int = 100) 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 readouterrors. 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.

  • maximum_matches – The total number of weighted subgraph monomorphisms that can be found before matches are returned.

  • timeout – Total time in milliseconds before stopping search for monomorphisms.

  • maximum_pattern_gates – The upper bound on the number of circuit gates used to construct the pattern graph for finding subgraph monomorphisms.

  • maximum_pattern_depth – The upper bound on the circuit depth gates are added to the pattern graph to for finding subgraph monomorphisms.

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

Deprecated and no longer modifies paramters for finding solutions. Please create a new NoiseAwarePlacement object instead

class pytket.placement.Placement

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

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

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

Parameters:

arc – An Architecture object.

static from_dict(arg0: dict) pytket.placement.Placement

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

get_placement_map(self: pytket.placement.Placement, circuit: pytket.circuit.Circuit) dict[pytket.unit_id.Qubit, pytket.unit_id.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.placement.Placement, circuit: pytket.circuit.Circuit, matches: int = 100) list[dict[pytket.unit_id.Qubit, pytket.unit_id.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.

  • matches – The maximum number of maps returned by the method.

Returns:

list of dictionaries mapping Qubit s to Node s

place(self: pytket.placement.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.unit_id.Qubit, pytket.unit_id.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.

to_dict(self: pytket.placement.Placement) object

Return a JSON serializable dict representation of the Placement.

Returns:

dict representing the Placement.

pytket.placement.place_fully_connected(circuit: pytket.circuit.Circuit, fully_connected: pytket.architecture.FullyConnected) None

Relabels all Circuit Qubits to the Node objects of a FullyConnected object.

Parameters:
  • circuit – The Circuit being relabelled.

  • fully_connected – FullyConnected object Qubits being relabelled to match.

pytket.placement.place_with_map(circuit: pytket.circuit.Circuit, qmap: dict[pytket.unit_id.Qubit, pytket.unit_id.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.