APIs

Base.matchMethod
match(r, zxd)

Returns all matched vertices, which will be store in sturct Match, for rule r in a ZX-diagram zxd.

source
Graphs.neMethod
ne(zxd; count_mul = false)

Returns the number of edges of a ZX-diagram. If count_mul, it will return the sum of multiplicities of all multiple edges. Otherwise, it will return the number of multiple edges.

source
Graphs.neighborsMethod
neighbors(zxd, v; count_mul = false)

Returns a vector of vertices connected to v. If count_mul, there will be multiple copy for each vertex. Otherwise, each vertex will only appear once.

source
Graphs.nvMethod
nv(zxd)

Returns the number of vertices (spiders) of a ZX-diagram.

source
ZXCalculus.ZX.add_spider!Method
add_spider!(zxd, spider_type, phase = 0, connect = [])

Add a new spider which is of the type spider_type with phase phase and connected to the vertices connect.

source
ZXCalculus.ZX.ancilla_extractionMethod
ancilla_extraction(zxg::ZXGraph) -> ZXDiagram

Extract a quantum circuit from a general ZXGraph even without a gflow. It will introduce post-selection operators.

source
ZXCalculus.ZX.gaussian_eliminationMethod
gaussian_elimination(M[, steps])

Return result and steps of Gaussian elimination of matrix M. Here we assume that the elements of M is in binary field F_2 = {0,1}.

source
ZXCalculus.ZX.insert_spider!Method
insert_spider!(zxd, v1, v2, spider_type, phase = 0)

Insert a spider of the type spider_type with phase = phase, between two vertices v1 and v2. It will insert multiple times if the edge between v1 and v2 is a multiple edge. Also it will remove the original edge between v1 and v2.

source
ZXCalculus.ZX.phaseMethod
phase(zxd, v)

Returns the phase of a spider. If the spider is not a Z or X spider, then return 0.

source
ZXCalculus.ZX.push_gate!Method
push_gate!(zxd, ::Val{M}, locs...[, phase]; autoconvert=true)

Push an M gate to the end of qubit loc where M can be :Z, :X, :H, :SWAP, :CNOT and :CZ. If M is :Z or :X, phase will be available and it will push a rotation M gate with angle phase * π. If autoconvert is false, the input phase should be a rational numbers.

source
ZXCalculus.ZX.pushfirst_gate!Method
pushfirst_gate!(zxd, ::Val{M}, loc[, phase])

Push an M gate to the beginning of qubit loc where M can be :Z, :X, :H, :SWAP, :CNOT and :CZ. If M is :Z or :X, phase will be available and it will push a rotation M gate with angle phase * π.

source
ZXCalculus.ZX.rewrite!Method
rewrite!(r, zxd, matches)

Rewrite a ZX-diagram zxd with rule r for all vertices in matches. matches can be a vector of Match or just an instance of Match.

source
ZXCalculus.ZX.RuleType
Rule{L}

The struct for identifying different rules.

Rule for ZXDiagrams:

  • Rule{:f}(): rule f
  • Rule{:h}(): rule h
  • Rule{:i1}(): rule i1
  • Rule{:i2}(): rule i2
  • Rule{:pi}(): rule π
  • Rule{:c}(): rule c

Rule for ZXGraphs:

  • Rule{:lc}(): local complementary rule
  • Rule{:p1}(): pivoting rule
  • Rule{:pab}(): rule for removing Pauli spiders adjancent to boundary spiders
  • Rule{:p2}(): rule p2
  • Rule{:p3}(): rule p3
  • Rule{:id}(): rule id
  • Rule{:gf}(): gadget fushion rule
source
ZXCalculus.ZX.ZXDiagramMethod
ZXDiagram(nbits)

Construct a ZXDiagram of a empty circuit with qubit number nbit

