Data structures

class pytket_dqc.circuits.hypergraph.Hypergraph

A representation of a hypergraph. Hypergraphs are represented by vertices and hyperedges, where hyperedges consist of a collection of two or more vertices. Since neighbourhoods and incident hyperedge list will be often used it is best to store them in the data structure.

Parameters:
  • vertex_list (list[Vertex]) – List of vertices

  • hyperedge_list (list[Hyperedge]) – List of hyperedges

  • hyperedge_dict (dict[Vertex, list[Hyperedge]]) – Maps each vertex to its incident hyperedges

  • vertex_neighbours (dict[Vertex, set[Vertex]]) – Maps each vertex to its neighbourhood

__init__()

Initialisation function. The hypergraph initialises as empty.

is_placement(placement: Placement) bool

Checks if a given placement is a valid placement of this hypergraph. Checks for example that all vertices are placed, and that every vertex placed is in the hypergraph.

Parameters:

placement (Placement) – The placement to check for validity

Returns:

Is the placement valid.

Return type:

bool

draw()

Draw hypergraph, using hypernetx package.

add_vertices(vertices: list[int])

Add list ov vertices to hypergraph.

Parameters:

vertices (list[Vertex]) – List of vertex indices

add_hyperedge(vertices: list[int], weight: int = 1, hyperedge_list_index: int | None = None, hyperedge_dict_index: list[int] | None = None)

Add hyperedge to hypergraph. Update vertex_neighbours.

Parameters:
  • vertices (list[Vertex]) – List of vertices in hyperedge

  • weight (int) – Hyperedge weight

  • hyperedge_list_index (list[int]) – index in hyperedge_list at which the new hyperedge will be added.

  • hyperedge_dict_index – index in hyperedge_dict at which the new hyperedge will be added. Note that hyperedge_dict_index should be the same length as vertices.

Raises:
  • Exception – Raised if hyperedge does not contain at least 2 vertices

  • Exception – Raised if vertices in hyperedge are not in hypergraph.

merge_hyperedge(to_merge_hyperedge_list: list[pytket_dqc.circuits.hypergraph.Hyperedge]) Hyperedge

Merge vertices of each of the hyperedges in to_merge_hyperedge_list into a single hyperedge. The new hyperedge will appear in hyperedge_list at the lowest index of the hyperedges in to_merge_hyperedge_list.

Parameters:

to_merge_hyperedge_list (list[Hyperedge]) – List of hyperedges to merge.

Raises:
  • Exception – Raised if any of the hyperedges in to_merge_hyperedge_list are not in this hypergraph.

  • Exception – Raised if the weights of the hyperedges to merge do not match.

  • Exception – Raised if hyperedges to be merged are not unique.

split_hyperedge(old_hyperedge: Hyperedge, new_hyperedge_list: list[pytket_dqc.circuits.hypergraph.Hyperedge])

Split old_hyperedge into the hyperedges in new_hyperedge_list. The new hyperedges will appear in hyperedge_list at the same location as the old_hyperedge in the same order as they appear in new_hyperedge_list.

Parameters:
  • old_hyperedge (Hyperedge) – Hyperedge to split.

  • new_hyperedge_list (list[Hyperedge]) – List of hyperedges into which old_hyperedge should be split.

Raises:

Exception – Raised if new_hyperedge_list is not a valid split of old_hyperedge

remove_hyperedge(old_hyperedge: Hyperedge)

Remove hypergraph. Update vertex_neighbours.

Parameters:

old_hyperedge – Hyperedge to remove

Raises:

KeyError – Raised if old_hyperedge is not in hypergraph.

to_dict() dict[str, Union[list[int], list[dict], dict]]

Generate JSON serialisable dictionary representation of the Hypergraph.

Returns:

JSON serialisable dictionary representation of the Hypergraph.

Return type:

dict[str, Union[list[Vertex], list[dict]]]

classmethod from_dict(hypergraph_dict: dict[str, Union[list[int], list[dict], dict]]) Hypergraph

Construct Hypergraph instance from JSON serialisable dictionary representation of the Hypergraph.

Parameters:

hypergraph_dict (dict[str, Union[list[Vertex], list[dict], dict]]) – JSON serialisable dictionary representation of the Hypergraph

Returns:

Hypergraph instance constructed from hypergraph_dict.

Return type:

Hypergraph

class pytket_dqc.circuits.hypergraph_circuit.HypergraphCircuit(circuit: Circuit)

Class representing circuit to be distributed on a network. HypergraphCircuit is a child of Hypergraph. HypergraphCircuit adds additional information on top of Hypergraph which describes the correspondence to a circuit.

Parameters:
  • _circuit (Circuit) – Circuit to be distributed.

  • _vertex_circuit_map (dict[int, dict]) – Map from hypergraph vertices to circuit commands.

