PositionedZX#
- class tqec.interop.PositionedZX(g, positions)[source]#
Bases:
object
A ZX graph with 3D positions and additional constraints.
The constraints are:
The vertex IDs in the graph match the position keys exactly.
The neighbors are all shifted by 1 in the 3D positions.
All the spiders are Z(0) or X(0) or Z(1/2) or Boundary spiders.
Boundary and Z(1/2) spiders are dangling, and Z(1/2) connects to the time direction.
There are no 3D corners.
- Parameters:
g (GraphS) – The ZX graph.
positions (Mapping[int, Position3D]) – A dictionary mapping vertex IDs to their 3D positions.
- Raises:
TQECException – If the constraints are not satisfied.
Methods
__init__
(g, positions)A ZX graph with 3D positions and additional constraints.
check_preconditions
(g, positions)Check the preconditions for the ZX graph with 3D positions.
draw
(*[, figsize, title, node_size, ...])Plot the
PositionedZX
using matplotlib.from_block_graph
(block_graph)Convert a
BlockGraph
to a ZX graph with 3D positions.get_direction
(v1, v2)Return the direction connecting two vertices.
Convert the positioned ZX graph to a block graph.
Attributes
g
Return the internal ZX graph.
p2v
Return the mapping from 3D positions to vertices.
positions
Return the 3D positions of the vertices.
Detailed methods
- __init__(g, positions)[source]#
A ZX graph with 3D positions and additional constraints.
The constraints are:
The vertex IDs in the graph match the position keys exactly.
The neighbors are all shifted by 1 in the 3D positions.
All the spiders are Z(0) or X(0) or Z(1/2) or Boundary spiders.
Boundary and Z(1/2) spiders are dangling, and Z(1/2) connects to the time direction.
There are no 3D corners.
- Parameters:
g (GraphS) – The ZX graph.
positions (Mapping[int, Position3D]) – A dictionary mapping vertex IDs to their 3D positions.
- Raises:
TQECException – If the constraints are not satisfied.
- Return type:
None
- static check_preconditions(g, positions)[source]#
Check the preconditions for the ZX graph with 3D positions.
- Parameters:
g (GraphS)
positions (Mapping[int, Position3D])
- Return type:
None
- draw(*, figsize=(5, 6), title=None, node_size=400, hadamard_size=200, edge_width=1)[source]#
Plot the
PositionedZX
using matplotlib.- Parameters:
graph – The ZX graph to plot.
figsize (tuple[float, float]) – The figure size. Default is
(5, 6)
.title (str | None) – The title of the plot. Default to the name of the graph.
node_size (int) – The size of the node in the plot. Default is
400
.hadamard_size (int) – The size of the Hadamard square in the plot. Default is
200
.edge_width (int) – The width of the edge in the plot. Default is
1
.
- Returns:
A tuple of the figure and the axes.
- Return type:
tuple[Figure, Axes3D]
- static from_block_graph(block_graph)[source]#
Convert a
BlockGraph
to a ZX graph with 3D positions.The conversion process is as follows:
For each cube in the block graph, convert it to a ZX vertex.
For each pipe in the block graph, add an edge to the ZX graph with the corresponding endpoints and Hadamard flag.
- Parameters:
block_graph (BlockGraph) – The block graph to be converted to a ZX graph.
- Returns:
The
PositionedZX
object converted from the block graph.- Return type:
- get_direction(v1, v2)[source]#
Return the direction connecting two vertices.
- Parameters:
v1 (int)
v2 (int)
- Return type: