Skip to content

Commit 8b1eb13

Browse files
committed
finish all porting
1 parent abe31b4 commit 8b1eb13

8 files changed

+96
-112
lines changed

src/ZXCalculus.jl

+60-71
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
module ZXCalculus
22

3-
# import Graphs: has_vertex
4-
5-
# using Graphs:
6-
# nv,
7-
# ne,
8-
# outneighbors,
9-
# inneighbors,
10-
# neighbors,
11-
# rem_edge!,
12-
# add_edge!,
13-
# has_edge,
14-
# degree,
15-
# indegree,
16-
# outdegree
17-
183
module Utils
194

205
using Expronicon.ADT: @const_use, @adt
@@ -33,8 +18,8 @@ using YaoHIR.IntrinsicOperation
3318
using YaoHIR: Chain
3419
using YaoLocations: plain
3520
using MLStyle
21+
using ..Utils: Scalar, Phase, add_phase!
3622

37-
using ZXCalculus.Utils: Scalar, Phase, add_phase!
3823
import ..Utils: add_power!
3924

4025
export spiders,
@@ -63,21 +48,18 @@ include("circuit_extraction.jl")
6348
include("phase_teleportation.jl")
6449

6550
include("ir.jl")
66-
6751
end
6852

69-
7053
module ZXW
54+
7155
using Expronicon.ADT: @const_use, @adt
7256
using MLStyle, Multigraphs, Graphs
7357
using ..Utils: Scalar, Phase, Parameter, PiUnit, Factor, add_phase!
7458
using ..ZX: safe_convert, AbstractRule, Rule, Match
59+
7560
import ..Utils: add_power!
7661
import ..ZX:
7762
rewrite!, simplify!, push_gate!, pushfirst_gate!, spiders, rem_spider!, rem_spiders!
78-
# import Multigraphs: has_vertex
79-
# import ..rewrite!, ..add_power!, ..add_edge!, ..vertices, ..nv, ..round_phases!
80-
8163

8264
export ZXWDiagram, substitute_variables!
8365

@@ -88,58 +70,65 @@ include("utils.jl")
8870

8971
end # module ZXW
9072

91-
# using .ZXW: ZXWDiagram, CalcRule
92-
93-
# export ZXWDiagram, CalcRule
94-
95-
96-
# include("planar_multigraph.jl")
97-
98-
# module ZW
99-
# using Expronicon.ADT: @adt, @const_use
100-
# using MLStyle, Graphs
101-
# using ..ZXCalculus
102-
# using ..ZXCalculus.ZXW: _round_phase, Parameter
103-
# # these will be changed to using PlanarMultigraph: vertices after we split out package
104-
# using ..ZXCalculus:
105-
# vertices,
106-
# nv,
107-
# has_vertex,
108-
# ne,
109-
# neighbors,
110-
# rem_edge!,
111-
# add_edge!,
112-
# degree,
113-
# next,
114-
# split_vertex!,
115-
# split_edge!,
116-
# face,
117-
# trace_face,
118-
# make_hole!,
119-
# add_vertex_and_facet_to_boarder!,
120-
# split_facet!,
121-
# twin,
122-
# prev,
123-
# add_multiedge!,
124-
# join_facet!,
125-
# trace_vertex,
126-
# join_vertex!
127-
128-
129-
130-
131-
# # these remains
132-
# using ..ZXCalculus: add_phase!
133-
# import ..ZXCalculus: add_power!, add_global_phase!, scalar, spiders, rem_spider!
134-
# import Graphs.rem_edge!
135-
136-
137-
# include("zw_adt.jl")
138-
# include("zw_diagram.jl")
139-
# include("zw_utils.jl")
140-
# end # module ZW
73+
module PMG
74+
75+
using Graphs
76+
77+
import Graphs: AbstractEdge, src, dst, nv, ne, neighbors
78+
import Graphs.SimpleGraphs: vertices
79+
80+
export HalfEdge, src, dst, new_edge, PlanarMultigraph
81+
82+
include("planar_multigraph.jl")
83+
84+
end # module PlanarMultigraph
85+
86+
module ZW
87+
using Expronicon.ADT: @adt, @const_use
88+
using MLStyle, Graphs
89+
using ..ZXW: _round_phase, Parameter
90+
91+
# these will be changed to using PlanarMultigraph: vertices after we split out package
92+
using ..PMG:
93+
vertices,
94+
nv,
95+
has_vertex,
96+
ne,
97+
neighbors,
98+
rem_edge!,
99+
add_edge!,
100+
degree,
101+
next,
102+
split_vertex!,
103+
split_edge!,
104+
face,
105+
trace_face,
106+
make_hole!,
107+
add_vertex_and_facet_to_boarder!,
108+
split_facet!,
109+
twin,
110+
prev,
111+
add_multiedge!,
112+
join_facet!,
113+
trace_vertex,
114+
join_vertex!
115+
116+
# these remains
117+
using ..Utils: add_phase!, Scalar, Phase, Parameter, PiUnit, Factor, add_power!
118+
using ..PMG: PlanarMultigraph, HalfEdge, new_edge, src, dst
119+
import ..Utils: add_power!
120+
import ..ZX: add_global_phase!, scalar, spiders, rem_spider!
121+
import Graphs.rem_edge!
122+
123+
export ZWDiagram
124+
125+
include("zw_adt.jl")
126+
include("zw_diagram.jl")
127+
include("zw_utils.jl")
128+
end # module ZW
141129

