diff --git a/Project.toml b/Project.toml index b83a40b..16de76a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,10 +1,10 @@ name = "ZXCalculus" uuid = "3525faa3-032d-4235-a8d4-8c2939a218dd" authors = ["Chen Zhao and contributors"] -version = "0.4.4" +version = "0.5.0" [deps] -LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078" Multigraphs = "7ebac608-6c66-46e6-9856-b5f43e107bac" @@ -14,9 +14,9 @@ YaoLocations = "66df03fb-d475-48f7-b449-3d9064bf085b" [compat] CompilerPluginTools = "0.1" -LightGraphs = "1.3" MLStyle = "0.4" -Multigraphs = "0.2, 0.3" +Graphs = "1" +Multigraphs = "0.3" YaoHIR = "0.2" YaoLocations = "0.1" julia = "1" diff --git a/src/ZXCalculus.jl b/src/ZXCalculus.jl index 98cbb03..75b7450 100644 --- a/src/ZXCalculus.jl +++ b/src/ZXCalculus.jl @@ -5,9 +5,9 @@ using YaoHIR.IntrinsicOperation using YaoHIR: Chain using YaoLocations: plain using MLStyle -using LightGraphs, Multigraphs +using Graphs, Multigraphs -using LightGraphs: nv, ne, outneighbors, inneighbors, neighbors, rem_edge!, +using Graphs: nv, ne, outneighbors, inneighbors, neighbors, rem_edge!, add_edge!, has_edge, degree, indegree, outdegree export SpiderType, EdgeType diff --git a/src/abstract_zx_diagram.jl b/src/abstract_zx_diagram.jl index f2f56b0..90fa516 100644 --- a/src/abstract_zx_diagram.jl +++ b/src/abstract_zx_diagram.jl @@ -1,16 +1,16 @@ abstract type AbstractZXDiagram{T, P} end -LightGraphs.nv(zxd::AbstractZXDiagram) = throw(MethodError(LightGraphs.nv, zxd)) -LightGraphs.ne(zxd::AbstractZXDiagram) = throw(MethodError(LightGraphs.ne, zxd)) -LightGraphs.degree(zxd::AbstractZXDiagram, v) = throw(MethodError(LightGraphs.degree, (zxd, v))) -LightGraphs.indegree(zxd::AbstractZXDiagram, v) = throw(MethodError(LightGraphs.indegree, (zxd, v))) -LightGraphs.outdegree(zxd::AbstractZXDiagram, v) = throw(MethodError(LightGraphs.outdegree, (zxd, v))) -LightGraphs.neighbors(zxd::AbstractZXDiagram, v) = throw(MethodError(LightGraphs.neighbors, (zxd, v))) -LightGraphs.outneighbors(zxd::AbstractZXDiagram, v) = throw(MethodError(LightGraphs.outneighbors, (zxd, v))) -LightGraphs.inneighbors(zxd::AbstractZXDiagram, v) = throw(MethodError(LightGraphs.inneighbors, (zxd, v))) -LightGraphs.rem_edge!(zxd::AbstractZXDiagram, args...) = throw(MethodError(LightGraphs.rem_edge!, (zxd, args...))) -LightGraphs.add_edge!(zxd::AbstractZXDiagram, args...) = throw(MethodError(LightGraphs.add_edge!, (zxd, args...))) -LightGraphs.has_edge(zxd::AbstractZXDiagram, args...) = throw(MethodError(LightGraphs.has_edge, (zxd, args...))) +Graphs.nv(zxd::AbstractZXDiagram) = throw(MethodError(Graphs.nv, zxd)) +Graphs.ne(zxd::AbstractZXDiagram) = throw(MethodError(Graphs.ne, zxd)) +Graphs.degree(zxd::AbstractZXDiagram, v) = throw(MethodError(Graphs.degree, (zxd, v))) +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...))) Base.show(io::IO, zxd::AbstractZXDiagram) = throw(MethodError(Base.show, io, zxd)) Base.copy(zxd::AbstractZXDiagram) = throw(MethodError(Base.copy, zxd)) diff --git a/src/zx_diagram.jl b/src/zx_diagram.jl index 9b8fe99..19d0f81 100644 --- a/src/zx_diagram.jl +++ b/src/zx_diagram.jl @@ -70,7 +70,7 @@ end Construct a ZXDiagram with all information. ```jldoctest -julia> using LightGraphs, Multigraphs, ZXCalculus; +julia> using Graphs, Multigraphs, ZXCalculus; julia> using ZXCalculus.SpiderType: In, Out, H, Z, X; @@ -206,7 +206,7 @@ end Returns the number of vertices (spiders) of a ZX-diagram. """ -LightGraphs.nv(zxd::ZXDiagram) = nv(zxd.mg) +Graphs.nv(zxd::ZXDiagram) = nv(zxd.mg) """ ne(zxd; count_mul = false) @@ -215,14 +215,14 @@ Returns the number of edges of a ZX-diagram. If `count_mul`, it will return the sum of multiplicities of all multiple edges. Otherwise, it will return the number of multiple edges. """ -LightGraphs.ne(zxd::ZXDiagram; count_mul::Bool = false) = ne(zxd.mg, count_mul = count_mul) +Graphs.ne(zxd::ZXDiagram; count_mul::Bool = false) = ne(zxd.mg, count_mul = count_mul) -LightGraphs.outneighbors(zxd::ZXDiagram, v; count_mul::Bool = false) = outneighbors(zxd.mg, v, count_mul = count_mul) -LightGraphs.inneighbors(zxd::ZXDiagram, v; count_mul::Bool = false) = inneighbors(zxd.mg, v, count_mul = count_mul) +Graphs.outneighbors(zxd::ZXDiagram, v; count_mul::Bool = false) = outneighbors(zxd.mg, v, count_mul = count_mul) +Graphs.inneighbors(zxd::ZXDiagram, v; count_mul::Bool = false) = inneighbors(zxd.mg, v, count_mul = count_mul) -LightGraphs.degree(zxd::ZXDiagram, v::Integer) = degree(zxd.mg, v) -LightGraphs.indegree(zxd::ZXDiagram, v::Integer) = degree(zxd, v) -LightGraphs.outdegree(zxd::ZXDiagram, v::Integer) = degree(zxd, v) +Graphs.degree(zxd::ZXDiagram, v::Integer) = degree(zxd.mg, v) +Graphs.indegree(zxd::ZXDiagram, v::Integer) = degree(zxd, v) +Graphs.outdegree(zxd::ZXDiagram, v::Integer) = degree(zxd, v) """ neighbors(zxd, v; count_mul = false) @@ -230,11 +230,11 @@ LightGraphs.outdegree(zxd::ZXDiagram, v::Integer) = degree(zxd, v) Returns a vector of vertices connected to `v`. If `count_mul`, there will be multiple copy for each vertex. Otherwise, each vertex will only appear once. """ -LightGraphs.neighbors(zxd::ZXDiagram, v; count_mul::Bool = false) = neighbors(zxd.mg, v, count_mul = count_mul) -function LightGraphs.rem_edge!(zxd::ZXDiagram, x...) +Graphs.neighbors(zxd::ZXDiagram, v; count_mul::Bool = false) = neighbors(zxd.mg, v, count_mul = count_mul) +function Graphs.rem_edge!(zxd::ZXDiagram, x...) rem_edge!(zxd.mg, x...) end -function LightGraphs.add_edge!(zxd::ZXDiagram, x...) +function Graphs.add_edge!(zxd::ZXDiagram, x...) add_edge!(zxd.mg, x...) end diff --git a/src/zx_graph.jl b/src/zx_graph.jl index f510499..88760e6 100644 --- a/src/zx_graph.jl +++ b/src/zx_graph.jl @@ -100,16 +100,16 @@ function ZXGraph(zxd::ZXDiagram{T, P}) where {T, P} return zxg end -LightGraphs.has_edge(zxg::ZXGraph, vs...) = has_edge(zxg.mg, vs...) -LightGraphs.nv(zxg::ZXGraph) = nv(zxg.mg) -LightGraphs.ne(zxg::ZXGraph) = ne(zxg.mg) -LightGraphs.outneighbors(zxg::ZXGraph, v::Integer) = outneighbors(zxg.mg, v) -LightGraphs.inneighbors(zxg::ZXGraph, v::Integer) = inneighbors(zxg.mg, v) -LightGraphs.neighbors(zxg::ZXGraph, v::Integer) = neighbors(zxg.mg, v) -LightGraphs.degree(zxg::ZXGraph, v::Integer) = degree(zxg.mg, v) -LightGraphs.indegree(zxg::ZXGraph, v::Integer) = degree(zxg, v) -LightGraphs.outdegree(zxg::ZXGraph, v::Integer) = degree(zxg, v) -function LightGraphs.rem_edge!(zxg::ZXGraph, v1::Integer, v2::Integer) +Graphs.has_edge(zxg::ZXGraph, vs...) = has_edge(zxg.mg, vs...) +Graphs.nv(zxg::ZXGraph) = nv(zxg.mg) +Graphs.ne(zxg::ZXGraph) = ne(zxg.mg) +Graphs.outneighbors(zxg::ZXGraph, v::Integer) = outneighbors(zxg.mg, v) +Graphs.inneighbors(zxg::ZXGraph, v::Integer) = inneighbors(zxg.mg, v) +Graphs.neighbors(zxg::ZXGraph, v::Integer) = neighbors(zxg.mg, v) +Graphs.degree(zxg::ZXGraph, v::Integer) = degree(zxg.mg, v) +Graphs.indegree(zxg::ZXGraph, v::Integer) = degree(zxg, v) +Graphs.outdegree(zxg::ZXGraph, v::Integer) = degree(zxg, v) +function Graphs.rem_edge!(zxg::ZXGraph, v1::Integer, v2::Integer) if rem_edge!(zxg.mg, v1, v2) delete!(zxg.et, (min(v1, v2), max(v1, v2))) return true @@ -117,7 +117,7 @@ function LightGraphs.rem_edge!(zxg::ZXGraph, v1::Integer, v2::Integer) return false end -function LightGraphs.add_edge!(zxg::ZXGraph, v1::Integer, v2::Integer, edge_type::EdgeType.EType = EdgeType.HAD) +function Graphs.add_edge!(zxg::ZXGraph, v1::Integer, v2::Integer, edge_type::EdgeType.EType = EdgeType.HAD) if has_vertex(zxg.mg, v1) && has_vertex(zxg.mg, v2) if v1 == v2 if edge_type == EdgeType.HAD diff --git a/src/zx_layout.jl b/src/zx_layout.jl index 67b871a..6327359 100644 --- a/src/zx_layout.jl +++ b/src/zx_layout.jl @@ -13,7 +13,7 @@ ZXLayout(nbits::Integer, spider_q::Dict{T, Rational{Int}}, spider_col::Dict{T, R ZXLayout{T}() where {T} = ZXLayout(0, Dict{T, Rational{Int}}(), Dict{T, Rational{Int}}()) Base.copy(layout::ZXLayout) = ZXLayout(layout.nbits, copy(layout.spider_q), copy(layout.spider_col)) -function LightGraphs.rem_vertex!(layout::ZXLayout{T}, v::T) where {T} +function Graphs.rem_vertex!(layout::ZXLayout{T}, v::T) where {T} delete!(layout.spider_q, v) delete!(layout.spider_col, v) return diff --git a/test/abstract_zx_diagram.jl b/test/abstract_zx_diagram.jl index 31b0734..1dd08b3 100644 --- a/test/abstract_zx_diagram.jl +++ b/test/abstract_zx_diagram.jl @@ -1,4 +1,4 @@ -using ZXCalculus, LightGraphs +using ZXCalculus, Graphs using Test using ZXCalculus: Phase @@ -6,17 +6,17 @@ struct TestZXDiagram{T, P} <: AbstractZXDiagram{T, P} end test_zxd = TestZXDiagram{Int, Phase}(); -@test_throws MethodError LightGraphs.nv(test_zxd) -@test_throws MethodError LightGraphs.ne(test_zxd) -@test_throws MethodError LightGraphs.degree(test_zxd, 1) -@test_throws MethodError LightGraphs.indegree(test_zxd, 1) -@test_throws MethodError LightGraphs.outdegree(test_zxd, 1) -@test_throws MethodError LightGraphs.neighbors(test_zxd, 1) -@test_throws MethodError LightGraphs.outneighbors(test_zxd, 1) -@test_throws MethodError LightGraphs.inneighbors(test_zxd, 1) -@test_throws MethodError LightGraphs.rem_edge!(test_zxd, 1, 2) -@test_throws MethodError LightGraphs.add_edge!(test_zxd, 1, 2, 1) -@test_throws MethodError LightGraphs.has_edge(test_zxd, 1, 2) +@test_throws MethodError Graphs.nv(test_zxd) +@test_throws MethodError Graphs.ne(test_zxd) +@test_throws MethodError Graphs.degree(test_zxd, 1) +@test_throws MethodError Graphs.indegree(test_zxd, 1) +@test_throws MethodError Graphs.outdegree(test_zxd, 1) +@test_throws MethodError Graphs.neighbors(test_zxd, 1) +@test_throws MethodError Graphs.outneighbors(test_zxd, 1) +@test_throws MethodError Graphs.inneighbors(test_zxd, 1) +@test_throws MethodError Graphs.rem_edge!(test_zxd, 1, 2) +@test_throws MethodError Graphs.add_edge!(test_zxd, 1, 2, 1) +@test_throws MethodError Graphs.has_edge(test_zxd, 1, 2) @test_throws MethodError print(test_zxd) @test_throws MethodError Base.copy(test_zxd) diff --git a/test/phase_teleportation.jl b/test/phase_teleportation.jl index 986a51b..0f8fad9 100644 --- a/test/phase_teleportation.jl +++ b/test/phase_teleportation.jl @@ -1,4 +1,4 @@ -using ZXCalculus, LightGraphs +using ZXCalculus, Graphs function gen_cir() cir = ZXDiagram(5) diff --git a/test/runtests.jl b/test/runtests.jl index 8b35285..83962a2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using ZXCalculus, LightGraphs, Multigraphs, SparseArrays +using ZXCalculus, Graphs, Multigraphs, SparseArrays using Documenter using Test