Skip to content

Commit

Permalink
LightGraphs -> Graphs (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Dec 2, 2021
1 parent bc367c1 commit 5d49931
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/ZXCalculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/abstract_zx_diagram.jl
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
22 changes: 11 additions & 11 deletions src/zx_diagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -215,26 +215,26 @@ 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)
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

Expand Down
22 changes: 11 additions & 11 deletions src/zx_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@ 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
end
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
Expand Down
2 changes: 1 addition & 1 deletion src/zx_layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions test/abstract_zx_diagram.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using ZXCalculus, LightGraphs
using ZXCalculus, Graphs
using Test
using ZXCalculus: Phase

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)
Expand Down
2 changes: 1 addition & 1 deletion test/phase_teleportation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ZXCalculus, LightGraphs
using ZXCalculus, Graphs

function gen_cir()
cir = ZXDiagram(5)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ZXCalculus, LightGraphs, Multigraphs, SparseArrays
using ZXCalculus, Graphs, Multigraphs, SparseArrays
using Documenter
using Test

Expand Down

2 comments on commit 5d49931

@Roger-luo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

switch to Graphs from LightGraphs

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/49739

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 5d49931d9f2b4b45f537aaea03fcfebf6ad82ee2
git push origin v0.5.0

Please sign in to comment.