142130
module Application
131+
143132
using OMEinsum, MLStyle
144133
using ..ZXW: ZXWDiagram, Z, X, W, H, D, Input, Output
145134
using ..Utils: PiUnit, Factor, Parameter, unwrap_scalar

src/planar_multigraph.jl

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import Graphs: AbstractEdge, src, dst, nv, ne, neighbors
2-
import Graphs.SimpleGraphs: vertices
3-
export HalfEdge, src, dst, new_edge, PlanarMultigraph
4-
51
"""
62
HalfEdge{T<:Integer}(src ,dst)
73

src/zx_diagram.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ end
7070
Construct a ZXDiagram with all information.
7171
7272
```jldoctest
73-
julia> using Graphs, Multigraphs, ZXCalculus;
73+
julia> using Graphs, Multigraphs, ZXCalculus.ZX;
7474
75-
julia> using ZXCalculus.SpiderType: In, Out, H, Z, X;
75+
julia> using ZXCalculus.ZX.SpiderType: In, Out, H, Z, X;
7676
7777
julia> mg = Multigraph(5);
7878
@@ -101,7 +101,7 @@ ZXDiagram(mg::Multigraph{T}, st::Vector{SpiderType.SType}, ps::Vector{P},
101101
102102
Construct a ZXDiagram of a empty circuit with qubit number `nbit`
103103
104-
```jldoctest; setup = :(using ZXCalculus)
104+
```jldoctest; setup = :(using ZXCalculus.ZX)
105105
julia> zxd = ZXDiagram(3)
106106
ZX-diagram with 6 vertices and 3 multiple edges:
107107
(S_1{input} <-1-> S_2{output})

src/zx_graph.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535
Convert a ZX-diagram to graph-like ZX-diagram.
3636
3737
```jldoctest
38-
julia> using ZXCalculus
38+
julia> using ZXCalculus.ZX
3939
4040
julia> zxd = ZXDiagram(2); push_gate!(zxd, Val{:CNOT}(), 2, 1);
4141

test/planar_multigraph.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ZXCalculus:
1+
using ZXCalculus.PMG:
22
create_vertex!,
33
create_edge!,
44
split_vertex!,

test/runtests.jl

+18-14
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ using ZXCalculus,
55
ZXCalculus.Utils,
66
ZXCalculus.ZX,
77
ZXCalculus.ZXW,
8-
ZXCalculus.Application #, ZXCalculus.ZW
8+
ZXCalculus.PMG,
9+
ZXCalculus.Application,
10+
ZXCalculus.ZW
911

1012
import ZXCalculus.ZX as ZX
1113
import ZXCalculus.ZXW as ZXW
14+
import ZXCalculus.ZW as ZW
15+
1216
using YaoHIR: Chain
1317
using Documenter
1418
using Test
@@ -62,19 +66,6 @@ end
6266
include("challenge.jl")
6367
end
6468

65-
# @testset "ZW Diagram with Planar Multigraph" begin
66-
# include("zw_diagram.jl")
67-
# end
68-
69-
# @testset "ZW Diagram Utilities" begin
70-
# include("zw_utils.jl")
71-
# end
72-
73-
# @testset "planar multigraphs.jl" begin
74-
# include("planar_multigraph.jl")
75-
# end
76-
77-
7869
@testset "zxw_diagram.jl" begin
7970
include("zxw_diagram.jl")
8071
end
@@ -87,6 +78,19 @@ end
8778
include("zxw_rules.jl")
8879
end
8980

81+
@testset "planar multigraphs.jl" begin
82+
include("planar_multigraph.jl")
83+
end
84+
85+
@testset "ZW Diagram with Planar Multigraph" begin
86+
include("zw_diagram.jl")
87+
end
88+
89+
@testset "ZW Diagram Utilities" begin
90+
include("zw_utils.jl")
91+
end
92+
93+
9094
@testset "to_eincode.jl" begin
9195
include("to_eincode.jl")
9296
end

test/zw_diagram.jl

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ZXCalculus.ZW: ZWDiagram, Input, Output
21
@testset "ZWDiagrm Creation" begin
32
zx1 = ZWDiagram(1)
43
pmg1 = PlanarMultigraph(
@@ -15,7 +14,7 @@ using ZXCalculus.ZW: ZWDiagram, Input, Output
1514
)
1615

1716

18-
@test zx1.st == Dict([1 => Input(1), 2 => Output(1)])
17+
@test zx1.st == Dict([1 => ZW.Input(1), 2 => ZW.Output(1)])
1918
@test zx1.inputs == [1]
2019
@test zx1.outputs == [2]
2120
@test zx1.pmg == pmg1
@@ -44,7 +43,7 @@ using ZXCalculus.ZW: ZWDiagram, Input, Output
4443
[0],
4544
)
4645

47-
@test zx2.st == Dict([1 => Input(1), 2 => Output(1), 3 => Input(2), 4 => Output(2)])
46+
@test zx2.st == Dict([1 => ZW.Input(1), 2 => ZW.Output(1), 3 => ZW.Input(2), 4 => ZW.Output(2)])
4847
@test zx2.inputs == [1, 3]
4948
@test zx2.outputs == [2, 4]
5049
@test zx2.pmg == pmg2
@@ -127,12 +126,12 @@ using ZXCalculus.ZW: ZWDiagram, Input, Output
127126
)
128127

129128
@test zx3.st == Dict([
130-
1 => Input(1),
131-
2 => Output(1),
132-
3 => Input(2),
133-
4 => Output(2),
134-
5 => Input(3),
135-
6 => Output(3),
129+
1 => ZW.Input(1),
130+
2 => ZW.Output(1),
131+
3 => ZW.Input(2),
132+
4 => ZW.Output(2),
133+
5 => ZW.Input(3),
134+
6 => ZW.Output(3),
136135
])
137136
@test zx3.inputs == [1, 3, 5]
138137
@test zx3.outputs == [2, 4, 6]

test/zw_utils.jl

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using ZXCalculus.ZW:
2-
ZWDiagram,
32
ZWSpiderType,
4-
spider_type,
53
set_phase!,
64
parameter,
75
nin,
@@ -23,22 +21,20 @@ using ZXCalculus.ZW:
2321
get_output_idx,
2422
add_power!,
2523
add_global_phase!,
26-
insert_spider!,
2724
neighbors,
2825
join_spider!,
2926
add_edge!,
3027
add_spider!,
3128
rem_edge!,
3229
rem_spider!
3330

34-
35-
using ZXCalculus: trace_vertex
36-
using ZXCalculus.ZXW: Parameter
31+
using ZXCalculus.PMG: trace_vertex
32+
using ZXCalculus.Utils: Parameter
3733

3834
@testset "utils" begin
3935
zw = ZWDiagram(3)
4036

41-
@test spider_type(zw, 1) == ZW.Input(1)
37+
@test ZW.spider_type(zw, 1) == ZW.Input(1)
4238
@test parameter(zw, 2) == 1
4339
@test nqubits(zw) == 3
4440
@test nin(zw) == 3
@@ -155,7 +151,7 @@ end
155151
[0],
156152
)
157153

158-
insert_spider!(zw, 12, ZW.binZ(Parameter(Val(:Factor), 2.0)))
154+
ZW.insert_spider!(zw, 12, ZW.binZ(Parameter(Val(:Factor), 2.0)))
159155
@test zw.pmg == pmg2
160156

161157
set_phase!(zw, 7, Parameter(Val(:PiUnit), 1))
@@ -256,7 +252,7 @@ end
256252
@test pmg2 == zw.pmg
257253

258254
zw2 = ZWDiagram(3)
259-
insert_spider!(zw2, 12, ZW.binZ(Parameter(Val(:Factor), 2.0)))
255+
ZW.insert_spider!(zw2, 12, ZW.binZ(Parameter(Val(:Factor), 2.0)))
260256

261257
add_spider!(zw2, ZW.fSWAP, [1, 7, 4])
262258
st2 = Dict(

0 commit comments

Comments
 (0)