From 7262c4a3dec7e78e9878af22d198c8fa44fb88ae Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Sat, 30 Sep 2023 09:27:40 +0800 Subject: [PATCH 01/10] add placeholder for doc imporvement --- src/ZXCalculus.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ZXCalculus.jl b/src/ZXCalculus.jl index e616f51..9c2e70a 100644 --- a/src/ZXCalculus.jl +++ b/src/ZXCalculus.jl @@ -1,5 +1,6 @@ module ZXCalculus - +# TODO: add docs and improve package structure +## this is a place holder using OMEinsum using YaoHIR, YaoLocations using YaoHIR.IntrinsicOperation From 8781a62eed10fbd6b8563deaccdcd80436a39830 Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Mon, 9 Oct 2023 22:04:43 +0800 Subject: [PATCH 02/10] relocate utils and zx into own module --- src/ZXCalculus.jl | 212 +++++++++++++++++++----------------- src/abstract_zx_diagram.jl | 68 +++++++----- src/adts.jl | 20 ---- src/parameter.jl | 21 +++- src/scalar.jl | 2 + test/abstract_zx_diagram.jl | 39 ++++--- test/parameter.jl | 2 +- test/phase.jl | 11 +- test/phase_teleportation.jl | 1 - test/rules.jl | 4 +- test/runtests.jl | 73 +++++++------ test/scalar.jl | 4 +- test/zx_diagram.jl | 28 ++--- test/zx_graph.jl | 18 +-- 14 files changed, 265 insertions(+), 238 deletions(-) diff --git a/src/ZXCalculus.jl b/src/ZXCalculus.jl index 0c776e1..7691fb7 100644 --- a/src/ZXCalculus.jl +++ b/src/ZXCalculus.jl @@ -1,47 +1,59 @@ module ZXCalculus -# TODO: add docs and improve package structure -## this is a place holder -using OMEinsum -using YaoHIR, YaoLocations + +# using OMEinsum + +# import Graphs: has_vertex + + + +# using Graphs: +# nv, +# ne, +# outneighbors, +# inneighbors, +# neighbors, +# rem_edge!, +# add_edge!, +# has_edge, +# degree, +# indegree, +# outdegree + +module Utils + +using Expronicon.ADT: @const_use, @adt +using MLStyle + +include("scalar.jl") +include("phase.jl") +include("parameter.jl") + +end + +module ZX + +using Graphs, Multigraphs, YaoHIR, YaoLocations using YaoHIR.IntrinsicOperation using YaoHIR: Chain using YaoLocations: plain using MLStyle -using Graphs, Multigraphs - -using Graphs: - nv, - ne, - outneighbors, - inneighbors, - neighbors, - rem_edge!, - add_edge!, - has_edge, - degree, - indegree, - outdegree - -import Graphs: has_vertex + +using ZXCalculus.Utils: Scalar, Phase, add_phase! +import ..Utils: add_power! + +export spiders, + tcount, spider_type, phase, rem_spider!, rem_spiders!, pushfirst_gate!, push_gate! export SpiderType, EdgeType export AbstractZXDiagram, ZXDiagram, ZXGraph -export AbstractRule -export Rule, Match, Scalar -export push_gate!, pushfirst_gate!, tcount -export convert_to_chain, convert_to_zxd -export rewrite!, - simplify!, - clifford_simplification, - full_reduction, - circuit_extraction, - phase_teleportation -export phase, spiders, rem_spider! +export AbstractRule +export Rule, Match -include("scalar.jl") +export rewrite!, simplify! -include("phase.jl") +export convert_to_chain, convert_to_zxd +export clifford_simplification, full_reduction, circuit_extraction, phase_teleportation include("abstract_zx_diagram.jl") include("zx_layout.jl") @@ -50,82 +62,88 @@ include("zx_graph.jl") include("rules.jl") include("simplify.jl") + include("circuit_extraction.jl") include("phase_teleportation.jl") include("ir.jl") -include("deprecations.jl") +end -module ZXW -using Expronicon.ADT: @const_use, @adt -using MLStyle, Multigraphs, Graphs -using OMEinsum -import Multigraphs: has_vertex -using ..ZXCalculus -using ..ZXCalculus: safe_convert, add_phase! -import ..pushfirst_gate!, ..push_gate! -import ..rewrite!, ..add_power!, ..add_edge!, ..vertices, ..nv, ..round_phases! +# module ZXW +# using Expronicon.ADT: @const_use, @adt +# using MLStyle, Multigraphs, Graphs +# using OMEinsum +# import Multigraphs: has_vertex +# using ..ZXCalculus +# using ..ZXCalculus: safe_convert, add_phase! +# import ..pushfirst_gate!, ..push_gate! +# import ..rewrite!, ..add_power!, ..add_edge!, ..vertices, ..nv, ..round_phases! -include("adts.jl") -include("zxw_diagram.jl") -include("zxw_rules.jl") -include("to_eincode.jl") -include("utils.jl") -end # module ZXW +# include("adts.jl") +# include("zxw_diagram.jl") +# include("zxw_rules.jl") +# include("to_eincode.jl") +# include("utils.jl") -using .ZXW: ZXWDiagram, CalcRule +# end # module ZXW -export ZXWDiagram, CalcRule +# using .ZXW: ZXWDiagram, CalcRule -include("parameter.jl") +# export ZXWDiagram, CalcRule + + +# include("planar_multigraph.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 +# 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 + +# module Application + +# end # module APP + +include("deprecations.jl") end # module diff --git a/src/abstract_zx_diagram.jl b/src/abstract_zx_diagram.jl index 90fa516..17f58ce 100644 --- a/src/abstract_zx_diagram.jl +++ b/src/abstract_zx_diagram.jl @@ -1,4 +1,4 @@ -abstract type AbstractZXDiagram{T, P} end +abstract type AbstractZXDiagram{T,P} end Graphs.nv(zxd::AbstractZXDiagram) = throw(MethodError(Graphs.nv, zxd)) Graphs.ne(zxd::AbstractZXDiagram) = throw(MethodError(Graphs.ne, zxd)) @@ -6,36 +6,48 @@ Graphs.degree(zxd::AbstractZXDiagram, v) = throw(MethodError(Graphs.degree, (zxd Graphs.indegree(zxd::AbstractZXDiagram, v) = throw(MethodError(Graphs.indegree, (zxd, v))) Graphs.outdegree(zxd::AbstractZXDiagram, v) = throw(MethodError(Graphs.outdegree, (zxd, v))) Graphs.neighbors(zxd::AbstractZXDiagram, v) = throw(MethodError(Graphs.neighbors, (zxd, v))) -Graphs.outneighbors(zxd::AbstractZXDiagram, v) = throw(MethodError(Graphs.outneighbors, (zxd, v))) -Graphs.inneighbors(zxd::AbstractZXDiagram, v) = throw(MethodError(Graphs.inneighbors, (zxd, v))) -Graphs.rem_edge!(zxd::AbstractZXDiagram, args...) = throw(MethodError(Graphs.rem_edge!, (zxd, args...))) -Graphs.add_edge!(zxd::AbstractZXDiagram, args...) = throw(MethodError(Graphs.add_edge!, (zxd, args...))) -Graphs.has_edge(zxd::AbstractZXDiagram, args...) = throw(MethodError(Graphs.has_edge, (zxd, args...))) +Graphs.outneighbors(zxd::AbstractZXDiagram, v) = + throw(MethodError(Graphs.outneighbors, (zxd, v))) +Graphs.inneighbors(zxd::AbstractZXDiagram, v) = + throw(MethodError(Graphs.inneighbors, (zxd, v))) +Graphs.rem_edge!(zxd::AbstractZXDiagram, args...) = + throw(MethodError(Graphs.rem_edge!, (zxd, args...))) +Graphs.add_edge!(zxd::AbstractZXDiagram, args...) = + throw(MethodError(Graphs.add_edge!, (zxd, args...))) +Graphs.has_edge(zxd::AbstractZXDiagram, args...) = + throw(MethodError(Graphs.has_edge, (zxd, args...))) Base.show(io::IO, zxd::AbstractZXDiagram) = throw(MethodError(Base.show, io, zxd)) Base.copy(zxd::AbstractZXDiagram) = throw(MethodError(Base.copy, zxd)) -nqubits(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.nqubits, zxd)) -spiders(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.spiders, zxd)) -tcount(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.tcount, zxd)) -get_inputs(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.get_inputs, zxd)) -get_outputs(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.get_outputs, zxd)) -scalar(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.scalar, zxd)) -spider_sequence(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.spider_sequence, zxd)) -round_phases!(zxd::AbstractZXDiagram) = throw(MethodError(ZXCalculus.round_phases!, zxd)) +nqubits(zxd::AbstractZXDiagram) = throw(MethodError(ZX.nqubits, zxd)) +spiders(zxd::AbstractZXDiagram) = throw(MethodError(ZX.spiders, zxd)) +tcount(zxd::AbstractZXDiagram) = throw(MethodError(ZX.tcount, zxd)) +get_inputs(zxd::AbstractZXDiagram) = throw(MethodError(ZX.get_inputs, zxd)) +get_outputs(zxd::AbstractZXDiagram) = throw(MethodError(ZX.get_outputs, zxd)) +scalar(zxd::AbstractZXDiagram) = throw(MethodError(ZX.scalar, zxd)) +spider_sequence(zxd::AbstractZXDiagram) = throw(MethodError(ZX.spider_sequence, zxd)) +round_phases!(zxd::AbstractZXDiagram) = throw(MethodError(ZX.round_phases!, zxd)) -spider_type(zxd::AbstractZXDiagram, v) = throw(MethodError(ZXCalculus.spider_type, (zxd, v))) -phase(zxd::AbstractZXDiagram, v) = throw(MethodError(ZXCalculus.phase, (zxd, v))) -rem_spider!(zxd::AbstractZXDiagram, v) = throw(MethodError(ZXCalculus.rem_spider!, (zxd, v))) -rem_spiders!(zxd::AbstractZXDiagram, vs)= throw(MethodError(ZXCalculus.rem_spiders!, (zxd, vs))) -qubit_loc(zxd::AbstractZXDiagram, v) = throw(MethodError(ZXCalculus.qubit_loc, (zxd, v))) -column_loc(zxd::AbstractZXDiagram, v) = throw(MethodError(ZXCalculus.column_loc, (zxd, v))) -add_global_phase!(zxd::AbstractZXDiagram, p) = throw(MethodError(ZXCalculus.add_global_phase!, (zxd, p))) -add_power!(zxd::AbstractZXDiagram, n) = throw(MethodError(ZXCalculus.add_power!, (zxd, n))) -generate_layout!(zxd::AbstractZXDiagram, seq) = throw(MethodError(ZXCalculus.generate_layout!, (zxd, seq))) +spider_type(zxd::AbstractZXDiagram, v) = throw(MethodError(ZX.spider_type, (zxd, v))) +phase(zxd::AbstractZXDiagram, v) = throw(MethodError(ZX.phase, (zxd, v))) +rem_spider!(zxd::AbstractZXDiagram, v) = throw(MethodError(ZX.rem_spider!, (zxd, v))) +rem_spiders!(zxd::AbstractZXDiagram, vs) = throw(MethodError(ZX.rem_spiders!, (zxd, vs))) +qubit_loc(zxd::AbstractZXDiagram, v) = throw(MethodError(ZX.qubit_loc, (zxd, v))) +column_loc(zxd::AbstractZXDiagram, v) = throw(MethodError(ZX.column_loc, (zxd, v))) +add_global_phase!(zxd::AbstractZXDiagram, p) = + throw(MethodError(ZX.add_global_phase!, (zxd, p))) +add_power!(zxd::AbstractZXDiagram, n) = throw(MethodError(ZX.add_power!, (zxd, n))) +generate_layout!(zxd::AbstractZXDiagram, seq) = + throw(MethodError(ZX.generate_layout!, (zxd, seq))) -set_phase!(zxd::AbstractZXDiagram, args...) = throw(MethodError(ZXCalculus.set_phase!, (zxd, args...))) -push_gate!(zxd::AbstractZXDiagram, args...) = throw(MethodError(ZXCalculus.push_gate!, (zxd, args...))) -pushfirst_gate!(zxd::AbstractZXDiagram, args...) = throw(MethodError(ZXCalculus.pushfirst_gate!, (zxd, args...))) -add_spider!(zxd::AbstractZXDiagram, args...) = throw(MethodError(ZXCalculus.add_spider!, (zxd, args...))) -insert_spider!(zxd::AbstractZXDiagram, args...) = throw(MethodError(ZXCalculus.insert_spider!, (zxd, args...))) \ No newline at end of file +set_phase!(zxd::AbstractZXDiagram, args...) = + throw(MethodError(ZX.set_phase!, (zxd, args...))) +push_gate!(zxd::AbstractZXDiagram, args...) = + throw(MethodError(ZX.push_gate!, (zxd, args...))) +pushfirst_gate!(zxd::AbstractZXDiagram, args...) = + throw(MethodError(ZX.pushfirst_gate!, (zxd, args...))) +add_spider!(zxd::AbstractZXDiagram, args...) = + throw(MethodError(ZX.add_spider!, (zxd, args...))) +insert_spider!(zxd::AbstractZXDiagram, args...) = + throw(MethodError(ZX.insert_spider!, (zxd, args...))) diff --git a/src/adts.jl b/src/adts.jl index 8e97d86..8d712a2 100644 --- a/src/adts.jl +++ b/src/adts.jl @@ -1,22 +1,3 @@ -""" - Parameter -The Algebraic Data Type for representing parameter related to spider. -`PiUnit(x)` represents the the phase of a number `exp(im*x*π)`. -`Factor(x)` represents a number `x`. -""" -@adt Parameter begin - - struct PiUnit - pu - pu_type::Type - end - - struct Factor - f::Number - f_type::Type - end - -end @adt ZXWSpiderType begin W @@ -41,4 +22,3 @@ end end @const_use ZXWSpiderType:W, H, D, Z, X, Input, Output -@const_use Parameter:PiUnit, Factor diff --git a/src/parameter.jl b/src/parameter.jl index 5f5331f..6cf3784 100644 --- a/src/parameter.jl +++ b/src/parameter.jl @@ -1,4 +1,23 @@ -using .ZXW: Parameter, PiUnit, Factor +""" + Parameter +The Algebraic Data Type for representing parameter related to spider. +`PiUnit(x)` represents the the phase of a number `exp(im*x*π)`. +`Factor(x)` represents a number `x`. +""" +@adt Parameter begin + + struct PiUnit + pu + pu_type::Type + end + + struct Factor + f::Number + f_type::Type + end + +end +@const_use Parameter:PiUnit, Factor """ Parameter diff --git a/src/scalar.jl b/src/scalar.jl index 6ba2ed1..dc4afaa 100644 --- a/src/scalar.jl +++ b/src/scalar.jl @@ -1,3 +1,5 @@ +export Scalar + """ Scalar diff --git a/test/abstract_zx_diagram.jl b/test/abstract_zx_diagram.jl index 1dd08b3..74444bc 100644 --- a/test/abstract_zx_diagram.jl +++ b/test/abstract_zx_diagram.jl @@ -1,10 +1,9 @@ -using ZXCalculus, Graphs -using Test -using ZXCalculus: Phase +using ZXCalculus.ZX +using ZXCalculus.Utils: Phase -struct TestZXDiagram{T, P} <: AbstractZXDiagram{T, P} end +struct TestZXDiagram{T,P} <: AbstractZXDiagram{T,P} end -test_zxd = TestZXDiagram{Int, Phase}(); +test_zxd = TestZXDiagram{Int,Phase}(); @test_throws MethodError Graphs.nv(test_zxd) @test_throws MethodError Graphs.ne(test_zxd) @@ -21,27 +20,27 @@ test_zxd = TestZXDiagram{Int, Phase}(); @test_throws MethodError print(test_zxd) @test_throws MethodError Base.copy(test_zxd) -@test_throws MethodError ZXCalculus.nqubits(test_zxd) +@test_throws MethodError ZX.nqubits(test_zxd) @test_throws MethodError spiders(test_zxd) @test_throws MethodError tcount(test_zxd) -@test_throws MethodError ZXCalculus.get_inputs(test_zxd) -@test_throws MethodError ZXCalculus.get_outputs(test_zxd) -@test_throws MethodError ZXCalculus.scalar(test_zxd) -@test_throws MethodError ZXCalculus.spider_sequence(test_zxd) -@test_throws MethodError ZXCalculus.round_phases!(test_zxd) +@test_throws MethodError ZX.get_inputs(test_zxd) +@test_throws MethodError ZX.get_outputs(test_zxd) +@test_throws MethodError ZX.scalar(test_zxd) +@test_throws MethodError ZX.spider_sequence(test_zxd) +@test_throws MethodError ZX.round_phases!(test_zxd) @test_throws MethodError spider_type(test_zxd, 1) @test_throws MethodError phase(test_zxd, 1) @test_throws MethodError rem_spider!(test_zxd, 1) @test_throws MethodError rem_spiders!(test_zxd, [1, 2]) -@test_throws MethodError ZXCalculus.qubit_loc(test_zxd, 1) -@test_throws MethodError ZXCalculus.column_loc(test_zxd, 1) -@test_throws MethodError ZXCalculus.add_global_phase!(test_zxd, 3) -@test_throws MethodError ZXCalculus.add_power!(test_zxd, 4) -@test_throws MethodError ZXCalculus.generate_layout!(test_zxd, []) +@test_throws MethodError ZX.qubit_loc(test_zxd, 1) +@test_throws MethodError ZX.column_loc(test_zxd, 1) +@test_throws MethodError ZX.add_global_phase!(test_zxd, 3) +@test_throws MethodError ZX.add_power!(test_zxd, 4) +@test_throws MethodError ZX.generate_layout!(test_zxd, []) -@test_throws MethodError ZXCalculus.set_phase!(test_zxd, 1, Phase(1//1)) -@test_throws MethodError push_gate!(test_zxd, 1, Val(:X), Phase(1//2)) +@test_throws MethodError ZX.set_phase!(test_zxd, 1, Phase(1 // 1)) +@test_throws MethodError push_gate!(test_zxd, 1, Val(:X), Phase(1 // 2)) @test_throws MethodError pushfirst_gate!(test_zxd, 1, 2, Val(:CNOT)) -@test_throws MethodError ZXCalculus.add_spider!(test_zxd, Phase(1//1)) -@test_throws MethodError ZXCalculus.insert_spider!(test_zxd, Phase(1//2), [2, 3]) \ No newline at end of file +@test_throws MethodError ZX.add_spider!(test_zxd, Phase(1 // 1)) +@test_throws MethodError ZX.insert_spider!(test_zxd, Phase(1 // 2), [2, 3]) diff --git a/test/parameter.jl b/test/parameter.jl index 4893bc8..324123d 100644 --- a/test/parameter.jl +++ b/test/parameter.jl @@ -1,5 +1,5 @@ using Base: CodegenParams -using ZXCalculus.ZXW: Parameter +using ZXCalculus.Utils: Parameter @testset "Constructor" begin p1 = Parameter(Val(:PiUnit)) diff --git a/test/phase.jl b/test/phase.jl index 032935c..c5d1a72 100644 --- a/test/phase.jl +++ b/test/phase.jl @@ -1,11 +1,4 @@ -using Test -using YaoHIR -using YaoLocations -# using CompilerPluginTools -using ZXCalculus -using ZXCalculus: Phase, BlockIR -using YaoHIR.IntrinsicOperation -using YaoHIR: Chain, Gate, Ctrl +using ZXCalculus.Utils: Phase # ir = @make_ircode begin # Expr(:call, :+, 1, 1)::Int @@ -24,7 +17,9 @@ using YaoHIR: Chain, Gate, Ctrl # ZXCalculus.generate_layout!(zxd) # qc_tl = convert_to_chain(phase_teleportation(zxd)) # @test length(qc_tl) == 1 + p = Phase(1//1) + @test p + 1 == 1 + p == p + p @test p - 1 == 1 - p == p - p @test p / 1 == 1 / p == p / p diff --git a/test/phase_teleportation.jl b/test/phase_teleportation.jl index 0f8fad9..eb9eef7 100644 --- a/test/phase_teleportation.jl +++ b/test/phase_teleportation.jl @@ -1,4 +1,3 @@ -using ZXCalculus, Graphs function gen_cir() cir = ZXDiagram(5) diff --git a/test/rules.jl b/test/rules.jl index efe1a6e..0747948 100644 --- a/test/rules.jl +++ b/test/rules.jl @@ -73,7 +73,7 @@ add_edge!(g, 3, 5) add_edge!(g, 4, 6) ps = [0//1 for i = 1:6] v_t = [SpiderType.In, SpiderType.In, SpiderType.X, SpiderType.Z, SpiderType.Out, SpiderType.Out] -layout = ZXCalculus.ZXLayout(2, Dict(zip(1:6, [1//1, 2, 1, 2, 1, 2])), Dict(zip(1:6, [1//1, 1, 2, 2, 3, 3]))) +layout = ZXCalculus.ZX.ZXLayout(2, Dict(zip(1:6, [1//1, 2, 1, 2, 1, 2])), Dict(zip(1:6, [1//1, 1, 2, 2, 3, 3]))) zxd = ZXDiagram(g, v_t, ps, layout) matches = match(Rule{:b}(), zxd) rewrite!(Rule{:b}(), zxd, matches) @@ -156,4 +156,4 @@ end replace!(Rule{:p3}(), zxg) @test nv(zxg) == 16 && ne(zxg) == 28 -@test ZXCalculus.is_hadamard(zxg, 2, 15) && ZXCalculus.is_hadamard(zxg, 1, 16) +@test ZXCalculus.ZX.is_hadamard(zxg, 2, 15) && ZXCalculus.ZX.is_hadamard(zxg, 1, 16) diff --git a/test/runtests.jl b/test/runtests.jl index 294ec60..b38c6a2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,43 +1,38 @@ -using ZXCalculus, Graphs, Multigraphs, SparseArrays, ZXCalculus.ZXW, ZXCalculus.ZW +using ZXCalculus, Graphs, Multigraphs, SparseArrays, ZXCalculus.Utils, ZXCalculus.ZX # , ZXCalculus.ZXW, ZXCalculus.ZW +import ZXCalculus.ZX as ZX using YaoHIR: Chain using Documenter using Test -@testset "ZW Diagram with Planar Multigraph" begin - include("zw_diagram.jl") -end +# @testset "ZW Diagram with Planar Multigraph" begin +# include("zw_diagram.jl") +# end -@testset "ZW Diagram Utilities" begin - include("zw_utils.jl") -end +# @testset "ZW Diagram Utilities" begin +# include("zw_utils.jl") +# end -@testset "planar multigraphs.jl" begin - include("planar_multigraph.jl") -end +# @testset "planar multigraphs.jl" begin +# include("planar_multigraph.jl") +# end -@testset "zxw_rules.jl" begin - include("zxw_rules.jl") -end +# @testset "zxw_rules.jl" begin +# include("zxw_rules.jl") +# end -@testset "parameter.jl" begin - include("parameter.jl") -end -@testset "zxw_diagram.jl" begin - include("zxw_diagram.jl") -end +# @testset "zxw_diagram.jl" begin +# include("zxw_diagram.jl") +# end -@testset "utils.jl" begin - include("utils.jl") -end +# @testset "utils.jl" begin +# include("utils.jl") +# end -@testset "to_eincode.jl" begin - include("to_eincode.jl") -end +# @testset "to_eincode.jl" begin +# include("to_eincode.jl") +# end -@testset "scalar.jl" begin - include("scalar.jl") -end @testset "abstract_zx_diagram.jl" begin include("abstract_zx_diagram.jl") @@ -67,17 +62,25 @@ end # include("ir.jl") # end +@testset "scalar.jl" begin + include("scalar.jl") +end + @testset "phase.jl" begin include("phase.jl") end -@testset "simplify.jl" begin - include("simplify.jl") +@testset "parameter.jl" begin + include("parameter.jl") end -@testset "ancilla_extraction.jl" begin - include("ancilla_extraction.jl") - include("challenge.jl") -end +# @testset "simplify.jl" begin +# include("simplify.jl") +# end + +# @testset "ancilla_extraction.jl" begin +# include("ancilla_extraction.jl") +# include("challenge.jl") +# end -doctest(ZXCalculus) +# doctest(ZXCalculus) diff --git a/test/scalar.jl b/test/scalar.jl index 23ef724..0d1236d 100644 --- a/test/scalar.jl +++ b/test/scalar.jl @@ -1,6 +1,6 @@ -using ZXCalculus: Scalar, add_power!, add_phase! +using ZXCalculus.Utils: Scalar, add_power!, add_phase! s = Scalar() @test s * s == s @test add_power!(s, 1) == Scalar(1, 0) -@test add_phase!(s, 1) == Scalar(1, 1) \ No newline at end of file +@test add_phase!(s, 1) == Scalar(1, 1) diff --git a/test/zx_diagram.jl b/test/zx_diagram.jl index 5078bca..3e74013 100644 --- a/test/zx_diagram.jl +++ b/test/zx_diagram.jl @@ -7,27 +7,27 @@ zxd2 = ZXDiagram(g, Dict(zip(1:3,v_t)), Dict(zip(1:3,ps))) zxd2 = copy(zxd) @test zxd.st == zxd2.st && zxd.ps == zxd2.ps -@test ZXCalculus.spider_type(zxd, 1) == SpiderType.X +@test ZX.spider_type(zxd, 1) == SpiderType.X @test nv(zxd) == 3 && ne(zxd) == 2 @test rem_edge!(zxd, 2, 3) @test outneighbors(zxd, 2) == inneighbors(zxd, 2) -ZXCalculus.add_spider!(zxd, SpiderType.H, 0//1, [2, 3]) -ZXCalculus.insert_spider!(zxd, 2, 4, SpiderType.H) +ZX.add_spider!(zxd, SpiderType.H, 0//1, [2, 3]) +ZX.insert_spider!(zxd, 2, 4, SpiderType.H) @test nv(zxd) == 5 && ne(zxd) == 4 zxd3 = ZXDiagram(3) -ZXCalculus.insert_spider!(zxd3, 1, 2, SpiderType.H) +ZX.insert_spider!(zxd3, 1, 2, SpiderType.H) pushfirst_gate!(zxd3, Val{:SWAP}(), [1, 2]) push_gate!(zxd3, Val{:SWAP}(), [2, 3]) -@test ZXCalculus.qubit_loc(zxd3, 1) == ZXCalculus.qubit_loc(zxd3, 2) +@test ZX.qubit_loc(zxd3, 1) == ZX.qubit_loc(zxd3, 2) @testset "float to rational" begin - @test ZXCalculus.continued_fraction(2.41, 10) === 241//100 - @test ZXCalculus.continued_fraction(1.3, 10) === 13//10 - @test ZXCalculus.continued_fraction(0, 10) === 0//1 - @test ZXCalculus.continued_fraction(-0.5, 10) === -1//2 + @test ZX.continued_fraction(2.41, 10) === 241//100 + @test ZX.continued_fraction(1.3, 10) === 13//10 + @test ZX.continued_fraction(0, 10) === 0//1 + @test ZX.continued_fraction(-0.5, 10) === -1//2 zxd = ZXDiagram(4) push_gate!(zxd, Val(:X), 3, 0.5) @test zxd.ps[9] == 1//2 @@ -37,15 +37,15 @@ push_gate!(zxd3, Val{:SWAP}(), [2, 3]) @test zxd.ps[11] == 0//1 @test_warn "" push_gate!(zxd, Val(:Z), 3, sqrt(2)) @test_throws MethodError push_gate!(zxd, Val(:Z), 3, sqrt(2); autoconvert=false) - @test ZXCalculus.safe_convert(Rational{Int64}, 1.2) == 6//5 && ZXCalculus.safe_convert(Rational{Int64}, 1//2) == 1//2 + @test ZX.safe_convert(Rational{Int64}, 1.2) == 6//5 && ZX.safe_convert(Rational{Int64}, 1//2) == 1//2 end zxd4 = ZXDiagram(2) -ZXCalculus.add_global_phase!(zxd4, ZXCalculus.Phase(1//2)) -ZXCalculus.add_power!(zxd4, 2) -@test ZXCalculus.scalar(zxd4) == ZXCalculus.Scalar(2, 1//2) +ZX.add_global_phase!(zxd4, ZXCalculus.Utils.Phase(1//2)) +ZX.add_power!(zxd4, 2) +@test ZX.scalar(zxd4) == ZXCalculus.Utils.Scalar(2, 1//2) pushfirst_gate!(zxd4, Val(:X), 1) pushfirst_gate!(zxd4, Val(:H), 1) pushfirst_gate!(zxd4, Val(:CNOT), 2, 1) pushfirst_gate!(zxd4, Val(:CZ), 1, 2) -@test indegree(zxd4, 5) == outdegree(zxd4, 5) == degree(zxd4, 5) \ No newline at end of file +@test indegree(zxd4, 5) == outdegree(zxd4, 5) == degree(zxd4, 5) diff --git a/test/zx_graph.jl b/test/zx_graph.jl index 79d9480..d5466ab 100644 --- a/test/zx_graph.jl +++ b/test/zx_graph.jl @@ -9,14 +9,14 @@ v_t = [SpiderType.In, SpiderType.In, SpiderType.X, SpiderType.Z, SpiderType.Out, zxd = ZXDiagram(g, v_t, ps) zxg1 = ZXGraph(zxd) @test outneighbors(zxg1, 1) == inneighbors(zxg1, 1) -@test !ZXCalculus.is_hadamard(zxg1, 2, 4) && !ZXCalculus.is_hadamard(zxg1, 4, 6) +@test !ZX.is_hadamard(zxg1, 2, 4) && !ZX.is_hadamard(zxg1, 4, 6) @test add_edge!(zxg1, 1, 1) @test !add_edge!(zxg1, 2, 4) @test !add_edge!(zxg1, 7, 8) -@test sum([ZXCalculus.is_hadamard(zxg1, src(e), dst(e)) for e in edges(zxg1.mg)]) == 3 +@test sum([ZX.is_hadamard(zxg1, src(e), dst(e)) for e in edges(zxg1.mg)]) == 3 replace!(Rule{:b}(), zxd) zxg2 = ZXGraph(zxd) -@test !ZXCalculus.is_hadamard(zxg2, 5, 8) && !ZXCalculus.is_hadamard(zxg2, 1, 7) +@test !ZX.is_hadamard(zxg2, 5, 8) && !ZX.is_hadamard(zxg2, 1, 7) zxd = ZXDiagram(2) push_gate!(zxd, Val(:H), 1) @@ -24,10 +24,10 @@ push_gate!(zxd, Val(:CNOT), 2, 1) zxg = ZXGraph(zxd) zxg3 = ZXGraph(ZXDiagram(3)) -ZXCalculus.add_global_phase!(zxg3, ZXCalculus.Phase(1//4)) -ZXCalculus.add_power!(zxg3, 3) -@test ZXCalculus.scalar(zxg3) == Scalar(3, 1//4) +ZX.add_global_phase!(zxg3, ZXCalculus.Utils.Phase(1//4)) +ZX.add_power!(zxg3, 3) +@test ZX.scalar(zxg3) == Scalar(3, 1//4) @test degree(zxg3, 1) == indegree(zxg3, 1) == outdegree(zxg3, 1) -@test ZXCalculus.qubit_loc(zxg3, 1) == ZXCalculus.qubit_loc(zxg3, 2) -@test ZXCalculus.column_loc(zxg3, 1) == 1//1 -@test ZXCalculus.column_loc(zxg3, 2) == 3//1 \ No newline at end of file +@test ZX.qubit_loc(zxg3, 1) == ZX.qubit_loc(zxg3, 2) +@test ZX.column_loc(zxg3, 1) == 1//1 +@test ZX.column_loc(zxg3, 2) == 3//1 From 826188d74fb898a5833c1812433a217b92969b24 Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Tue, 10 Oct 2023 22:14:51 +0800 Subject: [PATCH 03/10] port most of ZXW --- src/ZXCalculus.jl | 28 ++++++++------- src/adts.jl | 1 - src/zxw_rules.jl | 4 +-- test/ancilla_extraction.jl | 5 ++- test/challenge.jl | 9 ++--- test/runtests.jl | 73 +++++++++++++++++++------------------- test/simplify.jl | 2 +- test/zxw_diagram.jl | 3 +- test/zxw_rules.jl | 6 ++-- 9 files changed, 68 insertions(+), 63 deletions(-) diff --git a/src/ZXCalculus.jl b/src/ZXCalculus.jl index 7691fb7..cd94e7e 100644 --- a/src/ZXCalculus.jl +++ b/src/ZXCalculus.jl @@ -4,8 +4,6 @@ module ZXCalculus # import Graphs: has_vertex - - # using Graphs: # nv, # ne, @@ -71,24 +69,28 @@ include("ir.jl") end -# module ZXW -# using Expronicon.ADT: @const_use, @adt -# using MLStyle, Multigraphs, Graphs +module ZXW +using Expronicon.ADT: @const_use, @adt +using MLStyle, Multigraphs, Graphs +using ..Utils: Scalar, Phase, Parameter, PiUnit, Factor, add_phase! +using ..ZX: safe_convert, AbstractRule, Rule, Match +import ..Utils: add_power! +import ..ZX: + rewrite!, simplify!, push_gate!, pushfirst_gate!, spiders, rem_spider!, rem_spiders! # using OMEinsum # import Multigraphs: has_vertex -# using ..ZXCalculus -# using ..ZXCalculus: safe_convert, add_phase! -# import ..pushfirst_gate!, ..push_gate! # import ..rewrite!, ..add_power!, ..add_edge!, ..vertices, ..nv, ..round_phases! -# include("adts.jl") -# include("zxw_diagram.jl") -# include("zxw_rules.jl") +export ZXWDiagram + +include("adts.jl") +include("zxw_diagram.jl") +include("zxw_rules.jl") # include("to_eincode.jl") -# include("utils.jl") +include("utils.jl") -# end # module ZXW +end # module ZXW # using .ZXW: ZXWDiagram, CalcRule diff --git a/src/adts.jl b/src/adts.jl index 8d712a2..64772df 100644 --- a/src/adts.jl +++ b/src/adts.jl @@ -1,4 +1,3 @@ - @adt ZXWSpiderType begin W H diff --git a/src/zxw_rules.jl b/src/zxw_rules.jl index 2814942..b3d05c7 100644 --- a/src/zxw_rules.jl +++ b/src/zxw_rules.jl @@ -152,7 +152,7 @@ function rewrite!(::Rule{:b1}, zxwd::ZXWDiagram{T,P}, vs::Vector{T}) where {T,P} return zxwd end -function rewrite!(r::CalcRule{:diff}, zxwd::ZXWDiagram{T,P}, vs::Vector{T}) where {T,P} +function rewrite!(::CalcRule{:diff}, zxwd::ZXWDiagram{T,P}, vs::Vector{T}) where {T,P} zero_loc = findfirst(x -> x == zero(T), vs) add_global_phase!(zxwd, P(π / 2)) @@ -203,7 +203,7 @@ function rewrite!(r::CalcRule{:diff}, zxwd::ZXWDiagram{T,P}, vs::Vector{T}) wher return zxwd end -function rewrite!(r::CalcRule{:int}, zxwd::ZXWDiagram{T,P}, vs::Vector{T}) where {T,P} +function rewrite!(::CalcRule{:int}, zxwd::ZXWDiagram{T,P}, vs::Vector{T}) where {T,P} zero_loc = findfirst(x -> x == zero(T), vs) return integrate!(zxwd, view(vs, 1:zero_loc-1)..., view(vs, zero_loc+1:length(vs))...) end diff --git a/test/ancilla_extraction.jl b/test/ancilla_extraction.jl index f82d3cb..c416392 100644 --- a/test/ancilla_extraction.jl +++ b/test/ancilla_extraction.jl @@ -1,5 +1,4 @@ -using ZXCalculus -using ZXCalculus: ancilla_extraction +using ZXCalculus.ZX: ancilla_extraction function gen_phase_gadget() zxd = ZXDiagram(2) @@ -26,4 +25,4 @@ convert_to_chain(zxd_swap) zxg_swap = ZXGraph(zxd_swap) zxd_anc = ancilla_extraction(zxg_swap) # plot(zxd_anc) -@test length(ZXCalculus.convert_to_chain(zxd_anc)) == 3 \ No newline at end of file +@test length(ZX.convert_to_chain(zxd_anc)) == 3 diff --git a/test/challenge.jl b/test/challenge.jl index 5e77a0e..a2097f0 100644 --- a/test/challenge.jl +++ b/test/challenge.jl @@ -1,5 +1,6 @@ -using ZXCalculus -using ZXCalculus: SpiderType +using ZXCalculus.ZX: SpiderType, EdgeType +using ZXCalculus.Utils: Phase + st = Dict( 0+1 => SpiderType.In, 1+1 => SpiderType.In, @@ -195,7 +196,7 @@ using Graphs zxg = ZXGraph(ZXDiagram(0)) vs = 1:52 for v in vs - ZXCalculus.add_spider!(zxg, st[v], ZXCalculus.Phase(ps[v])) + ZX.add_spider!(zxg, st[v], Phase(ps[v])) end for (e, _) in es Graphs.add_edge!(zxg, e[1], e[2]) @@ -205,4 +206,4 @@ for i = 1:5 push!(zxg.outputs, i+23) end -ZXCalculus.ancilla_extraction(zxg) \ No newline at end of file +ZX.ancilla_extraction(zxg) diff --git a/test/runtests.jl b/test/runtests.jl index b38c6a2..fa89a61 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,39 +1,11 @@ -using ZXCalculus, Graphs, Multigraphs, SparseArrays, ZXCalculus.Utils, ZXCalculus.ZX # , ZXCalculus.ZXW, ZXCalculus.ZW +using ZXCalculus, + Graphs, Multigraphs, SparseArrays, ZXCalculus.Utils, ZXCalculus.ZX, ZXCalculus.ZXW #, ZXCalculus.ZW import ZXCalculus.ZX as ZX +import ZXCalculus.ZXW as ZXW using YaoHIR: Chain using Documenter using Test -# @testset "ZW Diagram with Planar Multigraph" begin -# include("zw_diagram.jl") -# end - -# @testset "ZW Diagram Utilities" begin -# include("zw_utils.jl") -# end - -# @testset "planar multigraphs.jl" begin -# include("planar_multigraph.jl") -# end - -# @testset "zxw_rules.jl" begin -# include("zxw_rules.jl") -# end - - -# @testset "zxw_diagram.jl" begin -# include("zxw_diagram.jl") -# end - -# @testset "utils.jl" begin -# include("utils.jl") -# end - -# @testset "to_eincode.jl" begin -# include("to_eincode.jl") -# end - - @testset "abstract_zx_diagram.jl" begin include("abstract_zx_diagram.jl") end @@ -74,13 +46,42 @@ end include("parameter.jl") end -# @testset "simplify.jl" begin -# include("simplify.jl") +@testset "simplify.jl" begin + include("simplify.jl") +end + +@testset "ancilla_extraction.jl" begin + include("ancilla_extraction.jl") + include("challenge.jl") +end + +# @testset "ZW Diagram with Planar Multigraph" begin +# include("zw_diagram.jl") # end -# @testset "ancilla_extraction.jl" begin -# include("ancilla_extraction.jl") -# include("challenge.jl") +# @testset "ZW Diagram Utilities" begin +# include("zw_utils.jl") +# end + +# @testset "planar multigraphs.jl" begin +# include("planar_multigraph.jl") +# end + + +@testset "zxw_diagram.jl" begin + include("zxw_diagram.jl") +end + +@testset "utils.jl" begin + include("utils.jl") +end + +@testset "zxw_rules.jl" begin + include("zxw_rules.jl") +end + +# @testset "to_eincode.jl" begin +# include("to_eincode.jl") # end # doctest(ZXCalculus) diff --git a/test/simplify.jl b/test/simplify.jl index 3c811f4..d9072f8 100644 --- a/test/simplify.jl +++ b/test/simplify.jl @@ -8,6 +8,6 @@ push_gate!(chain_swap, Val(:SWAP), 3, 4) push_gate!(chain_swap, Val(:SWAP), 4, 3) push_gate!(chain_swap, Val(:SWAP), 2, 3) -ZXCalculus.simplify_swap!(chain_swap) +ZX.simplify_swap!(chain_swap) @test length(chain_swap) == 9 diff --git a/test/zxw_diagram.jl b/test/zxw_diagram.jl index 2ab4fb6..41503f9 100644 --- a/test/zxw_diagram.jl +++ b/test/zxw_diagram.jl @@ -1,4 +1,5 @@ -using ZXCalculus.ZXW: ZXWSpiderType, Parameter, PiUnit, Factor, Input, Output, W, H, D, Z, X +using ZXCalculus.ZXW: ZXWSpiderType, Input, Output, W, H, D, Z, X +using ZXCalculus.Utils: Parameter, PiUnit, Factor @testset "ZXWSpiderType" begin diff --git a/test/zxw_rules.jl b/test/zxw_rules.jl index f296228..45aef0c 100644 --- a/test/zxw_rules.jl +++ b/test/zxw_rules.jl @@ -1,13 +1,15 @@ using Test: match_logs -using ZXCalculus: insert_spider!, rewrite! using ZXCalculus.ZXW: + rewrite!, symbol_vertices, dagger, concat!, expval_circ!, push_gate!, stack_zxwd!, - substitute_variables! + substitute_variables!, + insert_spider! + @testset "Calculus Rule" begin deri_rule = CalcRule(:diff, :p) From abe31b4507aa74b7a16d38996d3023b26bf720ef Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Thu, 12 Oct 2023 15:04:02 +0800 Subject: [PATCH 04/10] finish porting ZXW --- src/ZXCalculus.jl | 15 ++++++++------- src/to_eincode.jl | 2 +- test/runtests.jl | 17 ++++++++++++----- test/to_eincode.jl | 5 +++-- test/zxw_rules.jl | 1 + 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/ZXCalculus.jl b/src/ZXCalculus.jl index cd94e7e..460eb81 100644 --- a/src/ZXCalculus.jl +++ b/src/ZXCalculus.jl @@ -1,7 +1,5 @@ module ZXCalculus -# using OMEinsum - # import Graphs: has_vertex # using Graphs: @@ -77,17 +75,15 @@ using ..ZX: safe_convert, AbstractRule, Rule, Match import ..Utils: add_power! import ..ZX: rewrite!, simplify!, push_gate!, pushfirst_gate!, spiders, rem_spider!, rem_spiders! -# using OMEinsum # import Multigraphs: has_vertex # import ..rewrite!, ..add_power!, ..add_edge!, ..vertices, ..nv, ..round_phases! -export ZXWDiagram +export ZXWDiagram, substitute_variables! include("adts.jl") include("zxw_diagram.jl") include("zxw_rules.jl") -# include("to_eincode.jl") include("utils.jl") end # module ZXW @@ -143,9 +139,14 @@ end # module ZXW # include("zw_utils.jl") # end # module ZW -# module Application +module Application +using OMEinsum, MLStyle +using ..ZXW: ZXWDiagram, Z, X, W, H, D, Input, Output +using ..Utils: PiUnit, Factor, Parameter, unwrap_scalar +using ..ZXW: get_outputs, get_inputs, degree, neighbors, vertices, scalar, nin, nout -# end # module APP +include("to_eincode.jl") +end # module Application include("deprecations.jl") end # module diff --git a/src/to_eincode.jl b/src/to_eincode.jl index 4e7ba21..fc0613e 100644 --- a/src/to_eincode.jl +++ b/src/to_eincode.jl @@ -40,7 +40,7 @@ function to_eincode(zxwd::ZXWDiagram{T,P}) where {T,P} scalar_tensor = zeros(ComplexF64, ()) - scalar_tensor[] = ZXCalculus.unwrap_scalar(scalar(zxwd)) + scalar_tensor[] = unwrap_scalar(scalar(zxwd)) push!(ixs, Tuple{T,T,T}[]) push!(tensors, scalar_tensor) return EinCode(ixs, iy), tensors diff --git a/test/runtests.jl b/test/runtests.jl index fa89a61..5c7711c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,12 @@ using ZXCalculus, - Graphs, Multigraphs, SparseArrays, ZXCalculus.Utils, ZXCalculus.ZX, ZXCalculus.ZXW #, ZXCalculus.ZW + Graphs, + Multigraphs, + SparseArrays, + ZXCalculus.Utils, + ZXCalculus.ZX, + ZXCalculus.ZXW, + ZXCalculus.Application #, ZXCalculus.ZW + import ZXCalculus.ZX as ZX import ZXCalculus.ZXW as ZXW using YaoHIR: Chain @@ -80,8 +87,8 @@ end include("zxw_rules.jl") end -# @testset "to_eincode.jl" begin -# include("to_eincode.jl") -# end +@testset "to_eincode.jl" begin + include("to_eincode.jl") +end -# doctest(ZXCalculus) +doctest(ZXCalculus) diff --git a/test/to_eincode.jl b/test/to_eincode.jl index 36728bb..fc0c94a 100644 --- a/test/to_eincode.jl +++ b/test/to_eincode.jl @@ -1,6 +1,7 @@ +using ZXCalculus.Application: + z_tensor, x_tensor, w_tensor, h_tensor, d_tensor +using ZXCalculus.ZXW: push_gate! using LinearAlgebra -using ZXCalculus.ZXW: - z_tensor, x_tensor, w_tensor, h_tensor, d_tensor, push_gate!, substitute_variables! @testset "Tensors" begin @test z_tensor(2, Parameter(Val(:PiUnit), 1 // 2)) == [1 0; 0 exp(im * π / 2)] diff --git a/test/zxw_rules.jl b/test/zxw_rules.jl index 45aef0c..65f967b 100644 --- a/test/zxw_rules.jl +++ b/test/zxw_rules.jl @@ -1,5 +1,6 @@ using Test: match_logs using ZXCalculus.ZXW: + CalcRule, rewrite!, symbol_vertices, dagger, From 8b1eb13a139ec54dab9d61c8e654abce5fb99373 Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Thu, 12 Oct 2023 16:07:34 +0800 Subject: [PATCH 05/10] finish all porting --- src/ZXCalculus.jl | 131 +++++++++++++++++--------------------- src/planar_multigraph.jl | 4 -- src/zx_diagram.jl | 6 +- src/zx_graph.jl | 2 +- test/planar_multigraph.jl | 2 +- test/runtests.jl | 32 ++++++---- test/zw_diagram.jl | 17 +++-- test/zw_utils.jl | 14 ++-- 8 files changed, 96 insertions(+), 112 deletions(-) diff --git a/src/ZXCalculus.jl b/src/ZXCalculus.jl index 460eb81..8bb1ca0 100644 --- a/src/ZXCalculus.jl +++ b/src/ZXCalculus.jl @@ -1,20 +1,5 @@ module ZXCalculus -# import Graphs: has_vertex - -# using Graphs: -# nv, -# ne, -# outneighbors, -# inneighbors, -# neighbors, -# rem_edge!, -# add_edge!, -# has_edge, -# degree, -# indegree, -# outdegree - module Utils using Expronicon.ADT: @const_use, @adt @@ -33,8 +18,8 @@ using YaoHIR.IntrinsicOperation using YaoHIR: Chain using YaoLocations: plain using MLStyle +using ..Utils: Scalar, Phase, add_phase! -using ZXCalculus.Utils: Scalar, Phase, add_phase! import ..Utils: add_power! export spiders, @@ -63,21 +48,18 @@ include("circuit_extraction.jl") include("phase_teleportation.jl") include("ir.jl") - end - module ZXW + using Expronicon.ADT: @const_use, @adt using MLStyle, Multigraphs, Graphs using ..Utils: Scalar, Phase, Parameter, PiUnit, Factor, add_phase! using ..ZX: safe_convert, AbstractRule, Rule, Match + import ..Utils: add_power! import ..ZX: rewrite!, simplify!, push_gate!, pushfirst_gate!, spiders, rem_spider!, rem_spiders! -# import Multigraphs: has_vertex -# import ..rewrite!, ..add_power!, ..add_edge!, ..vertices, ..nv, ..round_phases! - export ZXWDiagram, substitute_variables! @@ -88,58 +70,65 @@ include("utils.jl") end # module ZXW -# using .ZXW: ZXWDiagram, CalcRule - -# export ZXWDiagram, CalcRule - - -# 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 +module PMG + +using Graphs + +import Graphs: AbstractEdge, src, dst, nv, ne, neighbors +import Graphs.SimpleGraphs: vertices + +export HalfEdge, src, dst, new_edge, PlanarMultigraph + +include("planar_multigraph.jl") + +end # module PlanarMultigraph + +module ZW +using Expronicon.ADT: @adt, @const_use +using MLStyle, Graphs +using ..ZXW: _round_phase, Parameter + +# these will be changed to using PlanarMultigraph: vertices after we split out package +using ..PMG: + 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 ..Utils: add_phase!, Scalar, Phase, Parameter, PiUnit, Factor, add_power! +using ..PMG: PlanarMultigraph, HalfEdge, new_edge, src, dst +import ..Utils: add_power! +import ..ZX: add_global_phase!, scalar, spiders, rem_spider! +import Graphs.rem_edge! + +export ZWDiagram + +include("zw_adt.jl") +include("zw_diagram.jl") +include("zw_utils.jl") +end # module ZW module Application + using OMEinsum, MLStyle using ..ZXW: ZXWDiagram, Z, X, W, H, D, Input, Output using ..Utils: PiUnit, Factor, Parameter, unwrap_scalar diff --git a/src/planar_multigraph.jl b/src/planar_multigraph.jl index 0238494..d69076b 100644 --- a/src/planar_multigraph.jl +++ b/src/planar_multigraph.jl @@ -1,7 +1,3 @@ -import Graphs: AbstractEdge, src, dst, nv, ne, neighbors -import Graphs.SimpleGraphs: vertices -export HalfEdge, src, dst, new_edge, PlanarMultigraph - """ HalfEdge{T<:Integer}(src ,dst) diff --git a/src/zx_diagram.jl b/src/zx_diagram.jl index 72f57c2..c07eb27 100644 --- a/src/zx_diagram.jl +++ b/src/zx_diagram.jl @@ -70,9 +70,9 @@ end Construct a ZXDiagram with all information. ```jldoctest -julia> using Graphs, Multigraphs, ZXCalculus; +julia> using Graphs, Multigraphs, ZXCalculus.ZX; -julia> using ZXCalculus.SpiderType: In, Out, H, Z, X; +julia> using ZXCalculus.ZX.SpiderType: In, Out, H, Z, X; julia> mg = Multigraph(5); @@ -101,7 +101,7 @@ ZXDiagram(mg::Multigraph{T}, st::Vector{SpiderType.SType}, ps::Vector{P}, Construct a ZXDiagram of a empty circuit with qubit number `nbit` -```jldoctest; setup = :(using ZXCalculus) +```jldoctest; setup = :(using ZXCalculus.ZX) julia> zxd = ZXDiagram(3) ZX-diagram with 6 vertices and 3 multiple edges: (S_1{input} <-1-> S_2{output}) diff --git a/src/zx_graph.jl b/src/zx_graph.jl index 1ccd2ca..f70f95d 100644 --- a/src/zx_graph.jl +++ b/src/zx_graph.jl @@ -35,7 +35,7 @@ end Convert a ZX-diagram to graph-like ZX-diagram. ```jldoctest -julia> using ZXCalculus +julia> using ZXCalculus.ZX julia> zxd = ZXDiagram(2); push_gate!(zxd, Val{:CNOT}(), 2, 1); diff --git a/test/planar_multigraph.jl b/test/planar_multigraph.jl index 0a13f19..4219308 100644 --- a/test/planar_multigraph.jl +++ b/test/planar_multigraph.jl @@ -1,4 +1,4 @@ -using ZXCalculus: +using ZXCalculus.PMG: create_vertex!, create_edge!, split_vertex!, diff --git a/test/runtests.jl b/test/runtests.jl index 5c7711c..1be432d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,10 +5,14 @@ using ZXCalculus, ZXCalculus.Utils, ZXCalculus.ZX, ZXCalculus.ZXW, - ZXCalculus.Application #, ZXCalculus.ZW + ZXCalculus.PMG, + ZXCalculus.Application, + ZXCalculus.ZW import ZXCalculus.ZX as ZX import ZXCalculus.ZXW as ZXW +import ZXCalculus.ZW as ZW + using YaoHIR: Chain using Documenter using Test @@ -62,19 +66,6 @@ end include("challenge.jl") end -# @testset "ZW Diagram with Planar Multigraph" begin -# include("zw_diagram.jl") -# end - -# @testset "ZW Diagram Utilities" begin -# include("zw_utils.jl") -# end - -# @testset "planar multigraphs.jl" begin -# include("planar_multigraph.jl") -# end - - @testset "zxw_diagram.jl" begin include("zxw_diagram.jl") end @@ -87,6 +78,19 @@ end include("zxw_rules.jl") end +@testset "planar multigraphs.jl" begin + include("planar_multigraph.jl") +end + +@testset "ZW Diagram with Planar Multigraph" begin + include("zw_diagram.jl") +end + +@testset "ZW Diagram Utilities" begin + include("zw_utils.jl") +end + + @testset "to_eincode.jl" begin include("to_eincode.jl") end diff --git a/test/zw_diagram.jl b/test/zw_diagram.jl index f2aba2c..436a29b 100644 --- a/test/zw_diagram.jl +++ b/test/zw_diagram.jl @@ -1,4 +1,3 @@ -using ZXCalculus.ZW: ZWDiagram, Input, Output @testset "ZWDiagrm Creation" begin zx1 = ZWDiagram(1) pmg1 = PlanarMultigraph( @@ -15,7 +14,7 @@ using ZXCalculus.ZW: ZWDiagram, Input, Output ) - @test zx1.st == Dict([1 => Input(1), 2 => Output(1)]) + @test zx1.st == Dict([1 => ZW.Input(1), 2 => ZW.Output(1)]) @test zx1.inputs == [1] @test zx1.outputs == [2] @test zx1.pmg == pmg1 @@ -44,7 +43,7 @@ using ZXCalculus.ZW: ZWDiagram, Input, Output [0], ) - @test zx2.st == Dict([1 => Input(1), 2 => Output(1), 3 => Input(2), 4 => Output(2)]) + @test zx2.st == Dict([1 => ZW.Input(1), 2 => ZW.Output(1), 3 => ZW.Input(2), 4 => ZW.Output(2)]) @test zx2.inputs == [1, 3] @test zx2.outputs == [2, 4] @test zx2.pmg == pmg2 @@ -127,12 +126,12 @@ using ZXCalculus.ZW: ZWDiagram, Input, Output ) @test zx3.st == Dict([ - 1 => Input(1), - 2 => Output(1), - 3 => Input(2), - 4 => Output(2), - 5 => Input(3), - 6 => Output(3), + 1 => ZW.Input(1), + 2 => ZW.Output(1), + 3 => ZW.Input(2), + 4 => ZW.Output(2), + 5 => ZW.Input(3), + 6 => ZW.Output(3), ]) @test zx3.inputs == [1, 3, 5] @test zx3.outputs == [2, 4, 6] diff --git a/test/zw_utils.jl b/test/zw_utils.jl index 81d6ce3..dbc02e1 100644 --- a/test/zw_utils.jl +++ b/test/zw_utils.jl @@ -1,7 +1,5 @@ using ZXCalculus.ZW: - ZWDiagram, ZWSpiderType, - spider_type, set_phase!, parameter, nin, @@ -23,7 +21,6 @@ using ZXCalculus.ZW: get_output_idx, add_power!, add_global_phase!, - insert_spider!, neighbors, join_spider!, add_edge!, @@ -31,14 +28,13 @@ using ZXCalculus.ZW: rem_edge!, rem_spider! - -using ZXCalculus: trace_vertex -using ZXCalculus.ZXW: Parameter +using ZXCalculus.PMG: trace_vertex +using ZXCalculus.Utils: Parameter @testset "utils" begin zw = ZWDiagram(3) - @test spider_type(zw, 1) == ZW.Input(1) + @test ZW.spider_type(zw, 1) == ZW.Input(1) @test parameter(zw, 2) == 1 @test nqubits(zw) == 3 @test nin(zw) == 3 @@ -155,7 +151,7 @@ end [0], ) - insert_spider!(zw, 12, ZW.binZ(Parameter(Val(:Factor), 2.0))) + ZW.insert_spider!(zw, 12, ZW.binZ(Parameter(Val(:Factor), 2.0))) @test zw.pmg == pmg2 set_phase!(zw, 7, Parameter(Val(:PiUnit), 1)) @@ -256,7 +252,7 @@ end @test pmg2 == zw.pmg zw2 = ZWDiagram(3) - insert_spider!(zw2, 12, ZW.binZ(Parameter(Val(:Factor), 2.0))) + ZW.insert_spider!(zw2, 12, ZW.binZ(Parameter(Val(:Factor), 2.0))) add_spider!(zw2, ZW.fSWAP, [1, 7, 4]) st2 = Dict( From cf20e855c06ad0e6a2e733f8167bd675650336a0 Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Sun, 15 Oct 2023 14:20:32 +0800 Subject: [PATCH 06/10] change docs --- docs/make.jl | 4 +- docs/src/api.md | 147 ------------------------------------------ docs/src/tutorials.md | 5 +- 3 files changed, 6 insertions(+), 150 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 531d4fc..69b4e4e 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -2,12 +2,11 @@ using Documenter using DocThemeIndigo using ZXCalculus -using ZXCalculus: ZXW, ZW using Multigraphs indigo = DocThemeIndigo.install(ZXCalculus) makedocs(; - modules = [ZXCalculus, ZXW, ZW], + modules = Module[ZXCalculus], format=Documenter.HTML(; # ... # put your indigo css in assets @@ -21,6 +20,7 @@ makedocs(; ], repo = "https:/github.com/QuantumBFS/ZXCalculus.jl", sitename = "ZXCalculus.jl", + warnonly=true, ) deploydocs(repo = "github.com/QuantumBFS/ZXCalculus.jl.git") diff --git a/docs/src/api.md b/docs/src/api.md index 9090665..59b8f89 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -1,148 +1 @@ # APIs - -```@meta -CurrentModule = ZXCalculus -``` - -## ZX-diagrams - -```@docs -ZXCalculus.ZXDiagram -ZXDiagram(nbit::Int) -ZXCalculus.ZXGraph -ZXCalculus.ZXGraph(::ZXDiagram) -ZXCalculus.ZXLayout -ZXCalculus.qubit_loc -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) -Graphs.ne(::ZXDiagram) -Graphs.neighbors(::ZXDiagram, v) -ZXCalculus.is_interior(zxg::ZXGraph{T, P}, v::T) where {T, P} -ZXCalculus.add_spider! -ZXCalculus.insert_spider! -ZXCalculus.rem_spiders! -ZXCalculus.rem_spider! -``` - -## Pushing gates -```@docs -ZXCalculus.push_gate! -ZXCalculus.pushfirst_gate! -``` - -## Simplification -```@docs -ZXCalculus.phase_teleportation -ZXCalculus.clifford_simplification -Rule{L} where L -ZXCalculus.simplify! -ZXCalculus.replace! -ZXCalculus.match -ZXCalculus.rewrite! -ZXCalculus.Match -``` - -## Circuit extraction -```@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 -``` - diff --git a/docs/src/tutorials.md b/docs/src/tutorials.md index e1d719c..db5c480 100644 --- a/docs/src/tutorials.md +++ b/docs/src/tutorials.md @@ -1,4 +1,7 @@ # Tutorials +```@meta +CurrentModule= ZXCalculus.ZX +``` ZX-diagrams are the basic objects in ZX-calculus. In our implementation, each ZX-diagram consists of a multigraph and vertices information including the type of vertices and the phase of vertices. [`ZXDiagram`](@ref) is the data structure for representing ZX-diagrams. @@ -11,7 +14,7 @@ In each `ZXDiagram`, there is a `layout` for storing layout information for the As we usually focus on quantum circuits, the recommended way to construct `ZXDiagram`s is by the following function. ```@docs -ZXDiagram(nbit::T) where T<:Integer +ZXDiagram(nbits::T) where T<:Integer ``` Then one can use `push_gate!` to push quantum gates at the end of a quantum circuit, or use `pushfirst_gate!` to push gates at the beginning of a quantum circuit. ```@docs From f873abc010209ff216802b552710168087716c2b Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Sun, 15 Oct 2023 21:50:48 +0800 Subject: [PATCH 07/10] fix docs not building issue --- docs/make.jl | 2 +- docs/src/api.md | 5 +++++ docs/src/tutorials.md | 45 ++++++++++++------------------------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 69b4e4e..950c589 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -6,7 +6,7 @@ using Multigraphs indigo = DocThemeIndigo.install(ZXCalculus) makedocs(; - modules = Module[ZXCalculus], + modules = Module[ZXCalculus, ZXCalculus.ZX, ZXCalculus.ZXW, ZXCalculus.ZW, ZXCalculus.Utils, ZXCalculus.Application, ZXCalculus.PMG], format=Documenter.HTML(; # ... # put your indigo css in assets diff --git a/docs/src/api.md b/docs/src/api.md index 59b8f89..a78f245 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -1 +1,6 @@ # APIs + +```@autodocs +Modules = [ZXCalculus, ZXCalculus.ZX, ZXCalculus.ZXW, ZXCalculus.ZW, ZXCalculus.Utils, ZXCalculus.PMG] +Order = [:function, :type] +``` diff --git a/docs/src/tutorials.md b/docs/src/tutorials.md index db5c480..2d171aa 100644 --- a/docs/src/tutorials.md +++ b/docs/src/tutorials.md @@ -1,9 +1,6 @@ # Tutorials -```@meta -CurrentModule= ZXCalculus.ZX -``` -ZX-diagrams are the basic objects in ZX-calculus. In our implementation, each ZX-diagram consists of a multigraph and vertices information including the type of vertices and the phase of vertices. [`ZXDiagram`](@ref) is the data structure for representing +ZX-diagrams are the basic objects in ZX-calculus. In our implementation, each ZX-diagram consists of a multigraph and vertices information including the type of vertices and the phase of vertices. [`ZXCalculus.ZX.ZXDiagram`](@ref) is the data structure for representing ZX-diagrams. There are 5 types of vertices: `In`, `Out`, `Z`, `X`, `H` which represent the inputs of quantum circuits, outputs of quantum circuits, Z-spiders, X-spiders, H-boxes. There can be a phase for each vertex. The phase of a vertex of `Z` or `X` is the phase of a Z or X-spider. For the other types of vertices, the phase is zero by default. @@ -12,21 +9,15 @@ In each `ZXDiagram`, there is a `layout` for storing layout information for the ## Construction of ZX-diagrams -As we usually focus on quantum circuits, the recommended way to construct `ZXDiagram`s is by the following function. -```@docs -ZXDiagram(nbits::T) where T<:Integer -``` -Then one can use `push_gate!` to push quantum gates at the end of a quantum circuit, or use `pushfirst_gate!` to push gates at the beginning of a quantum circuit. -```@docs -push_gate!(zxd::ZXDiagram{T, P}, ::Val{:Z}, loc::T, phase = zero(P); autoconvert::Bool=true) where {T, P} -pushfirst_gate!(zxd::ZXDiagram{T, P}, ::Val{:Z}, loc::T, phase::P = zero(P)) where {T, P} -``` +As we usually focus on quantum circuits, the recommended way to construct `ZXDiagram`s is by the following function [`ZXCalculus.ZX.ZXDiagram(nbits::T) where {T<:Integer}`](@ref). + +Then one can use [`ZXCalculus.ZX.push_gate!`](@ref) to push quantum gates at the end of a quantum circuit, or use [`ZXCalculus.ZX.pushfirst_gate!`](@ref)to push gates at the beginning of a quantum circuit. For example, in `example\ex1.jl`, one can generate the demo circuit by the function ```julia using ZXCalculus function generate_example() - zxd = ZXDiagram(4) + zxd = ZXCalculus.ZX.ZXDiagram(4) push_gate!(zxd, Val(:Z), 1, 3//2) push_gate!(zxd, Val(:H), 1) push_gate!(zxd, Val(:Z), 1, 1//2) @@ -56,11 +47,7 @@ function generate_example() end ``` -In the paper [arXiv:1902.03178](https://arxiv.org/abs/1902.03178), they introduced a special type of ZX-diagrams, graph-like ZX-diagrams, which consists of Z-spiders with 2 different types of edges only. We use [`ZXGraph`](@ref) for representing this special type of ZX-diagrams. One can convert a `ZXDiagram` into a `ZXGraph` by simply use the construction function: -```@docs -ZXGraph(zxd::ZXDiagram{T, P}) where {T, P} -``` - +In the paper [arXiv:1902.03178](https://arxiv.org/abs/1902.03178), they introduced a special type of ZX-diagrams, graph-like ZX-diagrams, which consists of Z-spiders with 2 different types of edges only. We use [`ZXCalculus.ZX.ZXGraph`](@ref) for representing this special type of ZX-diagrams. One can convert a `ZXDiagram` into a `ZXGraph` by simply use the construction function [`ZXCalculus.ZX.ZXGraph(zxd::ZXCalculus.ZX.ZXDiagram{T, P}) where {T, P}`](@ref): ## Visualization @@ -78,18 +65,12 @@ With `ZXCalculus.jl`, one can manipulate ZX-diagrams at different levels. - Rewriting ZX-diagrams with rules - Rewriting ZX-diagrams at the graphical level -The highest level is the circuit simplification algorithms. By now there are two algorithms are available: -```@docs -clifford_simplification(circ::ZXDiagram) -phase_teleportation(circ::ZXDiagram{T, P}) where {T, P} -``` +The highest level is the circuit simplification algorithms. By now there are two algorithms are available: [`ZXCalculus.ZX.clifford_simplification`](@ref) and [`ZXCalculus.ZX.phase_teleportation`](ref). + The input of these algorithms will be a ZX-diagram representing a quantum circuit. And these algorithms will return a ZX-diagram of a simplified quantum circuit. For more details, please refer to [Clifford simplification](https://arxiv.org/abs/1902.03178) and [phase teleportation](https://arxiv.org/abs/1903.10477). -One can rewrite ZX-diagrams with rules. In `ZXCalculus.jl`, rules are identified as data structures [`Rule`](@ref). And we can use the following functions to simplify ZX-diagrams: -```@docs -simplify!(r::ZXCalculus.AbstractRule, zxd::AbstractZXDiagram) -replace!(r::ZXCalculus.AbstractRule, zxd::AbstractZXDiagram) -``` +One can rewrite ZX-diagrams with rules. In `ZXCalculus.jl`, rules are identified as data structures [`Rule`](@ref). And we can use the following functions to simplify ZX-diagrams: [`ZXCalculus.ZX.simplify!`](@ref) and [`ZXCalculus.ZX.replace!`](@ref). + For example, in `example/ex1.jl`, we can get a simplified graph-like ZX-diagram by: ```julia zxd = generate_example() @@ -102,10 +83,8 @@ replace!(Rule{:pab}(), zxg) The difference between `simplify!` and `replace!` is that `replace!` only matches vertices and tries to rewrite with all matched vertices once, while `simplify!` will keep matching until nothing matched. The following APIs are useful for more detailed rewriting. -```@docs -match(::ZXCalculus.AbstractRule, zxd::AbstractZXDiagram{T, P}) where {T, P} -rewrite!(r::ZXCalculus.AbstractRule, zxd::AbstractZXDiagram{T, P}, matches::Vector{Match{T}}) where {T, P} -``` +1. [`ZXCalculus.ZX.match`](@ref) +2. [`ZXCalculus.ZX.rewrite!`](@ref) The lowest level for rewriting ZX-diagrams is manipulating the multigraphs directly. This way is not recommended unless one wants to develop new rules in ZX-calculus. From 9e3388a0a6605518e795bf1b5247d4311869aa3e Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Tue, 17 Oct 2023 18:40:11 +0800 Subject: [PATCH 08/10] restructure module folders --- src/Application/Application.jl | 9 ++ src/{ => Application}/to_eincode.jl | 0 src/PMG/PMG.jl | 12 +++ src/{ => PMG}/planar_multigraph.jl | 0 src/Utils/Utils.jl | 10 ++ src/{ => Utils}/parameter.jl | 0 src/{ => Utils}/phase.jl | 0 src/{ => Utils}/scalar.jl | 0 src/ZW/ZW.jl | 43 +++++++++ src/{ => ZW}/zw_adt.jl | 0 src/{ => ZW}/zw_diagram.jl | 0 src/{ => ZW}/zw_utils.jl | 0 src/ZX/ZX.jl | 38 ++++++++ src/{ => ZX}/abstract_zx_diagram.jl | 0 src/{ => ZX}/circuit_extraction.jl | 0 src/{ => ZX}/ir.jl | 0 src/{ => ZX}/phase_teleportation.jl | 0 src/{ => ZX}/rules.jl | 0 src/{ => ZX}/simplify.jl | 0 src/{ => ZX}/zx_diagram.jl | 0 src/{ => ZX}/zx_graph.jl | 0 src/{ => ZX}/zx_layout.jl | 0 src/ZXCalculus.jl | 144 ++-------------------------- src/ZXW/ZXW.jl | 19 ++++ src/{ => ZXW}/adts.jl | 0 src/{ => ZXW}/utils.jl | 0 src/{ => ZXW}/zxw_diagram.jl | 0 src/{ => ZXW}/zxw_rules.jl | 0 28 files changed, 138 insertions(+), 137 deletions(-) create mode 100644 src/Application/Application.jl rename src/{ => Application}/to_eincode.jl (100%) create mode 100644 src/PMG/PMG.jl rename src/{ => PMG}/planar_multigraph.jl (100%) create mode 100644 src/Utils/Utils.jl rename src/{ => Utils}/parameter.jl (100%) rename src/{ => Utils}/phase.jl (100%) rename src/{ => Utils}/scalar.jl (100%) create mode 100644 src/ZW/ZW.jl rename src/{ => ZW}/zw_adt.jl (100%) rename src/{ => ZW}/zw_diagram.jl (100%) rename src/{ => ZW}/zw_utils.jl (100%) create mode 100644 src/ZX/ZX.jl rename src/{ => ZX}/abstract_zx_diagram.jl (100%) rename src/{ => ZX}/circuit_extraction.jl (100%) rename src/{ => ZX}/ir.jl (100%) rename src/{ => ZX}/phase_teleportation.jl (100%) rename src/{ => ZX}/rules.jl (100%) rename src/{ => ZX}/simplify.jl (100%) rename src/{ => ZX}/zx_diagram.jl (100%) rename src/{ => ZX}/zx_graph.jl (100%) rename src/{ => ZX}/zx_layout.jl (100%) create mode 100644 src/ZXW/ZXW.jl rename src/{ => ZXW}/adts.jl (100%) rename src/{ => ZXW}/utils.jl (100%) rename src/{ => ZXW}/zxw_diagram.jl (100%) rename src/{ => ZXW}/zxw_rules.jl (100%) diff --git a/src/Application/Application.jl b/src/Application/Application.jl new file mode 100644 index 0000000..ef214fe --- /dev/null +++ b/src/Application/Application.jl @@ -0,0 +1,9 @@ +module Application + +using OMEinsum, MLStyle +using ..ZXW: ZXWDiagram, Z, X, W, H, D, Input, Output +using ..Utils: PiUnit, Factor, Parameter, unwrap_scalar +using ..ZXW: get_outputs, get_inputs, degree, neighbors, vertices, scalar, nin, nout + +include("to_eincode.jl") +end # module Application diff --git a/src/to_eincode.jl b/src/Application/to_eincode.jl similarity index 100% rename from src/to_eincode.jl rename to src/Application/to_eincode.jl diff --git a/src/PMG/PMG.jl b/src/PMG/PMG.jl new file mode 100644 index 0000000..7e17e2c --- /dev/null +++ b/src/PMG/PMG.jl @@ -0,0 +1,12 @@ +module PMG + +using Graphs + +import Graphs: AbstractEdge, src, dst, nv, ne, neighbors +import Graphs.SimpleGraphs: vertices + +export HalfEdge, src, dst, new_edge, PlanarMultigraph + +include("planar_multigraph.jl") + +end # module PlanarMultigraph diff --git a/src/planar_multigraph.jl b/src/PMG/planar_multigraph.jl similarity index 100% rename from src/planar_multigraph.jl rename to src/PMG/planar_multigraph.jl diff --git a/src/Utils/Utils.jl b/src/Utils/Utils.jl new file mode 100644 index 0000000..5d66c23 --- /dev/null +++ b/src/Utils/Utils.jl @@ -0,0 +1,10 @@ +module Utils + +using Expronicon.ADT: @const_use, @adt +using MLStyle + +include("scalar.jl") +include("phase.jl") +include("parameter.jl") + +end diff --git a/src/parameter.jl b/src/Utils/parameter.jl similarity index 100% rename from src/parameter.jl rename to src/Utils/parameter.jl diff --git a/src/phase.jl b/src/Utils/phase.jl similarity index 100% rename from src/phase.jl rename to src/Utils/phase.jl diff --git a/src/scalar.jl b/src/Utils/scalar.jl similarity index 100% rename from src/scalar.jl rename to src/Utils/scalar.jl diff --git a/src/ZW/ZW.jl b/src/ZW/ZW.jl new file mode 100644 index 0000000..396f556 --- /dev/null +++ b/src/ZW/ZW.jl @@ -0,0 +1,43 @@ +module ZW +using Expronicon.ADT: @adt, @const_use +using MLStyle, Graphs +using ..ZXW: _round_phase, Parameter + +# these will be changed to using PlanarMultigraph: vertices after we split out package +using ..PMG: + 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 ..Utils: add_phase!, Scalar, Phase, Parameter, PiUnit, Factor, add_power! +using ..PMG: PlanarMultigraph, HalfEdge, new_edge, src, dst +import ..Utils: add_power! +import ..ZX: add_global_phase!, scalar, spiders, rem_spider! +import Graphs.rem_edge! + +export ZWDiagram + +include("zw_adt.jl") +include("zw_diagram.jl") +include("zw_utils.jl") +end # module ZW diff --git a/src/zw_adt.jl b/src/ZW/zw_adt.jl similarity index 100% rename from src/zw_adt.jl rename to src/ZW/zw_adt.jl diff --git a/src/zw_diagram.jl b/src/ZW/zw_diagram.jl similarity index 100% rename from src/zw_diagram.jl rename to src/ZW/zw_diagram.jl diff --git a/src/zw_utils.jl b/src/ZW/zw_utils.jl similarity index 100% rename from src/zw_utils.jl rename to src/ZW/zw_utils.jl diff --git a/src/ZX/ZX.jl b/src/ZX/ZX.jl new file mode 100644 index 0000000..f05e9dd --- /dev/null +++ b/src/ZX/ZX.jl @@ -0,0 +1,38 @@ +module ZX + +using Graphs, Multigraphs, YaoHIR, YaoLocations +using YaoHIR.IntrinsicOperation +using YaoHIR: Chain +using YaoLocations: plain +using MLStyle +using ..Utils: Scalar, Phase, add_phase! + +import ..Utils: add_power! + +export spiders, + tcount, spider_type, phase, rem_spider!, rem_spiders!, pushfirst_gate!, push_gate! + +export SpiderType, EdgeType +export AbstractZXDiagram, ZXDiagram, ZXGraph + +export AbstractRule +export Rule, Match + +export rewrite!, simplify! + +export convert_to_chain, convert_to_zxd +export clifford_simplification, full_reduction, circuit_extraction, phase_teleportation + +include("abstract_zx_diagram.jl") +include("zx_layout.jl") +include("zx_diagram.jl") +include("zx_graph.jl") + +include("rules.jl") +include("simplify.jl") + +include("circuit_extraction.jl") +include("phase_teleportation.jl") + +include("ir.jl") +end diff --git a/src/abstract_zx_diagram.jl b/src/ZX/abstract_zx_diagram.jl similarity index 100% rename from src/abstract_zx_diagram.jl rename to src/ZX/abstract_zx_diagram.jl diff --git a/src/circuit_extraction.jl b/src/ZX/circuit_extraction.jl similarity index 100% rename from src/circuit_extraction.jl rename to src/ZX/circuit_extraction.jl diff --git a/src/ir.jl b/src/ZX/ir.jl similarity index 100% rename from src/ir.jl rename to src/ZX/ir.jl diff --git a/src/phase_teleportation.jl b/src/ZX/phase_teleportation.jl similarity index 100% rename from src/phase_teleportation.jl rename to src/ZX/phase_teleportation.jl diff --git a/src/rules.jl b/src/ZX/rules.jl similarity index 100% rename from src/rules.jl rename to src/ZX/rules.jl diff --git a/src/simplify.jl b/src/ZX/simplify.jl similarity index 100% rename from src/simplify.jl rename to src/ZX/simplify.jl diff --git a/src/zx_diagram.jl b/src/ZX/zx_diagram.jl similarity index 100% rename from src/zx_diagram.jl rename to src/ZX/zx_diagram.jl diff --git a/src/zx_graph.jl b/src/ZX/zx_graph.jl similarity index 100% rename from src/zx_graph.jl rename to src/ZX/zx_graph.jl diff --git a/src/zx_layout.jl b/src/ZX/zx_layout.jl similarity index 100% rename from src/zx_layout.jl rename to src/ZX/zx_layout.jl diff --git a/src/ZXCalculus.jl b/src/ZXCalculus.jl index 8bb1ca0..ca64307 100644 --- a/src/ZXCalculus.jl +++ b/src/ZXCalculus.jl @@ -1,141 +1,11 @@ module ZXCalculus -module Utils - -using Expronicon.ADT: @const_use, @adt -using MLStyle - -include("scalar.jl") -include("phase.jl") -include("parameter.jl") - -end - -module ZX - -using Graphs, Multigraphs, YaoHIR, YaoLocations -using YaoHIR.IntrinsicOperation -using YaoHIR: Chain -using YaoLocations: plain -using MLStyle -using ..Utils: Scalar, Phase, add_phase! - -import ..Utils: add_power! - -export spiders, - tcount, spider_type, phase, rem_spider!, rem_spiders!, pushfirst_gate!, push_gate! - -export SpiderType, EdgeType -export AbstractZXDiagram, ZXDiagram, ZXGraph - -export AbstractRule -export Rule, Match - -export rewrite!, simplify! - -export convert_to_chain, convert_to_zxd -export clifford_simplification, full_reduction, circuit_extraction, phase_teleportation - -include("abstract_zx_diagram.jl") -include("zx_layout.jl") -include("zx_diagram.jl") -include("zx_graph.jl") - -include("rules.jl") -include("simplify.jl") - -include("circuit_extraction.jl") -include("phase_teleportation.jl") - -include("ir.jl") -end - -module ZXW - -using Expronicon.ADT: @const_use, @adt -using MLStyle, Multigraphs, Graphs -using ..Utils: Scalar, Phase, Parameter, PiUnit, Factor, add_phase! -using ..ZX: safe_convert, AbstractRule, Rule, Match - -import ..Utils: add_power! -import ..ZX: - rewrite!, simplify!, push_gate!, pushfirst_gate!, spiders, rem_spider!, rem_spiders! - -export ZXWDiagram, substitute_variables! - -include("adts.jl") -include("zxw_diagram.jl") -include("zxw_rules.jl") -include("utils.jl") - -end # module ZXW - -module PMG - -using Graphs - -import Graphs: AbstractEdge, src, dst, nv, ne, neighbors -import Graphs.SimpleGraphs: vertices - -export HalfEdge, src, dst, new_edge, PlanarMultigraph - -include("planar_multigraph.jl") - -end # module PlanarMultigraph - -module ZW -using Expronicon.ADT: @adt, @const_use -using MLStyle, Graphs -using ..ZXW: _round_phase, Parameter - -# these will be changed to using PlanarMultigraph: vertices after we split out package -using ..PMG: - 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 ..Utils: add_phase!, Scalar, Phase, Parameter, PiUnit, Factor, add_power! -using ..PMG: PlanarMultigraph, HalfEdge, new_edge, src, dst -import ..Utils: add_power! -import ..ZX: add_global_phase!, scalar, spiders, rem_spider! -import Graphs.rem_edge! - -export ZWDiagram - -include("zw_adt.jl") -include("zw_diagram.jl") -include("zw_utils.jl") -end # module ZW - -module Application - -using OMEinsum, MLStyle -using ..ZXW: ZXWDiagram, Z, X, W, H, D, Input, Output -using ..Utils: PiUnit, Factor, Parameter, unwrap_scalar -using ..ZXW: get_outputs, get_inputs, degree, neighbors, vertices, scalar, nin, nout - -include("to_eincode.jl") -end # module Application - +include("Utils/Utils.jl") +include("ZX/ZX.jl") +include("ZXW/ZXW.jl") +include("PMG/PMG.jl") +include("ZW/ZW.jl") +include("Application/Application.jl") include("deprecations.jl") + end # module diff --git a/src/ZXW/ZXW.jl b/src/ZXW/ZXW.jl new file mode 100644 index 0000000..fd0e220 --- /dev/null +++ b/src/ZXW/ZXW.jl @@ -0,0 +1,19 @@ +module ZXW + +using Expronicon.ADT: @const_use, @adt +using MLStyle, Multigraphs, Graphs +using ..Utils: Scalar, Phase, Parameter, PiUnit, Factor, add_phase! +using ..ZX: safe_convert, AbstractRule, Rule, Match + +import ..Utils: add_power! +import ..ZX: + rewrite!, simplify!, push_gate!, pushfirst_gate!, spiders, rem_spider!, rem_spiders! + +export ZXWDiagram, substitute_variables! + +include("adts.jl") +include("zxw_diagram.jl") +include("zxw_rules.jl") +include("utils.jl") + +end # module ZXW diff --git a/src/adts.jl b/src/ZXW/adts.jl similarity index 100% rename from src/adts.jl rename to src/ZXW/adts.jl diff --git a/src/utils.jl b/src/ZXW/utils.jl similarity index 100% rename from src/utils.jl rename to src/ZXW/utils.jl diff --git a/src/zxw_diagram.jl b/src/ZXW/zxw_diagram.jl similarity index 100% rename from src/zxw_diagram.jl rename to src/ZXW/zxw_diagram.jl diff --git a/src/zxw_rules.jl b/src/ZXW/zxw_rules.jl similarity index 100% rename from src/zxw_rules.jl rename to src/ZXW/zxw_rules.jl From 0409ae9f4677de8712756cdb7b7e5f0284a18899 Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Fri, 20 Oct 2023 21:27:00 +0800 Subject: [PATCH 09/10] add usings to each test file --- test/abstract_zx_diagram.jl | 4 +- test/ancilla_extraction.jl | 3 + test/challenge.jl | 4 +- test/circuit_extraction.jl | 4 +- test/parameter.jl | 1 + test/phase.jl | 1 + test/phase_teleportation.jl | 1 + test/planar_multigraph.jl | 1 + test/rules.jl | 162 +++++++++++++++++++++++++++--------- test/runtests.jl | 19 +---- test/scalar.jl | 1 + test/simplify.jl | 5 ++ test/to_eincode.jl | 3 +- test/utils.jl | 11 ++- test/zw_diagram.jl | 2 + test/zw_utils.jl | 3 +- test/zx_diagram.jl | 32 +++---- test/zx_graph.jl | 4 + test/zxw_diagram.jl | 3 + test/zxw_rules.jl | 1 + 20 files changed, 184 insertions(+), 81 deletions(-) diff --git a/test/abstract_zx_diagram.jl b/test/abstract_zx_diagram.jl index 74444bc..c7ce697 100644 --- a/test/abstract_zx_diagram.jl +++ b/test/abstract_zx_diagram.jl @@ -1,6 +1,8 @@ -using ZXCalculus.ZX +using Test, Graphs, ZXCalculus, ZXCalculus.ZX using ZXCalculus.Utils: Phase +import ZXCalculus.ZX as ZX + struct TestZXDiagram{T,P} <: AbstractZXDiagram{T,P} end test_zxd = TestZXDiagram{Int,Phase}(); diff --git a/test/ancilla_extraction.jl b/test/ancilla_extraction.jl index c416392..4c860ce 100644 --- a/test/ancilla_extraction.jl +++ b/test/ancilla_extraction.jl @@ -1,5 +1,8 @@ +using Test, ZXCalculus, ZXCalculus.ZX using ZXCalculus.ZX: ancilla_extraction +import ZXCalculus.ZX as ZX + function gen_phase_gadget() zxd = ZXDiagram(2) push_gate!(zxd, Val(:Z), 1, 1//2) diff --git a/test/challenge.jl b/test/challenge.jl index a2097f0..443244c 100644 --- a/test/challenge.jl +++ b/test/challenge.jl @@ -1,6 +1,9 @@ +using Test, ZXCalculus, Graphs, ZXCalculus.ZX using ZXCalculus.ZX: SpiderType, EdgeType using ZXCalculus.Utils: Phase +import ZXCalculus.ZX as ZX + st = Dict( 0+1 => SpiderType.In, 1+1 => SpiderType.In, @@ -192,7 +195,6 @@ es = Dict( (46+1, 47+1) => EdgeType.HAD, ) -using Graphs zxg = ZXGraph(ZXDiagram(0)) vs = 1:52 for v in vs diff --git a/test/circuit_extraction.jl b/test/circuit_extraction.jl index 4ec2fcd..0c83041 100644 --- a/test/circuit_extraction.jl +++ b/test/circuit_extraction.jl @@ -1,3 +1,5 @@ +using Test, Multigraphs, ZXCalculus, ZXCalculus.ZX, ZXCalculus.Utils, Graphs + zxd = ZXDiagram(4) push_gate!(zxd, Val{:Z}(), 1, 3//2) push_gate!(zxd, Val{:H}(), 1) @@ -35,4 +37,4 @@ zxg2 = clifford_simplification(zxd) @test ne(zxg2) <= ne(zxg) zxg3 = full_reduction(zxd) -cir = circuit_extraction(zxg3) \ No newline at end of file +cir = circuit_extraction(zxg3) diff --git a/test/parameter.jl b/test/parameter.jl index 324123d..1f87d7b 100644 --- a/test/parameter.jl +++ b/test/parameter.jl @@ -1,4 +1,5 @@ using Base: CodegenParams +using Test, ZXCalculus using ZXCalculus.Utils: Parameter @testset "Constructor" begin diff --git a/test/phase.jl b/test/phase.jl index c5d1a72..b5865a0 100644 --- a/test/phase.jl +++ b/test/phase.jl @@ -1,3 +1,4 @@ +using Test using ZXCalculus.Utils: Phase # ir = @make_ircode begin diff --git a/test/phase_teleportation.jl b/test/phase_teleportation.jl index eb9eef7..bf350e6 100644 --- a/test/phase_teleportation.jl +++ b/test/phase_teleportation.jl @@ -1,3 +1,4 @@ +using Test, ZXCalculus, ZXCalculus.ZX function gen_cir() cir = ZXDiagram(5) diff --git a/test/planar_multigraph.jl b/test/planar_multigraph.jl index 4219308..3ae5fd2 100644 --- a/test/planar_multigraph.jl +++ b/test/planar_multigraph.jl @@ -1,3 +1,4 @@ +using Test, ZXCalculus, ZXCalculus.PMG using ZXCalculus.PMG: create_vertex!, create_edge!, diff --git a/test/rules.jl b/test/rules.jl index 0747948..96b7932 100644 --- a/test/rules.jl +++ b/test/rules.jl @@ -1,16 +1,20 @@ +using Test, ZXCalculus, Multigraphs, ZXCalculus.ZX, ZXCalculus.Utils, Graphs + +import ZXCalculus.ZX as ZX + g = Multigraph([0 2 0; 2 0 1; 0 1 0]) collect(edges(g)) -ps = [i//4 for i = 1:3] +ps = [i // 4 for i = 1:3] v_t = [SpiderType.Z, SpiderType.Z, SpiderType.X] zxd = ZXDiagram(g, v_t, ps) matches = match(Rule{:f}(), zxd) rewrite!(Rule{:f}(), zxd, matches) @test sort!(spiders(zxd)) == [1, 3] -@test phase(zxd, 1) == phase(zxd, 3) == 3//4 +@test phase(zxd, 1) == phase(zxd, 3) == 3 // 4 g = Multigraph(path_graph(5)) add_edge!(g, 1, 2) -ps = [1, 0//1, 0, 0, 1] +ps = [1, 0 // 1, 0, 0, 1] v_t = [SpiderType.X, SpiderType.X, SpiderType.Z, SpiderType.Z, SpiderType.Z] zxd = ZXDiagram(g, v_t, ps) matches = match(Rule{:i1}(), zxd) @@ -18,7 +22,7 @@ rewrite!(Rule{:i1}(), zxd, matches) @test nv(zxd) == 3 && ne(zxd, count_mul = true) == 3 && ne(zxd) == 2 g = Multigraph([0 2 0; 2 0 1; 0 1 0]) -ps = [i//4 for i = 1:3] +ps = [i // 4 for i = 1:3] v_t = [SpiderType.X, SpiderType.X, SpiderType.Z] zxd = ZXDiagram(g, v_t, ps) matches = match(Rule{:h}(), zxd) @@ -35,35 +39,42 @@ 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] +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) matches = match(Rule{:pi}(), zxd) rewrite!(Rule{:pi}(), zxd, matches) @test nv(zxd) == 8 && ne(zxd) == 7 -@test zxd.scalar == Scalar(0, 1//2) +@test zxd.scalar == Scalar(0, 1 // 2) g = Multigraph([0 2 0; 2 0 1; 0 1 0]) -ps = [1, 1//2, 0] +ps = [1, 1 // 2, 0] v_t = [SpiderType.X, SpiderType.Z, SpiderType.In] zxd = ZXDiagram(g, v_t, ps) matches = match(Rule{:pi}(), zxd) rewrite!(Rule{:pi}(), zxd, matches) @test nv(zxd) == 4 && ne(zxd) == 3 && ne(zxd, count_mul = true) == 4 -@test zxd.scalar == Scalar(0, 1//2) +@test zxd.scalar == Scalar(0, 1 // 2) g = Multigraph(5) add_edge!(g, 1, 2) add_edge!(g, 2, 3, 2) add_edge!(g, 2, 4) add_edge!(g, 2, 5) -ps = [0, 1//2, 0, 0, 0] +ps = [0, 1 // 2, 0, 0, 0] v_t = [SpiderType.X, SpiderType.Z, SpiderType.Out, SpiderType.Out, SpiderType.Out] zxd = ZXDiagram(g, v_t, ps) matches = match(Rule{:c}(), zxd) rewrite!(Rule{:c}(), zxd, matches) @test nv(zxd) == 7 && ne(zxd) == 4 -@test zxd.scalar == Scalar(-3, 0//1) +@test zxd.scalar == Scalar(-3, 0 // 1) g = Multigraph(6) add_edge!(g, 1, 3) @@ -71,53 +82,97 @@ add_edge!(g, 2, 4) add_edge!(g, 3, 4) add_edge!(g, 3, 5) add_edge!(g, 4, 6) -ps = [0//1 for i = 1:6] -v_t = [SpiderType.In, SpiderType.In, SpiderType.X, SpiderType.Z, SpiderType.Out, SpiderType.Out] -layout = ZXCalculus.ZX.ZXLayout(2, Dict(zip(1:6, [1//1, 2, 1, 2, 1, 2])), Dict(zip(1:6, [1//1, 1, 2, 2, 3, 3]))) +ps = [0 // 1 for i = 1:6] +v_t = [ + SpiderType.In, + SpiderType.In, + SpiderType.X, + SpiderType.Z, + SpiderType.Out, + SpiderType.Out, +] +layout = ZXCalculus.ZX.ZXLayout( + 2, + Dict(zip(1:6, [1 // 1, 2, 1, 2, 1, 2])), + Dict(zip(1:6, [1 // 1, 1, 2, 2, 3, 3])), +) zxd = ZXDiagram(g, v_t, ps, layout) matches = match(Rule{:b}(), zxd) rewrite!(Rule{:b}(), zxd, matches) @test nv(zxd) == 8 && ne(zxd) == 8 -@test zxd.scalar == Scalar(1, 0//1) +@test zxd.scalar == Scalar(1, 0 // 1) g = Multigraph(9) -for e in [[2,6],[3,7],[4,8],[5,9]] +for e in [[2, 6], [3, 7], [4, 8], [5, 9]] add_edge!(g, e[1], e[2]) end -ps = [1//2, 0, 1//4, 1//2, 3//4, 0, 0, 0, 0] -st = [SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.In, SpiderType.In, SpiderType.Out, SpiderType.Out] +ps = [1 // 2, 0, 1 // 4, 1 // 2, 3 // 4, 0, 0, 0, 0] +st = [ + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.In, + SpiderType.In, + SpiderType.Out, + SpiderType.Out, +] zxg = ZXGraph(ZXDiagram(g, st, ps)) -for e in [[1,2],[1,3],[1,4],[1,5],[2,3]] +for e in [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3]] add_edge!(zxg, e[1], e[2]) end replace!(Rule{:lc}(), zxg) @test !has_edge(zxg, 2, 3) && ne(zxg) == 9 -@test phase(zxg, 2) == 3//2 && phase(zxg, 3) == 7//4 && phase(zxg, 4) == 0//1 && phase(zxg, 5) == 1//4 +@test phase(zxg, 2) == 3 // 2 && + phase(zxg, 3) == 7 // 4 && + phase(zxg, 4) == 0 // 1 && + phase(zxg, 5) == 1 // 4 g = Multigraph(14) -for e in [[3,9],[4,10],[5,11],[6,12],[7,13],[8,14]] +for e in [[3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14]] add_edge!(g, e[1], e[2]) end -ps = [1//1, 0, 1//4, 1//2, 3//4, 1, 5//4, 3//2, 0, 0, 0, 0, 0, 0] -st = [SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.In, SpiderType.Out, SpiderType.In, SpiderType.Out, SpiderType.In, SpiderType.Out] +ps = [1 // 1, 0, 1 // 4, 1 // 2, 3 // 4, 1, 5 // 4, 3 // 2, 0, 0, 0, 0, 0, 0] +st = [ + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.In, + SpiderType.Out, + SpiderType.In, + SpiderType.Out, + SpiderType.In, + SpiderType.Out, +] zxg = ZXGraph(ZXDiagram(g, st, ps)) -for e in [[1,2],[1,3],[1,4],[1,5],[1,6],[2,5],[2,6],[2,7],[2,8]] +for e in [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 5], [2, 6], [2, 7], [2, 8]] add_edge!(zxg, e[1], e[2]) end replace!(Rule{:p1}(), zxg) @test !has_edge(zxg, 3, 4) && !has_edge(zxg, 5, 6) && !has_edge(zxg, 7, 8) @test nv(zxg) == 12 && ne(zxg) == 18 -@test phase(zxg, 3) == 1//4 && phase(zxg, 4) == 1//2 && phase(zxg, 5) == 3//4 && phase(zxg, 6) == 1//1 && phase(zxg, 7) == 1//4 && phase(zxg, 8) == 1//2 +@test phase(zxg, 3) == 1 // 4 && + phase(zxg, 4) == 1 // 2 && + phase(zxg, 5) == 3 // 4 && + phase(zxg, 6) == 1 // 1 && + phase(zxg, 7) == 1 // 4 && + phase(zxg, 8) == 1 // 2 g = Multigraph(6) -for e in [[2,6]] +for e in [[2, 6]] add_edge!(g, e[1], e[2]) end -ps = [1//1, 1//4, 1//2, 3//4, 1, 0] +ps = [1 // 1, 1 // 4, 1 // 2, 3 // 4, 1, 0] st = [SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.In] zxg = ZXGraph(ZXDiagram(g, st, ps)) -for e in [[1,2],[2,3],[1,4],[1,5]] +for e in [[1, 2], [2, 3], [1, 4], [1, 5]] add_edge!(zxg, e[1], e[2]) end @@ -126,15 +181,28 @@ replace!(Rule{:pab}(), zxg) @test nv(zxg) == 7 && ne(zxg) == 6 g = Multigraph(14) -for e in [[3,9],[4,10],[5,11],[6,12],[7,13],[8,14]] +for e in [[3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14]] add_edge!(g, e[1], e[2]) end -ps = [1//1, 1//4, 1//4, 1//2, 3//4, 1, 5//4, 3//2, 0, 0, 0, 0, 0, 0] -st = [SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, - SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.In, SpiderType.Out, - SpiderType.In, SpiderType.Out, SpiderType.In, SpiderType.Out] +ps = [1 // 1, 1 // 4, 1 // 4, 1 // 2, 3 // 4, 1, 5 // 4, 3 // 2, 0, 0, 0, 0, 0, 0] +st = [ + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.In, + SpiderType.Out, + SpiderType.In, + SpiderType.Out, + SpiderType.In, + SpiderType.Out, +] zxg = ZXGraph(ZXDiagram(g, st, ps)) -for e in [[1,2],[1,3],[1,4],[1,5],[1,6],[2,5],[2,6],[2,7],[2,8]] +for e in [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 5], [2, 6], [2, 7], [2, 8]] add_edge!(zxg, e[1], e[2]) end match(Rule{:p2}(), zxg) @@ -142,15 +210,29 @@ replace!(Rule{:p2}(), zxg) @test zxg.phase_ids[15] == (2, -1) g = Multigraph(15) -for e in [[3,9],[4,10],[5,11],[6,12],[7,13],[8,14],[2,15]] +for e in [[3, 9], [4, 10], [5, 11], [6, 12], [7, 13], [8, 14], [2, 15]] add_edge!(g, e[1], e[2]) end -ps = [1//1, 1//4, 1//2, 1//2, 3//2, 1, 1//2, 3//2, 0, 0, 0, 0, 0, 0, 0, 0] -st = [SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.Z, - SpiderType.Z, SpiderType.Z, SpiderType.Z, SpiderType.In, SpiderType.Out, - SpiderType.In, SpiderType.Out, SpiderType.In, SpiderType.Out, SpiderType.Out] +ps = [1 // 1, 1 // 4, 1 // 2, 1 // 2, 3 // 2, 1, 1 // 2, 3 // 2, 0, 0, 0, 0, 0, 0, 0, 0] +st = [ + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.Z, + SpiderType.In, + SpiderType.Out, + SpiderType.In, + SpiderType.Out, + SpiderType.In, + SpiderType.Out, + SpiderType.Out, +] zxg = ZXGraph(ZXDiagram(g, st, ps)) -for e in [[1,2],[1,3],[1,4],[1,5],[1,6],[2,5],[2,6],[2,7],[2,8]] +for e in [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 5], [2, 6], [2, 7], [2, 8]] add_edge!(zxg, e[1], e[2]) end replace!(Rule{:p3}(), zxg) diff --git a/test/runtests.jl b/test/runtests.jl index 1be432d..13f992f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,21 +1,4 @@ -using ZXCalculus, - Graphs, - Multigraphs, - SparseArrays, - ZXCalculus.Utils, - ZXCalculus.ZX, - ZXCalculus.ZXW, - ZXCalculus.PMG, - ZXCalculus.Application, - ZXCalculus.ZW - -import ZXCalculus.ZX as ZX -import ZXCalculus.ZXW as ZXW -import ZXCalculus.ZW as ZW - -using YaoHIR: Chain -using Documenter -using Test +using ZXCalculus, Documenter, Test @testset "abstract_zx_diagram.jl" begin include("abstract_zx_diagram.jl") diff --git a/test/scalar.jl b/test/scalar.jl index 0d1236d..da896f6 100644 --- a/test/scalar.jl +++ b/test/scalar.jl @@ -1,3 +1,4 @@ +using Test using ZXCalculus.Utils: Scalar, add_power!, add_phase! s = Scalar() diff --git a/test/simplify.jl b/test/simplify.jl index d9072f8..8f2cf45 100644 --- a/test/simplify.jl +++ b/test/simplify.jl @@ -1,3 +1,8 @@ +using Test, ZXCalculus, ZXCalculus.ZX +using YaoHIR: Chain + +import ZXCalculus.ZX as ZX + chain_swap = Chain() push_gate!(chain_swap, Val(:SWAP), 1, 3) diff --git a/test/to_eincode.jl b/test/to_eincode.jl index fc0c94a..6a6f2ed 100644 --- a/test/to_eincode.jl +++ b/test/to_eincode.jl @@ -1,7 +1,8 @@ +using Test, ZXCalculus, LinearAlgebra, ZXCalculus.Utils, ZXCalculus.ZXW using ZXCalculus.Application: z_tensor, x_tensor, w_tensor, h_tensor, d_tensor +using ZXCalculus.Utils: Parameter using ZXCalculus.ZXW: push_gate! -using LinearAlgebra @testset "Tensors" begin @test z_tensor(2, Parameter(Val(:PiUnit), 1 // 2)) == [1 0; 0 exp(im * π / 2)] diff --git a/test/utils.jl b/test/utils.jl index d9444c1..966673f 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -1,3 +1,4 @@ +using Test, ZXCalculus, ZXCalculus.ZXW, ZXCalculus.Utils, Multigraphs, Graphs using ZXCalculus.ZXW: Parameter, _round_phase, @@ -9,12 +10,16 @@ using ZXCalculus.ZXW: expval_circ!, substitute_variables!, rem_spiders!, - add_inout! - - + add_inout!, + Z, + X, + W, + H using MLStyle: @match +import ZXCalculus.ZXW as ZXW + @testset "Phase rounding" begin st = Dict( 1 => Z(Parameter(Val(:PiUnit), -1)), diff --git a/test/zw_diagram.jl b/test/zw_diagram.jl index 436a29b..36b049c 100644 --- a/test/zw_diagram.jl +++ b/test/zw_diagram.jl @@ -1,3 +1,5 @@ +using Test, ZXCalculus, ZXCalculus.ZW, ZXCalculus.PMG, ZXCalculus.Utils + @testset "ZWDiagrm Creation" begin zx1 = ZWDiagram(1) pmg1 = PlanarMultigraph( diff --git a/test/zw_utils.jl b/test/zw_utils.jl index dbc02e1..f24537d 100644 --- a/test/zw_utils.jl +++ b/test/zw_utils.jl @@ -1,3 +1,4 @@ +using Test, ZXCalculus, ZXCalculus.ZW, ZXCalculus.Utils, ZXCalculus.PMG using ZXCalculus.ZW: ZWSpiderType, set_phase!, @@ -62,8 +63,6 @@ using ZXCalculus.Utils: Parameter sc = scalar(zw) @test sc == Scalar{Rational}(2, 1 // 2) - # TODO - # set_phase! end @testset "Add and Rem Spiders" begin diff --git a/test/zx_diagram.jl b/test/zx_diagram.jl index 3e74013..1ac3a78 100644 --- a/test/zx_diagram.jl +++ b/test/zx_diagram.jl @@ -1,8 +1,11 @@ +using Test, ZXCalculus, Multigraphs, Graphs, ZXCalculus.ZX +import ZXCalculus.ZX as ZX + g = Multigraph([0 1 0; 1 0 1; 0 1 0]) -ps = [Rational(0) for i = 1:3] +ps = [Rational(0) for i ∈ 1:3] v_t = [SpiderType.X, SpiderType.Z, SpiderType.X] zxd = ZXDiagram(g, v_t, ps) -zxd2 = ZXDiagram(g, Dict(zip(1:3,v_t)), Dict(zip(1:3,ps))) +zxd2 = ZXDiagram(g, Dict(zip(1:3, v_t)), Dict(zip(1:3, ps))) @test zxd.mg == zxd2.mg && zxd.st == zxd2.st && zxd.ps == zxd2.ps zxd2 = copy(zxd) @@ -13,7 +16,7 @@ zxd2 = copy(zxd) @test rem_edge!(zxd, 2, 3) @test outneighbors(zxd, 2) == inneighbors(zxd, 2) -ZX.add_spider!(zxd, SpiderType.H, 0//1, [2, 3]) +ZX.add_spider!(zxd, SpiderType.H, 0 // 1, [2, 3]) ZX.insert_spider!(zxd, 2, 4, SpiderType.H) @test nv(zxd) == 5 && ne(zxd) == 4 @@ -24,26 +27,27 @@ push_gate!(zxd3, Val{:SWAP}(), [2, 3]) @test ZX.qubit_loc(zxd3, 1) == ZX.qubit_loc(zxd3, 2) @testset "float to rational" begin - @test ZX.continued_fraction(2.41, 10) === 241//100 - @test ZX.continued_fraction(1.3, 10) === 13//10 - @test ZX.continued_fraction(0, 10) === 0//1 - @test ZX.continued_fraction(-0.5, 10) === -1//2 + @test ZX.continued_fraction(2.41, 10) === 241 // 100 + @test ZX.continued_fraction(1.3, 10) === 13 // 10 + @test ZX.continued_fraction(0, 10) === 0 // 1 + @test ZX.continued_fraction(-0.5, 10) === -1 // 2 zxd = ZXDiagram(4) push_gate!(zxd, Val(:X), 3, 0.5) - @test zxd.ps[9] == 1//2 + @test zxd.ps[9] == 1 // 2 push_gate!(zxd, Val(:X), 3, -0.5) - @test zxd.ps[10] == 3//2 + @test zxd.ps[10] == 3 // 2 push_gate!(zxd, Val(:Z), 3, 0) - @test zxd.ps[11] == 0//1 + @test zxd.ps[11] == 0 // 1 @test_warn "" push_gate!(zxd, Val(:Z), 3, sqrt(2)) - @test_throws MethodError push_gate!(zxd, Val(:Z), 3, sqrt(2); autoconvert=false) - @test ZX.safe_convert(Rational{Int64}, 1.2) == 6//5 && ZX.safe_convert(Rational{Int64}, 1//2) == 1//2 + @test_throws MethodError push_gate!(zxd, Val(:Z), 3, sqrt(2); autoconvert = false) + @test ZX.safe_convert(Rational{Int64}, 1.2) == 6 // 5 && + ZX.safe_convert(Rational{Int64}, 1 // 2) == 1 // 2 end zxd4 = ZXDiagram(2) -ZX.add_global_phase!(zxd4, ZXCalculus.Utils.Phase(1//2)) +ZX.add_global_phase!(zxd4, ZXCalculus.Utils.Phase(1 // 2)) ZX.add_power!(zxd4, 2) -@test ZX.scalar(zxd4) == ZXCalculus.Utils.Scalar(2, 1//2) +@test ZX.scalar(zxd4) == ZXCalculus.Utils.Scalar(2, 1 // 2) pushfirst_gate!(zxd4, Val(:X), 1) pushfirst_gate!(zxd4, Val(:H), 1) pushfirst_gate!(zxd4, Val(:CNOT), 2, 1) diff --git a/test/zx_graph.jl b/test/zx_graph.jl index d5466ab..7eda938 100644 --- a/test/zx_graph.jl +++ b/test/zx_graph.jl @@ -1,3 +1,7 @@ +using Test, Multigraphs, ZXCalculus, ZXCalculus.ZX, ZXCalculus.Utils, Graphs + +import ZXCalculus.ZX as ZX + g = Multigraph(6) add_edge!(g, 1, 3) add_edge!(g, 2, 4) diff --git a/test/zxw_diagram.jl b/test/zxw_diagram.jl index 41503f9..cc57fd0 100644 --- a/test/zxw_diagram.jl +++ b/test/zxw_diagram.jl @@ -1,6 +1,9 @@ +using Test, ZXCalculus, Multigraphs, Graphs, ZXCalculus.ZXW using ZXCalculus.ZXW: ZXWSpiderType, Input, Output, W, H, D, Z, X using ZXCalculus.Utils: Parameter, PiUnit, Factor +import ZXCalculus.ZXW as ZXW + @testset "ZXWSpiderType" begin spider_vec = diff --git a/test/zxw_rules.jl b/test/zxw_rules.jl index 65f967b..0b46e6d 100644 --- a/test/zxw_rules.jl +++ b/test/zxw_rules.jl @@ -1,3 +1,4 @@ +using Test, ZXCalculus, ZXCalculus.ZXW, ZXCalculus.ZX, Graphs using Test: match_logs using ZXCalculus.ZXW: CalcRule, From 8e9ab1f9648131d3ac164df309959962a631618d Mon Sep 17 00:00:00 2001 From: Yusheng Zhao Date: Fri, 20 Oct 2023 22:10:41 +0800 Subject: [PATCH 10/10] replace import with using --- test/abstract_zx_diagram.jl | 2 +- test/ancilla_extraction.jl | 3 +-- test/challenge.jl | 2 +- test/rules.jl | 3 +-- test/simplify.jl | 3 +-- test/utils.jl | 2 +- test/zx_diagram.jl | 2 +- test/zx_graph.jl | 3 +-- test/zxw_diagram.jl | 3 +-- 9 files changed, 9 insertions(+), 14 deletions(-) diff --git a/test/abstract_zx_diagram.jl b/test/abstract_zx_diagram.jl index c7ce697..232f2a4 100644 --- a/test/abstract_zx_diagram.jl +++ b/test/abstract_zx_diagram.jl @@ -1,7 +1,7 @@ using Test, Graphs, ZXCalculus, ZXCalculus.ZX using ZXCalculus.Utils: Phase +using ZXCalculus: ZX -import ZXCalculus.ZX as ZX struct TestZXDiagram{T,P} <: AbstractZXDiagram{T,P} end diff --git a/test/ancilla_extraction.jl b/test/ancilla_extraction.jl index 4c860ce..1a5e787 100644 --- a/test/ancilla_extraction.jl +++ b/test/ancilla_extraction.jl @@ -1,7 +1,6 @@ using Test, ZXCalculus, ZXCalculus.ZX using ZXCalculus.ZX: ancilla_extraction - -import ZXCalculus.ZX as ZX +using ZXCalculus: ZX function gen_phase_gadget() zxd = ZXDiagram(2) diff --git a/test/challenge.jl b/test/challenge.jl index 443244c..b9eacf4 100644 --- a/test/challenge.jl +++ b/test/challenge.jl @@ -2,7 +2,7 @@ using Test, ZXCalculus, Graphs, ZXCalculus.ZX using ZXCalculus.ZX: SpiderType, EdgeType using ZXCalculus.Utils: Phase -import ZXCalculus.ZX as ZX +using ZXCalculus: ZX st = Dict( 0+1 => SpiderType.In, diff --git a/test/rules.jl b/test/rules.jl index 96b7932..bcc6d1e 100644 --- a/test/rules.jl +++ b/test/rules.jl @@ -1,6 +1,5 @@ using Test, ZXCalculus, Multigraphs, ZXCalculus.ZX, ZXCalculus.Utils, Graphs - -import ZXCalculus.ZX as ZX +using ZXCalculus: ZX g = Multigraph([0 2 0; 2 0 1; 0 1 0]) collect(edges(g)) diff --git a/test/simplify.jl b/test/simplify.jl index 8f2cf45..6706fae 100644 --- a/test/simplify.jl +++ b/test/simplify.jl @@ -1,7 +1,6 @@ using Test, ZXCalculus, ZXCalculus.ZX using YaoHIR: Chain - -import ZXCalculus.ZX as ZX +using ZXCalculus: ZX chain_swap = Chain() diff --git a/test/utils.jl b/test/utils.jl index 966673f..9535779 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -1,4 +1,5 @@ using Test, ZXCalculus, ZXCalculus.ZXW, ZXCalculus.Utils, Multigraphs, Graphs +using ZXCalculus: ZXW using ZXCalculus.ZXW: Parameter, _round_phase, @@ -18,7 +19,6 @@ using ZXCalculus.ZXW: using MLStyle: @match -import ZXCalculus.ZXW as ZXW @testset "Phase rounding" begin st = Dict( diff --git a/test/zx_diagram.jl b/test/zx_diagram.jl index 1ac3a78..370442f 100644 --- a/test/zx_diagram.jl +++ b/test/zx_diagram.jl @@ -1,5 +1,5 @@ using Test, ZXCalculus, Multigraphs, Graphs, ZXCalculus.ZX -import ZXCalculus.ZX as ZX +using ZXCalculus: ZX g = Multigraph([0 1 0; 1 0 1; 0 1 0]) ps = [Rational(0) for i ∈ 1:3] diff --git a/test/zx_graph.jl b/test/zx_graph.jl index 7eda938..a27f8eb 100644 --- a/test/zx_graph.jl +++ b/test/zx_graph.jl @@ -1,6 +1,5 @@ using Test, Multigraphs, ZXCalculus, ZXCalculus.ZX, ZXCalculus.Utils, Graphs - -import ZXCalculus.ZX as ZX +using ZXCalculus: ZX g = Multigraph(6) add_edge!(g, 1, 3) diff --git a/test/zxw_diagram.jl b/test/zxw_diagram.jl index cc57fd0..03807ef 100644 --- a/test/zxw_diagram.jl +++ b/test/zxw_diagram.jl @@ -1,8 +1,7 @@ using Test, ZXCalculus, Multigraphs, Graphs, ZXCalculus.ZXW using ZXCalculus.ZXW: ZXWSpiderType, Input, Output, W, H, D, Z, X using ZXCalculus.Utils: Parameter, PiUnit, Factor - -import ZXCalculus.ZXW as ZXW +using ZXCalculus: ZXW @testset "ZXWSpiderType" begin