julia> zxd = ZXDiagram(3)
ZX-diagram with 6 vertices and 3 multiple edges:
(S_1{input} <-1-> S_2{output})
(S_3{input} <-1-> S_4{output})
(S_5{input} <-1-> S_6{output})
source
ZXCalculus.ZX.ZXDiagramMethod
ZXDiagram(mg::Multigraph{T}, st::Dict{T, SpiderType.SType}, ps::Dict{T, P},
    layout::ZXLayout{T} = ZXLayout{T}(),
    phase_ids::Dict{T,Tuple{T, Int}} = Dict{T,Tuple{T,Int}}()) where {T, P}
ZXDiagram(mg::Multigraph{T}, st::Vector{SpiderType.SType}, ps::Vector{P},
    layout::ZXLayout{T} = ZXLayout{T}()) where {T, P}

Construct a ZXDiagram with all information.

julia> using Graphs, Multigraphs, ZXCalculus.ZX;

julia> using ZXCalculus.ZX.SpiderType: In, Out, H, Z, X;

julia> mg = Multigraph(5);

julia> for i = 1:4
           add_edge!(mg, i, i+1)
       end;

julia> ZXDiagram(mg, [In, Z, H, X, Out], [0//1, 1, 0, 1//2, 0])
ZX-diagram with 5 vertices and 4 multiple edges:
(S_1{input} <-1-> S_2{phase = 1//1⋅π})
(S_2{phase = 1//1⋅π} <-1-> S_3{H})
(S_3{H} <-1-> S_4{phase = 1//2⋅π})
(S_4{phase = 1//2⋅π} <-1-> S_5{output})
source
ZXCalculus.ZX.ZXGraphMethod
ZXGraph(zxd::ZXDiagram)

Convert a ZX-diagram to graph-like ZX-diagram.

julia> using ZXCalculus.ZX

julia> zxd = ZXDiagram(2); push_gate!(zxd, Val{:CNOT}(), 2, 1);

julia> zxg = ZXGraph(zxd)
ZX-graph with 6 vertices and 5 edges:
(S_1{input} <-> S_5{phase = 0//1⋅π})
(S_2{output} <-> S_5{phase = 0//1⋅π})
(S_3{input} <-> S_6{phase = 0//1⋅π})
(S_4{output} <-> S_6{phase = 0//1⋅π})
(S_5{phase = 0//1⋅π} <-> S_6{phase = 0//1⋅π})
source
Base.matchMethod
match(r, zxwd)

Returns all matched vertices, which will be store in sturct Match, for rule r in a ZXW-diagram zxwd.

source
Graphs.neMethod
ne(zxwd; count_mul = false)

Returns the number of edges of a ZXW-diagram. If count_mul, it will return the sum of multiplicities of all multiple edges. Otherwise, it will return the number of multiple edges.

source
Graphs.neighborsMethod
neighbors(zxwd, v; count_mul = false)

Returns a vector of vertices connected to v. If count_mul, there will be multiple copy for each vertex. Otherwise, each vertex will only appear once.

source
Graphs.nvMethod
nv(zxwd)

Returns the number of vertices (spiders) of a ZXW-diagram.

source
ZXCalculus.ZX.push_gate!Method
push_gate!(zxwd, ::Val{M}, locs...[, phase]; autoconvert=true)

Push an M gate to the end of qubit loc where M can be :Z, :X, :H, :SWAP, :CNOT and :CZ. If M is :Z or :X, phase will be available and it will push a rotation M gate with angle phase * π. If autoconvert is false, the input phase should be a rational numbers.

source
ZXCalculus.ZX.pushfirst_gate!Method
pushfirst_gate!(zxwd, ::Val{M}, loc[, phase])

Push an M gate to the beginning of qubit loc where M can be :Z, :X, :H, :SWAP, :CNOT and :CZ. If M is :Z or :X, phase will be available and it will push a rotation M gate with angle phase * π.

source
ZXCalculus.ZX.rewrite!Method
rewrite!(r, zxd, matches)

Rewrite a ZX-diagram zxd with rule r for all vertices in matches. matches can be a vector of Match or just an instance of Match.

source
ZXCalculus.ZXW.add_spider!Method
add_spider!(zxwd, spider, connect = [])

Add a new spider spider with appropriate parameter connected to the vertices connect.

source
ZXCalculus.ZXW.concat!Method

Concatenate two ZXWDiagrams, modify d1.

Remove outputs of d1 and inputs of d2. Then add edges between to vertices that was conntecting to outputs of d1 and inputs of d2. Assuming you don't concatenate two empty circuit ZXWDiagram

source
ZXCalculus.ZXW.insert_spider!Method
insert_spider!(zxwd, v1, v2, spider)

Insert a spider spider with appropriate parameter, between two vertices v1 and v2. It will insert multiple times if the edge between v1 and v2 is a multiple edge. Also it will remove the original edge between v1 and v2.

source
ZXCalculus.ZXW.int_prep!Method

Prepare spider at loc for integration.

Perform the simplified step of zeroing out phase of spider and readying it for integration

  1. If target spider is X spider, turn it to Z by adding H to all its legs
  2. Pull out the Phase of the spider
  3. zero out the phase
  4. change the current spider back to its original type if necessary,

will generate one extra H spider.

source
ZXCalculus.ZXW.set_phase!Method
set_phase!(zxwd, v, p)

Set the phase of v in zxwd to p. If v is not a Z or X spider, then do nothing. If v is not in zxwd, then return false to indicate failure.

source
ZXCalculus.ZXW.stack_zxwd!Method

Stacking two ZXWDiagrams in place. Modify d1.

Performs tensor product of two ZXWDiagrams. The result is a ZXWDiagram with d1 on lower qubit indices. Assuming number of inputs and outputs of are the same for both d1 and d2.

source
Graphs.neMethod
ne(zwd)

Returns the number of edges of a ZW-diagram.

source
Graphs.nvMethod
nv(zwd)

Returns the number of vertices (spiders) of a ZW-diagram.

source
ZXCalculus.ZW.add_spider!Method
add_spider!(zwd, spider, connect = [])

Add a new spider spider with appropriate parameter connected to the half edges connect.

Had to make halfedge class 1 citizen because there will be ambiguity Consider A to B and there are multiple edges to A and from A to B

source
ZXCalculus.ZW.insert_spider!Method
insert_spider!(zwd, he1, spider)

Insert a spider spider with appropriate parameter on the half-edge prior to he1. v1 <- he1 - v2 becomes v1 <- he1 - v2 <- henew - vnew

source
ZXCalculus.ZW.parameterMethod
parameter(zwd, v)

Returns the parameter of a spider. If the spider is not a monoZ or binZ spider, then return 0.

source
ZXCalculus.ZW.set_phase!Method
set_phase!(zwd, v, p)

Set the phase of v in zwd to p. If v is not a monoZ or binZ spider, then do nothing. If v is not in zwd, then return false to indicate failure.

source
ZXCalculus.ZW.ZWDiagramMethod
ZWDiagram(nbits::T, ::Type{P}) where {T<:Integer}

Create a ZW-diagram with nbits input and output qubits.

Scalar is parameterized to be P.

source
ZXCalculus.Utils.ParameterType
Parameter

The Algebraic Data Type for representing parameter related to spider. PiUnit(x) represents the the phase of a number exp(im*x*π). Factor(x) represents a number x.

source
ZXCalculus.PMG.add_facet_to_boarder!Method
add_facet_to_boarder!(pmg::PlanarMultigraph{T}, h::T, g::T) where {T<:Integer}

Creates a facet with edge connecting the destination of h and g.

h and g needs to be in ccw order

Reference

source
ZXCalculus.PMG.create_edge!Method
create_edge!(pmg::PlanarMultigraph{T}, vs::T, vd::T) where {T<:Integer}

Create an a pair of halfedge from vs to vd, add to PlanarMultigraph pmg. Facet information is not updated yet but set to default value of 0. Vertex to halfedge is updated and set to the two newly added half edges.

source
ZXCalculus.PMG.create_vertex!Method
create_vertex!(g::PlanarMultigraph{T}; mul::Int = 1) where {T<:Integer}

Create vertices.

Create mul of vertices and record them in PlanarMultigraph g's v_max field.

source
ZXCalculus.PMG.gc_vertex!Method
gc_vertex!(pmg::PlanarMultigraph{T}, vs::Vector{T}) where {T<:Integer}

Garbage collect vertices that's no longer connected to any edge.

source
ZXCalculus.PMG.join_facet!Method
join_facet!(pmg::PlanarMultigraph{T}, h::T) where {T}

Join two facets incident to h and it's twin into one.

The facet incident to h's twin is removed.

source
ZXCalculus.PMG.join_vertex!Method
join_vertex!(pmg::PlanarMultigraph{T}, h::T) where {T<:Integer}

Join two vertices connected by a HalfEdge into one.

Provides the removal of an edge.

source
ZXCalculus.PMG.make_hole!Method
make_hole!(pmg::PlanarMultigraph{T}, h::T) where {T<:Integer}

Convert the facet incident to a half edge into a hole.

Makes all the half edges in the facet a boundary halfedge.

Reference

source
ZXCalculus.PMG.prevMethod
prev(g::PlanarMultigraph{T}, he_id::T) where {T<:Integer}

Provides Previous Half Edge of a facet. HDS is bidi

source
ZXCalculus.PMG.split_edge!Method
split_edge!(pmg::PlanarMultigraph{T}, h::T) where {T<:Integer}

Split an edge into two consecutive ones. 1->2->3 becomes 1->4->2->3

source
ZXCalculus.PMG.split_facet!Method
split_facet!(pmg::PlanarMultigraph{T}, h::T, g::T) where {T<:Integer}

Split a facet incident to h and g into two facets.

Precondition

  1. h and g are in the same facet
  2. h and g are not the same half edge
  3. Cannot be used to split the faces incident to the multiedge.
source
ZXCalculus.PMG.split_vertex!Method
split_vertex!(g::PlanarMultigraph{T}, he1::T, he2::T) where {T<:Integer}

Split a vertex into 2 vertices.

Connect the two vertices with a new pair of half edges. he1 and he2 are half edges that marks the start and end of half edges that remain on v1.

After splitting, h points to the newly added vertex

Reference

source
ZXCalculus.PMG.trace_faceMethod
trace_face(g::PlanarMultigraph{T}, f::T; safe_trace = false) where {T}

Return the half edges of a face.

If safe_trace is true, then the half edges are returned in scrambled order. Otherwise, the returned half edges are in counter clockwise order but is not guaranteed to be consitent with he2f.

source
ZXCalculus.PMG.PlanarMultigraphType
PlanarMultigraph{T<:Integer}

Implements a planar multigraph with a maximal HDS Structure.

Features

  1. Stores Forward Half Edge pointer in facet
  2. Vertex linked
  3. Face Linked

References:

Our implementation is based heavily on the CGAL Library. A good introduction on the HDS Structure and the Polyhedron3 Object which gives the boundary representation of a 2-manifold can be found in this paper.

TODO: Proof of Completeness for Euler Operations with Preconditions In the

CGAL Library, the Euler Operations are implemented with preconditions. It was pointed out that Euler Operations are closed for orientable 2-manifolds in paper where the detailed proof is in book. It was further pointed out in paper that Euler Operations are complete in Theorem 4.4.

The question remains whether the completeness remains for the preconditions attached. One way of proving is to show that for the Euler Operations used in Theorem 4.4, we could always construct them out of the Euler Operations in CGAL Library with preconditions?

source