Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
f8ad27d
comments for refactoring
ChenZhao44 Oct 23, 2025
a6b9387
group tests
ChenZhao44 Oct 23, 2025
6e27dbd
phase interface
ChenZhao44 Oct 23, 2025
1579ad7
restrict phase type
ChenZhao44 Oct 23, 2025
7248c54
fix test for restricted phase type
ChenZhao44 Oct 23, 2025
4429506
update phase interface
ChenZhao44 Oct 23, 2025
f286d93
restrict abstract type
ChenZhao44 Oct 23, 2025
079e409
fix test
ChenZhao44 Oct 23, 2025
4f7a216
clifford check
ChenZhao44 Oct 23, 2025
58a10d1
phase interface
ChenZhao44 Oct 23, 2025
c947362
complete test
ChenZhao44 Oct 23, 2025
ff46d4b
reorganize rules
ChenZhao44 Oct 23, 2025
52d9b17
rename fusion
ChenZhao44 Oct 23, 2025
1b2c1f4
rename rules
ChenZhao44 Oct 23, 2025
61fddf1
decouple layout for ZXGraph
ChenZhao44 Oct 23, 2025
399bd75
rename rule
ChenZhao44 Oct 23, 2025
ad1bc27
decouple inputs and outputs
ChenZhao44 Oct 23, 2025
8258e2f
move inputs outputs
ChenZhao44 Oct 23, 2025
787bafa
rm layouts from ZXGraph
ChenZhao44 Oct 23, 2025
85cffe0
fix add edge
ChenZhao44 Oct 23, 2025
714a35f
fusion rule for ZXGraph
ChenZhao44 Oct 24, 2025
e2a3ae5
polish test
ChenZhao44 Oct 24, 2025
cb3b033
fix test
ChenZhao44 Oct 24, 2025
5fed218
H-box to edge
ChenZhao44 Oct 24, 2025
11abcaa
rename
ChenZhao44 Oct 24, 2025
3b5862d
test HBoxRule
ChenZhao44 Oct 24, 2025
31c187c
fix upto rules.jl
ChenZhao44 Oct 24, 2025
f089e45
fix upto zx_graph
ChenZhao44 Oct 24, 2025
ccc7906
import Chain
ChenZhao44 Oct 24, 2025
30d1c67
fix circuit simplification
ChenZhao44 Oct 24, 2025
6ae8f7d
fix circuit extraction
ChenZhao44 Oct 24, 2025
6d51900
move some interface to ZXCircuit
ChenZhao44 Oct 24, 2025
97bd534
identity removal for ZXCircuit
ChenZhao44 Oct 24, 2025
4f9ba46
fix equality test
ChenZhao44 Oct 24, 2025
a96c5b3
polish rule id rm
ChenZhao44 Oct 24, 2025
d904bb7
fix p3 rule
ChenZhao44 Oct 24, 2025
082bd91
pivot 2 for ZXCircuit
ChenZhao44 Oct 24, 2025
c5fd1ea
ZXCircuit for pivot gadget
ChenZhao44 Oct 24, 2025
6cc6816
fix pivot on the boundary
ChenZhao44 Oct 24, 2025
699b289
rename vars
ChenZhao44 Oct 24, 2025
0cbe89e
fix pivot on the boundary
ChenZhao44 Oct 24, 2025
46b2c05
fix tests
ChenZhao44 Oct 24, 2025
4f8c2e1
rm printing
ChenZhao44 Oct 24, 2025
c6c972e
fix pivot 2 phase id check
ChenZhao44 Oct 24, 2025
952bb5e
zxgraph test
ChenZhao44 Oct 24, 2025
4a87549
rm comments
ChenZhao44 Oct 24, 2025
97197d6
two-level abstract type
ChenZhao44 Oct 25, 2025
1ed050a
ZXCircuit <-> ZXDiagram
ChenZhao44 Oct 26, 2025
4d0bdc6
fix test
ChenZhao44 Oct 26, 2025
0897043
deprecating ZXDiagram
ChenZhao44 Oct 26, 2025
c8e4a58
polish interface
ChenZhao44 Oct 26, 2025
17ddf51
fix ZW test
ChenZhao44 Oct 26, 2025
09964a7
reorganize ZX module
ChenZhao44 Oct 26, 2025
1850975
rm Interfaces
ChenZhao44 Oct 26, 2025
f22ba94
use conventional Julia interface
ChenZhao44 Oct 26, 2025
1ead3b8
interface docstrings
ChenZhao44 Oct 26, 2025
8a99695
polish docstrings
ChenZhao44 Oct 26, 2025
da99f02
migrate to ZXCircuit
ChenZhao44 Oct 27, 2025
182c8a7
composition for ZXCircuit
ChenZhao44 Oct 27, 2025
7c0b3fe
add DocStringExtensions
ChenZhao44 Oct 27, 2025
5b0d5fa
fix push gate
ChenZhao44 Oct 27, 2025
d476126
to html plot
ChenZhao44 Oct 27, 2025
ff773d8
fix circuit implementation
ChenZhao44 Oct 27, 2025
0c5e930
fix plot interface
ChenZhao44 Oct 27, 2025
eaf9fef
reorganize import
ChenZhao44 Oct 27, 2025
46bfd81
add todo
ChenZhao44 Oct 27, 2025
f7d6b23
add edge check
ChenZhao44 Oct 27, 2025
f2bd59a
add edge checks
ChenZhao44 Oct 27, 2025
d8044d3
edge check for :pab
ChenZhao44 Oct 27, 2025
13fd270
edge check for p2
ChenZhao44 Oct 27, 2025
5b0bf9c
edge check for p3
ChenZhao44 Oct 27, 2025
5de340c
edge check for id and pivot gadget
ChenZhao44 Oct 27, 2025
b4ec5e4
fix id
ChenZhao44 Oct 27, 2025
f7139cf
fix typing
ChenZhao44 Oct 27, 2025
1eddaa8
add todo
ChenZhao44 Oct 27, 2025
b33835f
rm comments
ChenZhao44 Oct 27, 2025
a6fb68f
tests for ir
ChenZhao44 Oct 27, 2025
fdc8c4e
rm proposal
ChenZhao44 Oct 27, 2025
1060d77
modularize tests
ChenZhao44 Oct 28, 2025
8cf3e2a
fix imports
ChenZhao44 Oct 28, 2025
89a67b2
fix test
ChenZhao44 Oct 29, 2025
4eb1ab8
test layout
ChenZhao44 Oct 29, 2025
1ab808e
refactor interface
ChenZhao44 Oct 29, 2025
07637a3
fix import
ChenZhao44 Oct 29, 2025
92b6de5
polish interface docstring
ChenZhao44 Oct 29, 2025
0824904
tests for abstract ZX circuit
ChenZhao44 Oct 29, 2025
6564b7a
move conversion
ChenZhao44 Oct 29, 2025
d2e673a
rename
ChenZhao44 Oct 29, 2025
756bfbf
rename files
ChenZhao44 Oct 29, 2025
5cfa8d0
move files
ChenZhao44 Oct 29, 2025
5c07740
move files
ChenZhao44 Oct 29, 2025
d44cfd0
ZXGraph tests
ChenZhao44 Oct 29, 2025
8a5f93e
add assertions
ChenZhao44 Oct 29, 2025
e0bb340
test parallel edge and self-loop handling
ChenZhao44 Oct 29, 2025
9b99d2b
add assertion
ChenZhao44 Oct 29, 2025
5742869
rename files
ChenZhao44 Oct 29, 2025
8e269dd
polish tests
ChenZhao44 Oct 29, 2025
3a60883
decompose rule tests
ChenZhao44 Oct 29, 2025
73112c0
decompose files
ChenZhao44 Oct 29, 2025
eceeb0d
add place holders
ChenZhao44 Oct 29, 2025
13dd333
eincode for ZX
ChenZhao44 Oct 29, 2025
1af381a
fix to_eincode
ChenZhao44 Oct 29, 2025
abfdae4
rm useless tests
ChenZhao44 Oct 29, 2025
ce433b1
add nin nout into interface
ChenZhao44 Oct 30, 2025
93bfb8e
add matrix check test
ChenZhao44 Oct 30, 2025
a6380e8
rename
ChenZhao44 Oct 30, 2025
0d78009
rename
ChenZhao44 Oct 30, 2025
95fdd14
fix tests
ChenZhao44 Oct 30, 2025
d344838
rm redundant tests
ChenZhao44 Oct 30, 2025
69c40d3
fix tests
ChenZhao44 Oct 30, 2025
46afd0e
test printing
ChenZhao44 Oct 30, 2025
219ce96
weak deps
ChenZhao44 Oct 30, 2025
8d23c9a
check if tracking phase
ChenZhao44 Oct 30, 2025
e539cee
add TODO
ChenZhao44 Oct 30, 2025
45f97b4
refactor simplification
ChenZhao44 Oct 30, 2025
47d4889
update docs
ChenZhao44 Oct 30, 2025
5943979
fix tests
ChenZhao44 Oct 30, 2025
0ddac76
fix IdentityRemoval
ChenZhao44 Oct 31, 2025
1c90337
update interface
ChenZhao44 Oct 31, 2025
096f064
export new interface
ChenZhao44 Oct 31, 2025
219dbbc
fix import warning
ChenZhao44 Oct 31, 2025
8c4df85
fix including ordering
ChenZhao44 Oct 31, 2025
1e64a3b
using base_zx_graph
ChenZhao44 Oct 31, 2025
3c67f62
update interfaces
ChenZhao44 Oct 31, 2025
ed728ce
delegate to underlying graph
ChenZhao44 Oct 31, 2025
20cf8bf
update add_edge!
ChenZhao44 Oct 31, 2025
e1d9beb
add_spider! with specified edge type connections
ChenZhao44 Oct 31, 2025
fd2026b
adapt new add_spider! interface
ChenZhao44 Oct 31, 2025
a1f66e0
ZToXRule
ChenZhao44 Nov 3, 2025
70fbc66
add layout kwargs
ChenZhao44 Nov 3, 2025
ccbb5c4
use API
ChenZhao44 Nov 3, 2025
dcc0ed2
fix scalar
ChenZhao44 Nov 5, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/docs/Manifest.toml
.vscode
.JuliaFormatter.toml
lcov.info
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name = "ZXCalculus"
uuid = "3525faa3-032d-4235-a8d4-8c2939a218dd"
authors = ["Chen Zhao and contributors"]
version = "0.7.1"
authors = ["Chen Zhao and contributors"]

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expronicon = "6b7a57c9-7cc1-4fdf-b7f5-e857abae3636"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
Multigraphs = "7ebac608-6c66-46e6-9856-b5f43e107bac"
Expand All @@ -23,8 +25,10 @@ ZXCalculusExt = ["Vega", "DataFrames"]

