Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of ZW Diagram (#99) #104

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pkg> add ZXCalculus

This project is highly inpsired by [PyZX](https://github.com/Quantomatic/pyzx)

The `ZXWDiagram` and `ZWDiagram` part is supported by the [OSPP 2023](https://summer-ospp.ac.cn/)

## License

MIT License
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ using Documenter
using DocThemeIndigo

using ZXCalculus
using ZXCalculus: ZXW, ZW
using Multigraphs

indigo = DocThemeIndigo.install(ZXCalculus)
makedocs(;
modules = [ZXCalculus],
modules = [ZXCalculus, ZXW, ZW],
format=Documenter.HTML(;
# ...
# put your indigo css in assets
Expand Down
100 changes: 99 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ZXCalculus.ZXGraph
ZXCalculus.ZXGraph(::ZXDiagram)
ZXCalculus.ZXLayout
ZXCalculus.qubit_loc
ZXCalculus.tcount(zxd::AbstractZXDiagram)
spider_type(zxd::ZXDiagram{T, P}, v::T) where {T<:Integer, P}
ZXCalculus.phase(zxd::ZXDiagram{T, P}, v::T) where {T<:Integer, P}
Graphs.nv(zxd::ZXDiagram)
Expand Down Expand Up @@ -48,3 +47,102 @@ ZXCalculus.Match
```@docs
ZXCalculus.circuit_extraction(zxg::ZXGraph{T, P}) where {T, P}
```

## ZXW-diagram
```@docs
ZXCalculus.ZXW.add_inout!
ZXCalculus.ZXW.substitute_variables!
ZXCalculus.biadjacency
ZXCalculus.ZXW.rem_spider!
ZXCalculus.continued_fraction
ZXCalculus.ZXW.symbol_vertices
ZXCalculus.ZXW.dagger
ZXCalculus.ZXW.add_spider!
ZXCalculus.tcount
ZXCalculus.Phase
ZXCalculus.round_phases!
ZXCalculus.gaussian_elimination
ZXCalculus.Scalar
ZXCalculus.ZXW.expval_circ!
Graphs.SimpleGraphs.rem_edge!
ZXCalculus.ZXW.parameter
ZXCalculus.ZXW.int_prep!
ZXCalculus.update_frontier!
ZXCalculus.ZXW.integrate!
ZXCalculus.set_column!
ZXCalculus.set_phase!
ZXCalculus.prev
ZXCalculus.ancilla_extraction
Graphs.SimpleGraphs.add_edge!
ZXCalculus.ZXW.stack_zxwd!
ZXCalculus.ZXW.get_outputs
ZXCalculus.scalar
ZXCalculus.get_inputs
ZXCalculus.ZW.get_inputs
ZXCalculus.column_loc
ZXCalculus.GEStep
ZXCalculus.ZXW.spider_type
ZXCalculus.ZXW.print_spider
ZXCalculus.ZXW.Parameter
ZXCalculus.ZXW.nqubits
ZXCalculus.set_qubit!
ZXCalculus.ZXW.insert_wtrig!
ZXCalculus.ZXW.concat!
ZXCalculus.ZXW.rem_spiders!
ZXCalculus.ZXW.insert_spider!
ZXCalculus.set_loc!
ZXCalculus.spiders
ZXCalculus.split_edge!
ZXCalculus.ZXW.import_edges!
ZXCalculus.get_outputs
ZXCalculus.ZXW.get_inputs
ZXCalculus.ZXW.import_non_in_out!
ZXCalculus.ZXW.set_phase!
ZXCalculus.ZXW.nout
```

# Planar Multigraph
```@docs
ZXCalculus.PlanarMultigraph
ZXCalculus.is_boundary
ZXCalculus.trace_face
ZXCalculus.new_edge
ZXCalculus.ϕ
ZXCalculus.nqubits
ZXCalculus.erase_facet!
ZXCalculus.create_face!
ZXCalculus.surrounding_half_edge
ZXCalculus.add_facet_to_boarder!
ZXCalculus.split_facet!
ZXCalculus.split_vertex!
ZXCalculus.add_vertex_and_facet_to_boarder!
ZXCalculus.create_edge!
ZXCalculus.join_facet!
ZXCalculus.create_vertex!
ZXCalculus.σ_inv
ZXCalculus.σ
ZXCalculus.make_hole!
ZXCalculus.gc_vertex!
ZXCalculus.HalfEdge
ZXCalculus.out_half_edge
ZXCalculus.n_conn_comp
ZXCalculus.join_vertex!
```

# ZW-diagrams
```@docs
ZXCalculus.ZW.ZWDiagram
ZXCalculus.ZW.insert_spider!
ZXCalculus.ZW.get_output_idx
ZXCalculus.ZW.nqubits
ZXCalculus.ZW.round_phases!
ZXCalculus.ZW.nout
ZXCalculus.ZW.get_input_idx
ZXCalculus.ZW.set_phase!
ZXCalculus.ZW.get_outputs
ZXCalculus.ZW.add_spider!
ZXCalculus.ZW.parameter
ZXCalculus.ZW.print_spider
ZXCalculus.ZW.spider_type
```

70 changes: 49 additions & 21 deletions src/ZXCalculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using OMEinsum
import Multigraphs: has_vertex
using ..ZXCalculus
using ..ZXCalculus: safe_convert, add_phase!
import ..pushfirst_gate!, ..push_gate!, ..rewrite
import ..pushfirst_gate!, ..push_gate!
import ..rewrite!, ..add_power!, ..add_edge!, ..vertices, ..nv, ..round_phases!


Expand All @@ -73,30 +73,58 @@ include("zxw_rules.jl")
include("to_eincode.jl")
include("utils.jl")


export ZXWDiagram, CalcRule
end # module ZXW

using .ZXW:
ZXWDiagram,
ZXWSpiderType,
Parameter,
CalcRule,
PiUnit,
Factor,
Input,
Output,
W,
H,
D,
Z,
X,
rewrite!
export ZXWSpiderType,
ZXWDiagram, Parameter, PiUnit, Factor, Input, Output, W, H, D, Z, X, CalcRule
export substitute_variables!, expval_circ!, stack_zxwd!, concat!
using .ZXW: ZXWDiagram, CalcRule

export ZXWDiagram, CalcRule

include("parameter.jl")

include("planar_multigraph.jl")

module ZW
using Expronicon.ADT: @adt, @const_use
using MLStyle, Graphs
using ..ZXCalculus
using ..ZXCalculus.ZXW: _round_phase, Parameter
# these will be changed to using PlanarMultigraph: vertices after we split out package
using ..ZXCalculus:
vertices,
nv,
has_vertex,
ne,
neighbors,
rem_edge!,
add_edge!,
degree,
next,
split_vertex!,
split_edge!,
face,
trace_face,
make_hole!,
add_vertex_and_facet_to_boarder!,
split_facet!,
twin,
prev,
add_multiedge!,
join_facet!,
trace_vertex,
join_vertex!




# these remains
using ..ZXCalculus: add_phase!
import ..ZXCalculus: add_power!, add_global_phase!, scalar, spiders, rem_spider!
import Graphs.rem_edge!


include("zw_adt.jl")
include("zw_diagram.jl")
include("zw_utils.jl")
end # module ZW

end # module
2 changes: 2 additions & 0 deletions src/parameter.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using .ZXW: Parameter, PiUnit, Factor

"""
Parameter
Constructors for `Parameter` type.
Expand Down
Loading
Loading