You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -10,33 +10,33 @@ This example can be found in the appendix of [Clifford simplification](https://a
10
10
using ZXCalculus
11
11
12
12
functiongenerate_example_1()
13
-
zxd=ZXDiagram(4)
14
-
push_gate!(zxd, Val(:Z), 1, 3//2)
15
-
push_gate!(zxd, Val(:H), 1)
16
-
push_gate!(zxd, Val(:Z), 1, 1//2)
17
-
push_gate!(zxd, Val(:H), 4)
18
-
push_gate!(zxd, Val(:CZ), 4, 1)
19
-
push_gate!(zxd, Val(:CNOT), 1, 4)
20
-
push_gate!(zxd, Val(:H), 1)
21
-
push_gate!(zxd, Val(:H), 4)
22
-
push_gate!(zxd, Val(:Z), 1, 1//4)
23
-
push_gate!(zxd, Val(:Z), 4, 3//2)
24
-
push_gate!(zxd, Val(:X), 4, 1//1)
25
-
push_gate!(zxd, Val(:H), 1)
26
-
push_gate!(zxd, Val(:Z), 4, 1//2)
27
-
push_gate!(zxd, Val(:X), 4, 1//1)
28
-
push_gate!(zxd, Val(:Z), 2, 1//2)
29
-
push_gate!(zxd, Val(:CNOT), 3, 2)
30
-
push_gate!(zxd, Val(:H), 2)
31
-
push_gate!(zxd, Val(:CNOT), 3, 2)
32
-
push_gate!(zxd, Val(:Z), 2, 1//4)
33
-
push_gate!(zxd, Val(:Z), 3, 1//2)
34
-
push_gate!(zxd, Val(:H), 2)
35
-
push_gate!(zxd, Val(:H), 3)
36
-
push_gate!(zxd, Val(:Z), 3, 1//2)
37
-
push_gate!(zxd, Val(:CNOT), 3, 2)
38
-
39
-
returnzxd
13
+
zxc=ZXCircuit(4)
14
+
push_gate!(zxc, Val(:Z), 1, 3//2)
15
+
push_gate!(zxc, Val(:H), 1)
16
+
push_gate!(zxc, Val(:Z), 1, 1//2)
17
+
push_gate!(zxc, Val(:H), 4)
18
+
push_gate!(zxc, Val(:CZ), 4, 1)
19
+
push_gate!(zxc, Val(:CNOT), 1, 4)
20
+
push_gate!(zxc, Val(:H), 1)
21
+
push_gate!(zxc, Val(:H), 4)
22
+
push_gate!(zxc, Val(:Z), 1, 1//4)
23
+
push_gate!(zxc, Val(:Z), 4, 3//2)
24
+
push_gate!(zxc, Val(:X), 4, 1//1)
25
+
push_gate!(zxc, Val(:H), 1)
26
+
push_gate!(zxc, Val(:Z), 4, 1//2)
27
+
push_gate!(zxc, Val(:X), 4, 1//1)
28
+
push_gate!(zxc, Val(:Z), 2, 1//2)
29
+
push_gate!(zxc, Val(:CNOT), 3, 2)
30
+
push_gate!(zxc, Val(:H), 2)
31
+
push_gate!(zxc, Val(:CNOT), 3, 2)
32
+
push_gate!(zxc, Val(:Z), 2, 1//4)
33
+
push_gate!(zxc, Val(:Z), 3, 1//2)
34
+
push_gate!(zxc, Val(:H), 2)
35
+
push_gate!(zxc, Val(:H), 3)
36
+
push_gate!(zxc, Val(:Z), 3, 1//2)
37
+
push_gate!(zxc, Val(:CNOT), 3, 2)
38
+
39
+
returnzxc
40
40
end
41
41
ex1 =generate_example_1()
42
42
```
@@ -46,17 +46,16 @@ using YaoPlots
46
46
plot(ex1)
47
47
```
48
48

49
-
To simplify `zxd`, one can simply use
49
+
To simplify `ex1`, one can simply use
50
50
```julia
51
51
simplified_ex1 =clifford_simplification(ex1)
52
52
```
53
-
or explicitly use
53
+
or explicitly apply the simplification rules:
54
54
```julia
55
-
zxg =ZXCircuit(ex1)
56
-
simplify!(LocalCompRule(), zxg)
57
-
simplify!(Pivot1Rule(), zxg)
58
-
replace!(PivotBoundaryRule(), zxg)
59
-
simplified_ex1 =circuit_extraction(zxg)
55
+
simplify!(LocalCompRule(), ex1)
56
+
simplify!(Pivot1Rule(), ex1)
57
+
replace!(PivotBoundaryRule(), ex1)
58
+
simplified_ex1 =circuit_extraction(ex1)
60
59
```
61
60
And we draw the simplified circuit.
62
61
```julia
@@ -72,77 +71,77 @@ We first build up the circuit.
72
71
```julia
73
72
using ZXCalculus, YaoPlots
74
73
functiongenerate_example2()
75
-
cir=ZXDiagram(5)
76
-
push_gate!(cir, Val(:X), 5, 1//1)
77
-
push_gate!(cir, Val(:H), 5)
78
-
push_gate!(cir, Val(:Z), 5)
79
-
push_gate!(cir, Val(:CNOT), 5, 4)
80
-
push_gate!(cir, Val(:Z), 5, 7//4)
81
-
push_gate!(cir, Val(:CNOT), 5, 1)
82
-
push_gate!(cir, Val(:Z), 5, 1//4)
83
-
push_gate!(cir, Val(:CNOT), 5, 4)
84
-
push_gate!(cir, Val(:Z), 4, 1//4)
85
-
push_gate!(cir, Val(:Z), 5, 7//4)
86
-
push_gate!(cir, Val(:CNOT), 5, 1)
87
-
push_gate!(cir, Val(:CNOT), 4, 1)
88
-
push_gate!(cir, Val(:Z), 5, 1//4)
89
-
push_gate!(cir, Val(:Z), 1, 1//4)
90
-
push_gate!(cir, Val(:Z), 4, 7//4)
91
-
push_gate!(cir, Val(:CNOT), 4, 1)
92
-
push_gate!(cir, Val(:CNOT), 5, 4)
93
-
push_gate!(cir, Val(:Z), 5, 7//4)
94
-
push_gate!(cir, Val(:CNOT), 5, 3)
95
-
push_gate!(cir, Val(:Z), 5, 1//4)
96
-
push_gate!(cir, Val(:CNOT), 5, 4)
97
-
push_gate!(cir, Val(:Z), 4, 1//4)
98
-
push_gate!(cir, Val(:Z), 5, 7//4)
99
-
push_gate!(cir, Val(:CNOT), 5, 3)
100
-
push_gate!(cir, Val(:CNOT), 4, 3)
101
-
push_gate!(cir, Val(:Z), 5, 1//4)
102
-
push_gate!(cir, Val(:Z), 3, 1//4)
103
-
push_gate!(cir, Val(:Z), 4, 7//4)
104
-
push_gate!(cir, Val(:H), 5)
105
-
push_gate!(cir, Val(:Z), 5)
106
-
push_gate!(cir, Val(:CNOT), 4, 3)
107
-
push_gate!(cir, Val(:CNOT), 5, 4)
108
-
push_gate!(cir, Val(:H), 5)
109
-
push_gate!(cir, Val(:Z), 5)
110
-
push_gate!(cir, Val(:CNOT), 5, 3)
111
-
push_gate!(cir, Val(:Z), 5, 7//4)
112
-
push_gate!(cir, Val(:CNOT), 5, 2)
113
-
push_gate!(cir, Val(:Z), 5, 1//4)
114
-
push_gate!(cir, Val(:CNOT), 5, 3)
115
-
push_gate!(cir, Val(:Z), 3, 1//4)
116
-
push_gate!(cir, Val(:Z), 5, 7//4)
117
-
push_gate!(cir, Val(:CNOT), 5, 2)
118
-
push_gate!(cir, Val(:CNOT), 3, 2)
119
-
push_gate!(cir, Val(:Z), 5, 1//4)
120
-
push_gate!(cir, Val(:H), 5)
121
-
push_gate!(cir, Val(:Z), 2, 1//4)
122
-
push_gate!(cir, Val(:Z), 3, 7//4)
123
-
push_gate!(cir, Val(:Z), 5)
124
-
push_gate!(cir, Val(:CNOT), 3, 2)
125
-
push_gate!(cir, Val(:CNOT), 5, 3)
126
-
push_gate!(cir, Val(:H), 5)
127
-
push_gate!(cir, Val(:Z), 5)
128
-
push_gate!(cir, Val(:CNOT), 5, 2)
129
-
push_gate!(cir, Val(:Z), 5, 7//4)
130
-
push_gate!(cir, Val(:CNOT), 5, 1)
131
-
push_gate!(cir, Val(:Z), 5, 1//4)
132
-
push_gate!(cir, Val(:CNOT), 5, 2)
133
-
push_gate!(cir, Val(:Z), 2, 1//4)
134
-
push_gate!(cir, Val(:Z), 5, 7//4)
135
-
push_gate!(cir, Val(:CNOT), 5, 1)
136
-
push_gate!(cir, Val(:CNOT), 2, 1)
137
-
push_gate!(cir, Val(:Z), 5, 1//4)
138
-
push_gate!(cir, Val(:Z), 1, 1//4)
139
-
push_gate!(cir, Val(:Z), 2, 7//4)
140
-
push_gate!(cir, Val(:H), 5)
141
-
push_gate!(cir, Val(:Z), 5)
142
-
push_gate!(cir, Val(:CNOT), 2, 1)
143
-
push_gate!(cir, Val(:CNOT), 5, 2)
144
-
push_gate!(cir, Val(:CNOT), 5, 1)
145
-
returncir
74
+
zxc=ZXCircuit(5)
75
+
push_gate!(zxc, Val(:X), 5, 1//1)
76
+
push_gate!(zxc, Val(:H), 5)
77
+
push_gate!(zxc, Val(:Z), 5)
78
+
push_gate!(zxc, Val(:CNOT), 5, 4)
79
+
push_gate!(zxc, Val(:Z), 5, 7//4)
80
+
push_gate!(zxc, Val(:CNOT), 5, 1)
81
+
push_gate!(zxc, Val(:Z), 5, 1//4)
82
+
push_gate!(zxc, Val(:CNOT), 5, 4)
83
+
push_gate!(zxc, Val(:Z), 4, 1//4)
84
+
push_gate!(zxc, Val(:Z), 5, 7//4)
85
+
push_gate!(zxc, Val(:CNOT), 5, 1)
86
+
push_gate!(zxc, Val(:CNOT), 4, 1)
87
+
push_gate!(zxc, Val(:Z), 5, 1//4)
88
+
push_gate!(zxc, Val(:Z), 1, 1//4)
89
+
push_gate!(zxc, Val(:Z), 4, 7//4)
90
+
push_gate!(zxc, Val(:CNOT), 4, 1)
91
+
push_gate!(zxc, Val(:CNOT), 5, 4)
92
+
push_gate!(zxc, Val(:Z), 5, 7//4)
93
+
push_gate!(zxc, Val(:CNOT), 5, 3)
94
+
push_gate!(zxc, Val(:Z), 5, 1//4)
95
+
push_gate!(zxc, Val(:CNOT), 5, 4)
96
+
push_gate!(zxc, Val(:Z), 4, 1//4)
97
+
push_gate!(zxc, Val(:Z), 5, 7//4)
98
+
push_gate!(zxc, Val(:CNOT), 5, 3)
99
+
push_gate!(zxc, Val(:CNOT), 4, 3)
100
+
push_gate!(zxc, Val(:Z), 5, 1//4)
101
+
push_gate!(zxc, Val(:Z), 3, 1//4)
102
+
push_gate!(zxc, Val(:Z), 4, 7//4)
103
+
push_gate!(zxc, Val(:H), 5)
104
+
push_gate!(zxc, Val(:Z), 5)
105
+
push_gate!(zxc, Val(:CNOT), 4, 3)
106
+
push_gate!(zxc, Val(:CNOT), 5, 4)
107
+
push_gate!(zxc, Val(:H), 5)
108
+
push_gate!(zxc, Val(:Z), 5)
109
+
push_gate!(zxc, Val(:CNOT), 5, 3)
110
+
push_gate!(zxc, Val(:Z), 5, 7//4)
111
+
push_gate!(zxc, Val(:CNOT), 5, 2)
112
+
push_gate!(zxc, Val(:Z), 5, 1//4)
113
+
push_gate!(zxc, Val(:CNOT), 5, 3)
114
+
push_gate!(zxc, Val(:Z), 3, 1//4)
115
+
push_gate!(zxc, Val(:Z), 5, 7//4)
116
+
push_gate!(zxc, Val(:CNOT), 5, 2)
117
+
push_gate!(zxc, Val(:CNOT), 3, 2)
118
+
push_gate!(zxc, Val(:Z), 5, 1//4)
119
+
push_gate!(zxc, Val(:H), 5)
120
+
push_gate!(zxc, Val(:Z), 2, 1//4)
121
+
push_gate!(zxc, Val(:Z), 3, 7//4)
122
+
push_gate!(zxc, Val(:Z), 5)
123
+
push_gate!(zxc, Val(:CNOT), 3, 2)
124
+
push_gate!(zxc, Val(:CNOT), 5, 3)
125
+
push_gate!(zxc, Val(:H), 5)
126
+
push_gate!(zxc, Val(:Z), 5)
127
+
push_gate!(zxc, Val(:CNOT), 5, 2)
128
+
push_gate!(zxc, Val(:Z), 5, 7//4)
129
+
push_gate!(zxc, Val(:CNOT), 5, 1)
130
+
push_gate!(zxc, Val(:Z), 5, 1//4)
131
+
push_gate!(zxc, Val(:CNOT), 5, 2)
132
+
push_gate!(zxc, Val(:Z), 2, 1//4)
133
+
push_gate!(zxc, Val(:Z), 5, 7//4)
134
+
push_gate!(zxc, Val(:CNOT), 5, 1)
135
+
push_gate!(zxc, Val(:CNOT), 2, 1)
136
+
push_gate!(zxc, Val(:Z), 5, 1//4)
137
+
push_gate!(zxc, Val(:Z), 1, 1//4)
138
+
push_gate!(zxc, Val(:Z), 2, 7//4)
139
+
push_gate!(zxc, Val(:H), 5)
140
+
push_gate!(zxc, Val(:Z), 5)
141
+
push_gate!(zxc, Val(:CNOT), 2, 1)
142
+
push_gate!(zxc, Val(:CNOT), 5, 2)
143
+
push_gate!(zxc, Val(:CNOT), 5, 1)
144
+
returnzxc
146
145
end
147
146
ex2 =generate_example2()
148
147
plot(ex2)
@@ -166,25 +165,30 @@ we can see that the number of T gates has decreased from 28 to 8.
166
165
167
166
## Other usages
168
167
169
-
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.
168
+
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.
169
+
170
+
### Working with ZXGraph directly
171
+
172
+
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.
170
173
171
-
One can create a `ZXDiagram` by building up its `Multigraph` and other information. For example,
# Access the underlying ZXGraph if needed for low-level operations
183
+
zxg = zxc.zxd # The internal ZXGraph
184
+
185
+
# Apply graph-based rules
186
+
simplify!(LocalCompRule(), zxc)
183
187
```
184
-
Because the information of vertices locations of a general ZX-diagram is not provided, its plot will have a random layout.
185
188
186
-
We can manipulate `zxd` by using ZX-calculus [`Rule`](@ref)s.
189
+
### Deprecated: ZXDiagram
190
+
191
+
**Note:**`ZXDiagram` is deprecated. For circuit-based operations, use `ZXCircuit` instead. If you have existing code using `ZXDiagram`, you can convert it:
187
192
```julia
188
-
matches =match(PiRule(), zxd)
189
-
rewrite!(PiRule(), zxd, matches)
193
+
zxc =ZXCircuit(old_zxd) # Convert deprecated ZXDiagram to ZXCircuit
0 commit comments