[compat]
DataFrames = "1"
DocStringExtensions = "0.9.5"
Expronicon = "0.10.3"
Graphs = "1"
JSON = "0.21.4"
MLStyle = "0.4"
Multigraphs = "0.3"
OMEinsum = "0.7, 0.8, 0.9"
Expand Down
Binary file removed Proposal.pdf
Binary file not shown.
244 changes: 124 additions & 120 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ This example can be found in the appendix of [Clifford simplification](https://a
using ZXCalculus

function generate_example_1()
zxd = ZXDiagram(4)
push_gate!(zxd, Val(:Z), 1, 3//2)
push_gate!(zxd, Val(:H), 1)
push_gate!(zxd, Val(:Z), 1, 1//2)
push_gate!(zxd, Val(:H), 4)
push_gate!(zxd, Val(:CZ), 4, 1)
push_gate!(zxd, Val(:CNOT), 1, 4)
push_gate!(zxd, Val(:H), 1)
push_gate!(zxd, Val(:H), 4)
push_gate!(zxd, Val(:Z), 1, 1//4)
push_gate!(zxd, Val(:Z), 4, 3//2)
push_gate!(zxd, Val(:X), 4, 1//1)
push_gate!(zxd, Val(:H), 1)
push_gate!(zxd, Val(:Z), 4, 1//2)
push_gate!(zxd, Val(:X), 4, 1//1)
push_gate!(zxd, Val(:Z), 2, 1//2)
push_gate!(zxd, Val(:CNOT), 3, 2)
push_gate!(zxd, Val(:H), 2)
push_gate!(zxd, Val(:CNOT), 3, 2)
push_gate!(zxd, Val(:Z), 2, 1//4)
push_gate!(zxd, Val(:Z), 3, 1//2)
push_gate!(zxd, Val(:H), 2)
push_gate!(zxd, Val(:H), 3)
push_gate!(zxd, Val(:Z), 3, 1//2)
push_gate!(zxd, Val(:CNOT), 3, 2)

return zxd
zxc = ZXCircuit(4)
push_gate!(zxc, Val(:Z), 1, 3//2)
push_gate!(zxc, Val(:H), 1)
push_gate!(zxc, Val(:Z), 1, 1//2)
push_gate!(zxc, Val(:H), 4)
push_gate!(zxc, Val(:CZ), 4, 1)
push_gate!(zxc, Val(:CNOT), 1, 4)
push_gate!(zxc, Val(:H), 1)
push_gate!(zxc, Val(:H), 4)
push_gate!(zxc, Val(:Z), 1, 1//4)
push_gate!(zxc, Val(:Z), 4, 3//2)
push_gate!(zxc, Val(:X), 4, 1//1)
push_gate!(zxc, Val(:H), 1)
push_gate!(zxc, Val(:Z), 4, 1//2)
push_gate!(zxc, Val(:X), 4, 1//1)
push_gate!(zxc, Val(:Z), 2, 1//2)
push_gate!(zxc, Val(:CNOT), 3, 2)
push_gate!(zxc, Val(:H), 2)
push_gate!(zxc, Val(:CNOT), 3, 2)
push_gate!(zxc, Val(:Z), 2, 1//4)
push_gate!(zxc, Val(:Z), 3, 1//2)
push_gate!(zxc, Val(:H), 2)
push_gate!(zxc, Val(:H), 3)
push_gate!(zxc, Val(:Z), 3, 1//2)
push_gate!(zxc, Val(:CNOT), 3, 2)

return zxc
end
ex1 = generate_example_1()
```
Expand All @@ -46,17 +46,16 @@ using YaoPlots
plot(ex1)
```
![the circuit of example 1](imgs/ex1.svg)
To simplify `zxd`, one can simply use
To simplify `ex1`, one can simply use
```julia
simplified_ex1 = clifford_simplification(ex1)
```
or explicitly use
or explicitly apply the simplification rules:
```julia
zxg = ZXGraph(ex1)
simplify!(Rule{:lc}(), zxg)
simplify!(Rule{:p1}(), zxg)
replace!(Rule{:pab}(), zxg)
simplified_ex1 = circuit_extraction(zxg)
simplify!(LocalCompRule(), ex1)
simplify!(Pivot1Rule(), ex1)
replace!(PivotBoundaryRule(), ex1)
simplified_ex1 = circuit_extraction(ex1)
```
And we draw the simplified circuit.
```julia
Expand All @@ -72,77 +71,77 @@ We first build up the circuit.
```julia
using ZXCalculus, YaoPlots
function generate_example2()
cir = ZXDiagram(5)
push_gate!(cir, Val(:X), 5, 1//1)
push_gate!(cir, Val(:H), 5)
push_gate!(cir, Val(:Z), 5)
push_gate!(cir, Val(:CNOT), 5, 4)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 1)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:CNOT), 5, 4)
push_gate!(cir, Val(:Z), 4, 1//4)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 1)
push_gate!(cir, Val(:CNOT), 4, 1)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:Z), 1, 1//4)
push_gate!(cir, Val(:Z), 4, 7//4)
push_gate!(cir, Val(:CNOT), 4, 1)
push_gate!(cir, Val(:CNOT), 5, 4)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 3)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:CNOT), 5, 4)
push_gate!(cir, Val(:Z), 4, 1//4)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 3)
push_gate!(cir, Val(:CNOT), 4, 3)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:Z), 3, 1//4)
push_gate!(cir, Val(:Z), 4, 7//4)
push_gate!(cir, Val(:H), 5)
push_gate!(cir, Val(:Z), 5)
push_gate!(cir, Val(:CNOT), 4, 3)
push_gate!(cir, Val(:CNOT), 5, 4)
push_gate!(cir, Val(:H), 5)
push_gate!(cir, Val(:Z), 5)
push_gate!(cir, Val(:CNOT), 5, 3)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 2)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:CNOT), 5, 3)
push_gate!(cir, Val(:Z), 3, 1//4)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 2)
push_gate!(cir, Val(:CNOT), 3, 2)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:H), 5)
push_gate!(cir, Val(:Z), 2, 1//4)
push_gate!(cir, Val(:Z), 3, 7//4)
push_gate!(cir, Val(:Z), 5)
push_gate!(cir, Val(:CNOT), 3, 2)
push_gate!(cir, Val(:CNOT), 5, 3)
push_gate!(cir, Val(:H), 5)
push_gate!(cir, Val(:Z), 5)
push_gate!(cir, Val(:CNOT), 5, 2)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 1)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:CNOT), 5, 2)
push_gate!(cir, Val(:Z), 2, 1//4)
push_gate!(cir, Val(:Z), 5, 7//4)
push_gate!(cir, Val(:CNOT), 5, 1)
push_gate!(cir, Val(:CNOT), 2, 1)
push_gate!(cir, Val(:Z), 5, 1//4)
push_gate!(cir, Val(:Z), 1, 1//4)
push_gate!(cir, Val(:Z), 2, 7//4)
push_gate!(cir, Val(:H), 5)
push_gate!(cir, Val(:Z), 5)
push_gate!(cir, Val(:CNOT), 2, 1)
push_gate!(cir, Val(:CNOT), 5, 2)
push_gate!(cir, Val(:CNOT), 5, 1)
return cir
zxc = ZXCircuit(5)
push_gate!(zxc, Val(:X), 5, 1//1)
push_gate!(zxc, Val(:H), 5)
push_gate!(zxc, Val(:Z), 5)
push_gate!(zxc, Val(:CNOT), 5, 4)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 1)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:CNOT), 5, 4)
push_gate!(zxc, Val(:Z), 4, 1//4)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 1)
push_gate!(zxc, Val(:CNOT), 4, 1)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:Z), 1, 1//4)
push_gate!(zxc, Val(:Z), 4, 7//4)
push_gate!(zxc, Val(:CNOT), 4, 1)
push_gate!(zxc, Val(:CNOT), 5, 4)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 3)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:CNOT), 5, 4)
push_gate!(zxc, Val(:Z), 4, 1//4)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 3)
push_gate!(zxc, Val(:CNOT), 4, 3)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:Z), 3, 1//4)
push_gate!(zxc, Val(:Z), 4, 7//4)
push_gate!(zxc, Val(:H), 5)
push_gate!(zxc, Val(:Z), 5)
push_gate!(zxc, Val(:CNOT), 4, 3)
push_gate!(zxc, Val(:CNOT), 5, 4)
push_gate!(zxc, Val(:H), 5)
push_gate!(zxc, Val(:Z), 5)
push_gate!(zxc, Val(:CNOT), 5, 3)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 2)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:CNOT), 5, 3)
push_gate!(zxc, Val(:Z), 3, 1//4)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 2)
push_gate!(zxc, Val(:CNOT), 3, 2)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:H), 5)
push_gate!(zxc, Val(:Z), 2, 1//4)
push_gate!(zxc, Val(:Z), 3, 7//4)
push_gate!(zxc, Val(:Z), 5)
push_gate!(zxc, Val(:CNOT), 3, 2)
push_gate!(zxc, Val(:CNOT), 5, 3)
push_gate!(zxc, Val(:H), 5)
push_gate!(zxc, Val(:Z), 5)
push_gate!(zxc, Val(:CNOT), 5, 2)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 1)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:CNOT), 5, 2)
push_gate!(zxc, Val(:Z), 2, 1//4)
push_gate!(zxc, Val(:Z), 5, 7//4)
push_gate!(zxc, Val(:CNOT), 5, 1)
push_gate!(zxc, Val(:CNOT), 2, 1)
push_gate!(zxc, Val(:Z), 5, 1//4)
push_gate!(zxc, Val(:Z), 1, 1//4)
push_gate!(zxc, Val(:Z), 2, 7//4)
push_gate!(zxc, Val(:H), 5)
push_gate!(zxc, Val(:Z), 5)
push_gate!(zxc, Val(:CNOT), 2, 1)
push_gate!(zxc, Val(:CNOT), 5, 2)
push_gate!(zxc, Val(:CNOT), 5, 1)
return zxc
end
ex2 = generate_example2()
plot(ex2)
Expand All @@ -166,25 +165,30 @@ we can see that the number of T gates has decreased from 28 to 8.

## Other usages

In the previous sections, we introduced how to use `ZXCalculus.jl` for ZX-diagrams which represent quantum circuits. Sometimes, one may wish to use it for general ZX-diagrams. It is possible.
In the previous sections, we introduced how to use `ZXCalculus.jl` for quantum circuits using `ZXCircuit`. Sometimes, one may wish to work with the lower-level graph representation directly.

### Working with ZXGraph directly

For advanced users who need direct access to the graph structure, you can work with `ZXGraph`. However, for most use cases, `ZXCircuit` is the recommended interface.

One can create a `ZXDiagram` by building up its `Multigraph` and other information. For example,
```julia
using ZXCalculus, YaoPlots, Graphs
g = Multigraph(6)
add_edge!(g, 1, 2)
add_edge!(g, 2, 3)
add_edge!(g, 3, 4)
add_edge!(g, 3, 5)
add_edge!(g, 3, 6)
ps = [0, 1, 1//2, 0, 0, 0]
v_t = [SpiderType.In, SpiderType.X, SpiderType.Z, SpiderType.Out, SpiderType.Out, SpiderType.Out]
zxd = ZXDiagram(g, v_t, ps)

# Create a ZXCircuit first
zxc = ZXCircuit(3)
push_gate!(zxc, Val(:H), 1)
push_gate!(zxc, Val(:CNOT), 1, 2)

# Access the underlying ZXGraph if needed for low-level operations
zxg = zxc.zxd # The internal ZXGraph

# Apply graph-based rules
simplify!(LocalCompRule(), zxc)
```
Because the information of vertices locations of a general ZX-diagram is not provided, its plot will have a random layout.

We can manipulate `zxd` by using ZX-calculus [`Rule`](@ref)s.
### Deprecated: ZXDiagram

**Note:** `ZXDiagram` is deprecated. For circuit-based operations, use `ZXCircuit` instead. If you have existing code using `ZXDiagram`, you can convert it:
```julia
matches = match(Rule{:pi}(), zxd)
rewrite!(Rule{:pi}(), zxd, matches)
zxc = ZXCircuit(old_zxd) # Convert deprecated ZXDiagram to ZXCircuit
```
Loading
Loading