@@ -2,48 +2,13 @@ YaoHIR.Chain(zxd::AbstractZXCircuit) = convert_to_chain(zxd)
22
33# Main implementation on ZXCircuit
44function convert_to_chain (circ:: ZXCircuit{TT, P} ) where {TT, P}
5- spider_seq = spider_sequence (circ)
6- gates = []
7- for vs in spider_seq
8- if length (vs) == 1
9- v = vs
10- q = Int (qubit_loc (circ, v))
11- push_spider_to_chain! (gates, q, phase (circ, v), spider_type (circ, v))
12- elseif length (vs) == 2
13- v1, v2 = vs
14- q1 = Int (qubit_loc (circ, v1))
15- q2 = Int (qubit_loc (circ, v2))
16- push_spider_to_chain! (gates, q1, phase (circ, v1), spider_type (circ, v1))
17- push_spider_to_chain! (gates, q2, phase (circ, v2), spider_type (circ, v2))
18- if spider_type (circ, v1) == SpiderType. Z && spider_type (circ, v2) == SpiderType. X
19- push! (gates, Ctrl (Gate (X, Locations (q2)), CtrlLocations (q1)))
20- elseif spider_type (circ, v1) == SpiderType. X && spider_type (circ, v2) == SpiderType. Z
21- push! (gates, Ctrl (Gate (X, Locations (q1)), CtrlLocations (q2)))
22- else
23- error (" Spiders ($v1 , $v2 ) should represent a CNOT" )
24- end
25- elseif length (vs) == 3
26- v1, h, v2 = vs
27- spider_type (circ, h) == SpiderType. H || error (" The spider $h should be a H-box" )
28- q1 = Int (qubit_loc (circ, v1))
29- q2 = Int (qubit_loc (circ, v2))
30- push_spider_to_chain! (gates, q1, phase (circ, v1), spider_type (circ, v1))
31- push_spider_to_chain! (gates, q2, phase (circ, v2), spider_type (circ, v2))
32- if spider_type (circ, v1) == SpiderType. Z && spider_type (circ, v2) == SpiderType. Z
33- push! (gates, Ctrl (Gate (Z, Locations (q2)), CtrlLocations (q1)))
34- else
35- error (" Spiders ($v1 , $h , $v2 ) should represent a CZ" )
36- end
37- else
38- error (" ZXCircuit without proper circuit structure is not supported" )
39- end
40- end
41- return Chain (gates... )
5+ zxd = ZXDiagram (circ)
6+ return convert_to_chain (zxd)
427end
438
449# Implementation for deprecated ZXDiagram (avoid conversion to preserve structure)
4510function convert_to_chain (circ:: ZXDiagram{TT, P} ) where {TT, P}
46- Base. depwarn (" ZXDiagram is deprecated for circuit operations. Use ZXCircuit instead." , :convert_to_chain )
11+ # Base.depwarn("ZXDiagram is deprecated for circuit operations. Use ZXCircuit instead.", :convert_to_chain)
4712 spider_seq = spider_sequence (circ)
4813 gates = []
4914 for vs in spider_seq
0 commit comments