APIs
ZX-diagrams
ZXCalculus.ZXDiagram
— TypeZXDiagram{T, P}
This is the type for representing ZX-diagrams.
ZXCalculus.ZXDiagram
— MethodZXDiagram(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})
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})
ZXCalculus.ZXGraph
— TypeZXGraph{T, P}
This is the type for representing the graph-like ZX-diagrams.
ZXCalculus.ZXGraph
— MethodZXGraph(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⋅π})
ZXCalculus.ZXLayout
— TypeZXLayout
A struct for the layout information of ZXDiagram
and ZXGraph
.
ZXCalculus.qubit_loc
— Functionqubit_loc(layout, v)
Return the qubit number corresponding to the spider v
.
Missing docstring for ZXCalculus.tcount(zxd::AbstractZXDiagram)
. Check Documenter's build log for details.
ZXCalculus.spider_type
— Methodspider_type(zxd, v)
Returns the spider type of a spider.
ZXCalculus.phase
— Methodphase(zxd, v)
Returns the phase of a spider. If the spider is not a Z or X spider, then return 0.
Missing docstring for LightGraphs.nv(zxd::ZXDiagram)
. Check Documenter's build log for details.
Missing docstring for LightGraphs.ne(::ZXDiagram)
. Check Documenter's build log for details.
Missing docstring for LightGraphs.neighbors(::ZXDiagram, v)
. Check Documenter's build log for details.
ZXCalculus.is_interior
— Methodis_interior(zxg::ZXGraph, v)
Return true
if v
is a interior spider of zxg
.
ZXCalculus.add_spider!
— Functionadd_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
.
ZXCalculus.insert_spider!
— Functioninsert_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
.
ZXCalculus.rem_spiders!
— Functionrem_spiders!(zxd, vs)
Remove spiders indexed by vs
.
ZXCalculus.rem_spider!
— Functionrem_spider!(zxd, v)
Remove a spider indexed by v
.
Pushing gates
ZXCalculus.push_gate!
— Functionpush_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.
ZXCalculus.pushfirst_gate!
— Functionpushfirst_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 * π
.
Simplification
ZXCalculus.phase_teleportation
— Functionphase_teleportation(zxd)
Reducing T-count of zxd
with the algorithms in arXiv:1903.10477.
ZXCalculus.clifford_simplification
— Functionclifford_simplification(zxd)
Simplify zxd
with the algorithms in arXiv:1902.03178.
ZXCalculus.Rule
— TypeRule{L}
The struct for identifying different rules.
Rule for ZXDiagram
s:
Rule{:f}()
: rule fRule{:h}()
: rule hRule{:i1}()
: rule i1Rule{:i2}()
: rule i2Rule{:pi}()
: rule πRule{:c}()
: rule c
Rule for ZXGraph
s:
Rule{:lc}()
: local complementary ruleRule{:p1}()
: pivoting ruleRule{:pab}()
: rule for removing Paulis spiders adjancent to boundary spidersRule{:p2}()
: rule p2Rule{:p3}()
: rule p3Rule{:id}()
: rule idRule{:gf}()
: gadget fushion rule
ZXCalculus.simplify!
— Functionsimplify!(r, zxd)
Simplify zxd
with the rule r
.
Base.replace!
— Functionreplace!(r, zxd)
Match and replace with the rule r
.
Base.match
— Functionmatch(r, zxd)
Returns all matched vertices, which will be store in sturct Match
, for rule r
in a ZX-diagram zxd
.
ZXCalculus.rewrite!
— Functionrewrite!(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
.
ZXCalculus.Match
— TypeMatch{T<:Integer}
A struct for saving matched vertices.
Circuit extraction
ZXCalculus.circuit_extraction
— Methodcircuit_extraction(zxg::ZXGraph)
Extract circuit from a graph-like ZX-diagram.