APIs

ZX-diagrams

ZXCalculus.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;

julia> using ZXCalculus.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
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.ZXGraphMethod
ZXGraph(zxd::ZXDiagram)

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

julia> using ZXCalculus

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
Missing docstring.

Missing docstring for ZXCalculus.tcount(zxd::AbstractZXDiagram). Check Documenter's build log for details.

ZXCalculus.phaseMethod
phase(zxd, v)

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

source
Missing docstring.

Missing docstring for LightGraphs.nv(zxd::ZXDiagram). Check Documenter's build log for details.

Missing docstring.

Missing docstring for LightGraphs.ne(::ZXDiagram). Check Documenter's build log for details.

Missing docstring.

Missing docstring for LightGraphs.neighbors(::ZXDiagram, v). Check Documenter's build log for details.

ZXCalculus.add_spider!Function
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.insert_spider!Function
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

Pushing gates

ZXCalculus.push_gate!Function
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.pushfirst_gate!Function
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

Simplification

ZXCalculus.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 Paulis spiders adjancent to boundary spiders
  • Rule{:p2}(): rule p2
  • Rule{:p3}(): rule p3
  • Rule{:id}(): rule id
  • Rule{:gf}(): gadget fushion rule
source
Base.matchFunction
match(r, zxd)

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

source
ZXCalculus.rewrite!Function
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

Circuit extraction