__init__(circuit: Circuit)

Initialisation function

Parameters:

circuit (Circuit) – Circuit to be distributed.

add_hyperedge(vertices: list[int], weight: int = 1, hyperedge_list_index: int | None = None, hyperedge_dict_index: list[int] | None = None)

Add hyperedge to hypergraph of circuit. Adds some checks on top of add_hypergraph in Hypergraph in order to ensure that the first vertex is a qubit, and that there is only one qubit vertex.

Parameters:
  • vertices (list[Vertex]) – List of vertices in hyperedge to add.

  • weight (int) – Hyperedge weight

  • hyperedge_list_index (int) – index in hyperedge_list at which the new hyperedge will be added.

  • hyperedge_dict_index – index in hyperedge_dict at which the new hyperedge will be added. Note that hyperedge_dict_index should be the same length as vertices.

Raises:

Exception – Raised if first vertex in hyperedge is not a qubit

Raised Exception:

Raised if there is more than one qubit vertex in the list of vertices.

to_dict() dict[str, Union[list[int], list[dict], dict]]

Generate JSON serialisable dictionary representation of the HypergraphCircuit.

Returns:

JSON serialisable dictionary representation of the HypergraphCircuit.

Return type:

dict[str, Union[list[Vertex], list[dict], dict]]

classmethod from_dict(hypergraph_circuit_dict: dict[str, Union[list[int], list[dict], dict]]) HypergraphCircuit

Construct HypergraphCircuit instance from JSON serialisable dictionary representation of the HypergraphCircuit.

Parameters:

hypergraph_circuit_dict (dict[str, Union[list[Vertex], list[dict], dict]]) – JSON serialisable dictionary representation of the HypergraphCircuit.

Returns:

HypergraphCircuit instance constructed from hypergraph_circuit_dict.

Return type:

HypergraphCircuit

class pytket_dqc.circuits.distribution.Distribution(circuit: HypergraphCircuit, placement: Placement, network: NISQNetwork)

Class containing all information required to generate pytket circuit.

__init__(circuit: HypergraphCircuit, placement: Placement, network: NISQNetwork)

Initialisation function for Distribution

Parameters:
  • circuit (HypergraphCircuit) – Circuit to be distributed, including its hypergraph.

  • placement (Placement) – A placement of the qubits and gates onto servers.

  • network (NISQNetwork) – Network onto which circuit is distributed.

Raises:
  • Exception – Raised if the placement is not valid for the circuit.

  • Exception – Raised if the placement is not valid for the packets.

cost() int

Return the number of ebits required to implement this distribution.

NOTE: this function does not guarantee that the distribution being analysed satisfies the bound to the link qubit registers. If you wish to take the bound into account, call to_pytket_circuit before calling this function. Alternatively, call ebit_cost on the distributed circuit.

Returns:

The number of ebits used in this distribution.

Return type:

int

non_local_gate_count() int

Scan the distribution and return the number of non-local gates. A non-local gate is a 2-qubit gate that acts in a server not containing one of the two qubits it acts on.

Returns:

A list of non-local gates

Return type:

int

detached_gate_count() int

Scan the distribution and return the number of detached gates in it. A detached gate is a 2-qubit gate that acts on link qubits on both ends; i.e. it is implemented away from both of its home servers.

Returns:

The number of detached gates

Return type:

int

to_pytket_circuit(satisfy_bound: bool = True, allow_update: bool = False) Circuit

Generate the circuit corresponding to this Distribution.

Parameters:
  • satisfy_bound – Whether the output circuit is only allowed to use as many link qubits per module as establisehd by the network’s communication capacity (if provided). Optional parameter, defaults to True.

  • allow_update – Whether the Distribution may be altered by this method, in order to make it satisfy the network’s communication capacity (in case it has been bounded). Optional parameter, defaults to False.

Raises:

ConstraintException – If a server’s communication capacity is exceeded, satisfy_bound was set to True and allow_update was set to False.

get_qubit_mapping() dict[pytket._tket.circuit.Qubit, pytket._tket.circuit.Qubit]

Mapping from the names of the original circuit’s qubits to the names of the hardware qubits, including whether they are link qubits or computation qubits and the module they belong to.

Returns:

The mapping of circuit qubits to hardware qubits.

Return type:

dict[Qubit, Qubit]

to_dict() dict[str, dict]

Generate JSON serialisable dictionary representation of the Distribution.

Returns:

JSON serialisable dictionary representation of the Distribution.

Return type:

dict[str, dict]

classmethod from_dict(distribution_dict: dict[str, dict]) Distribution

Construct Distribution instance from JSON serialisable dictionary representation of the Distribution.

Parameters:

distribution_dict (dict[str, dict]) – JSON serialisable dictionary representation of the Distribution

Returns:

Distribution instance constructed from distribution_dict.

Return type:

Distribution