From 1250c901b617375dd32dbfacfe36d09a51817d50 Mon Sep 17 00:00:00 2001 From: Jaakko Ruohio Date: Wed, 10 Nov 2021 19:08:52 +0200 Subject: [PATCH] LightGraphs to Graphs --- Project.toml | 4 ++-- src/DiffEqJump.jl | 4 ++-- src/spatial/flatten.jl | 2 +- src/spatial/topology.jl | 8 ++++---- test/spatial/ABC.jl | 4 ++-- test/spatial/diffusion.jl | 8 ++++---- test/spatial/utils_test.jl | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index d4ccf9f3..7bacaca6 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e" -LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PoissonRandom = "e409e4f3-bfea-5376-8464-e040bb5c01ab" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" @@ -26,7 +26,7 @@ Compat = "2.2, 3.0" DataStructures = "0.17, 0.18" DiffEqBase = "6.45.0" FunctionWrappers = "1.0" -LightGraphs = "1.3.5" +Graphs = "1.4" PoissonRandom = "0.4" RandomNumbers = "1.3" RecursiveArrayTools = "2" diff --git a/src/DiffEqJump.jl b/src/DiffEqJump.jl index 0b9c0b81..78db6a46 100644 --- a/src/DiffEqJump.jl +++ b/src/DiffEqJump.jl @@ -6,12 +6,12 @@ using Reexport using Compat, RandomNumbers, TreeViews, LinearAlgebra using DataStructures, PoissonRandom, Random, ArrayInterface using FunctionWrappers, UnPack -using LightGraphs +using Graphs import DiffEqBase: DiscreteCallback, init, solve, solve!, plot_indices, initialize! import Base: size, getindex, setindex!, length, similar, show, merge!, merge import DataStructures: update! -import LightGraphs: neighbors, outdegree +import Graphs: neighbors, outdegree import RecursiveArrayTools: recursivecopy! using StaticArrays, Base.Threads diff --git a/src/spatial/flatten.jl b/src/spatial/flatten.jl index 542a7d29..01802935 100644 --- a/src/spatial/flatten.jl +++ b/src/spatial/flatten.jl @@ -1,4 +1,4 @@ -using DiffEqJump, DiffEqBase, LightGraphs +using DiffEqJump, DiffEqBase, Graphs """ prob.u0 must be a Matrix with prob.u0[i,j] being the number of species i at site j diff --git a/src/spatial/topology.jl b/src/spatial/topology.jl index e5865c84..55e992f9 100644 --- a/src/spatial/topology.jl +++ b/src/spatial/topology.jl @@ -2,10 +2,10 @@ A file with structs and functions for setting up and using the topology of the spatial system (e.g. a graph or a Cartesian grid) """ -################### LightGraph ######################## -num_sites(graph::AbstractGraph) = LightGraphs.nv(graph) -# neighbors(graph::AbstractGraph, site) = LightGraphs.neighbors(graph, site) -# outdegree(graph::AbstractGraph, site) = LightGraphs.outdegree(graph, site) +################### Graph ######################## +num_sites(graph::AbstractGraph) = Graphs.nv(graph) +# neighbors(graph::AbstractGraph, site) = Graphs.neighbors(graph, site) +# outdegree(graph::AbstractGraph, site) = Graphs.outdegree(graph, site) rand_nbr(rng, graph::AbstractGraph, site) = rand(rng, neighbors(graph, site)) nth_nbr(graph::AbstractGraph, site, n) = @inbounds neighbors(graph, site)[n] diff --git a/test/spatial/ABC.jl b/test/spatial/ABC.jl index 8396a552..5ad50672 100644 --- a/test/spatial/ABC.jl +++ b/test/spatial/ABC.jl @@ -1,6 +1,6 @@ using DiffEqJump, DiffEqBase # using BenchmarkTools -using Test, LightGraphs +using Test, Graphs Nsims = 100 reltol = 0.05 @@ -46,7 +46,7 @@ function get_mean_end_state(jump_prob, Nsims) end # testing -grids = [CartesianGridRej(dims), CartesianGridIter(dims), LightGraphs.grid(dims)] +grids = [CartesianGridRej(dims), CartesianGridIter(dims), Graphs.grid(dims)] jump_problems = JumpProblem[JumpProblem(prob, NSM(), majumps, hopping_constants=hopping_constants, spatial_system = grid, save_positions=(false,false)) for grid in grids] push!(jump_problems, JumpProblem(prob, DirectCRDirect(), majumps, hopping_constants=hopping_constants, spatial_system = grids[1], save_positions=(false,false))) # setup flattenned jump prob diff --git a/test/spatial/diffusion.jl b/test/spatial/diffusion.jl index 584802eb..31101af5 100644 --- a/test/spatial/diffusion.jl +++ b/test/spatial/diffusion.jl @@ -1,7 +1,7 @@ using DiffEqJump, DiffEqBase using Test using LinearAlgebra -using LightGraphs +using Graphs function get_mean_sol(jump_prob, Nsims, saveat) sol = solve(jump_prob, SSAStepper(), saveat = saveat).u @@ -49,7 +49,7 @@ hopping_rate = diffusivity * (linear_size/domain_size)^2 hopping_constants = [hopping_rate for i in starting_state] # analytic solution -lap = discrete_laplacian_from_spatial_system(LightGraphs.grid(dims), hopping_rate) +lap = discrete_laplacian_from_spatial_system(Graphs.grid(dims), hopping_rate) evals, B = eigen(lap) # lap == B*diagm(evals)*B' Bt = B' analytic_solution(t) = B*diagm(ℯ.^(t*evals))*Bt * reshape(prob.u0, num_nodes, 1) @@ -60,7 +60,7 @@ rel_tol = 0.01 times = 0.0:tf/num_time_points:tf algs = [NSM(), DirectCRDirect()] -grids = [CartesianGridRej(dims), CartesianGridIter(dims), LightGraphs.grid(dims)] +grids = [CartesianGridRej(dims), CartesianGridIter(dims), Graphs.grid(dims)] jump_problems = JumpProblem[JumpProblem(prob, algs[2], majumps, hopping_constants=hopping_constants, spatial_system = grid, save_positions=(false,false)) for grid in grids] sizehint!(jump_problems, 15 + length(jump_problems)) @@ -119,7 +119,7 @@ end # testing non-uniform hopping rates dims = (2,2) num_nodes = prod(dims) -grid = LightGraphs.grid(dims) +grid = Graphs.grid(dims) hopping_constants = Matrix{Vector{Float64}}(undef, 1, num_nodes) for ci in CartesianIndices(hopping_constants) (species, site) = Tuple(ci) diff --git a/test/spatial/utils_test.jl b/test/spatial/utils_test.jl index 25ddb888..021a3413 100644 --- a/test/spatial/utils_test.jl +++ b/test/spatial/utils_test.jl @@ -1,5 +1,5 @@ # Tests for CartesianGrid -using DiffEqJump, LightGraphs +using DiffEqJump, Graphs using Test, Random io = IOBuffer() @@ -8,7 +8,7 @@ dims = (4,3,2) sites = rand(1:prod(dims), 10) num_samples = 10^5 rel_tol = 0.01 -grids = [DiffEqJump.CartesianGridRej(dims), DiffEqJump.CartesianGridIter(dims), LightGraphs.grid(dims)] +grids = [DiffEqJump.CartesianGridRej(dims), DiffEqJump.CartesianGridIter(dims), Graphs.grid(dims)] for grid in grids show(io, "text/plain", grid) @test String(take!(io)) !== nothing