Skip to content

Commit

Permalink
Merge pull request #215 from jaakkor2/master
Browse files Browse the repository at this point in the history
LightGraphs to Graphs
  • Loading branch information
isaacsas authored Nov 10, 2021
2 parents 16f64bb + 1250c90 commit f71fd29
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/DiffEqJump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/spatial/flatten.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/spatial/topology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions test/spatial/ABC.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DiffEqJump, DiffEqBase
# using BenchmarkTools
using Test, LightGraphs
using Test, Graphs

Nsims = 100
reltol = 0.05
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/spatial/diffusion.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/spatial/utils_test.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tests for CartesianGrid
using DiffEqJump, LightGraphs
using DiffEqJump, Graphs
using Test, Random

io = IOBuffer()
Expand All @@ -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
Expand Down

0 comments on commit f71fd29

Please sign in to comment.