From 4aba244b1958fe276b698b1e8d28d89798691e92 Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Fri, 10 Nov 2023 14:14:12 +0100 Subject: [PATCH 1/6] remove `UnremovableABM` usages from src --- src/MicrobeAgents.jl | 2 +- src/model.jl | 76 ++++---------------------------------------- src/neighborlists.jl | 7 +--- 3 files changed, 8 insertions(+), 77 deletions(-) diff --git a/src/MicrobeAgents.jl b/src/MicrobeAgents.jl index 05d41e6..a2d034e 100644 --- a/src/MicrobeAgents.jl +++ b/src/MicrobeAgents.jl @@ -2,7 +2,7 @@ module MicrobeAgents using Agents export abmproperties, abmrng, abmspace, abmscheduler, spacesize -export StandardABM, UnremovableABM, ContinuousSpace +export StandardABM, ContinuousSpace export add_agent!, add_agent_pos! export move_agent!, walk!, run! diff --git a/src/model.jl b/src/model.jl index 38dad9f..83f6ed5 100644 --- a/src/model.jl +++ b/src/model.jl @@ -1,76 +1,9 @@ -# extended from Agents.jl -export StandardABM, UnremovableABM, add_agent! -# exported from Agents.jl without extensions -export ContinuousSpace - -""" - UnremovableABM(MicrobeType, space, timestep; kwargs...) -Extension of the `Agents.UnremovableABM` method for microbe types. -Implementation of `AgentBasedModel` where agents can only be added but not removed. -See `Agents.AgentBasedModel` for detailed information on the keyword arguments. - -**Arguments** -- `MicrobeType`: a concrete subtype of `AbstractMicrobe{D}`, - with explicitly specified dimensionality `D`. - A list of available options can be obtained by running `subtypes(AbstractMicrobe)`. -- `space`: a `ContinuousSpace{D}` with _the same_ dimensionality `D` as MicrobeType - which specifies the spatial properties of the simulation domain. -- `timestep`: the integration timestep of the simulation. - -**Keywords** -- `properties`: additional container of data to specify model-level properties. - MicrobeAgents.jl includes a set of default properties (detailed at the end). -- `agent_step!`: stepping function for each agent in the model -- `model_step!`: stepping function for the model -- `scheduler = Schedulers.fastest` -- `rng = Random.default_rng()` -- `spacing = minimum(extent)/20` -- `warn = true` - -**Default `properties`** - -When a model is created, a default set of properties is included in the model -(`MicrobeAgents.default_ABM_properties`): -``` -DEFAULT_ABM_PROPERTIES = Dict( - :t => 0, # counter for timekeeping - :concentration_field => (pos,model) -> 0.0, - :concentration_gradient => (pos,model) -> zero.(pos), - :concentration_time_derivative => (pos,model) -> 0.0, - # required by models of chemotaxis, default value is glutamate diffusivity - :compound_diffusivity => 608.0, -) -``` -By including these default properties, we make sure that all the chemotaxis models -will work even without extra user intervention. -All these properties can be overwritten by simply passing an equivalent key -to the `properties` dictionary when creating the model. -""" -function Agents.UnremovableABM( - T::Type{A}, space::ContinuousSpace{D}, timestep::Real; - agent_step! = microbe_step!, - model_step! = _ -> nothing, - scheduler = Schedulers.fastest, - properties = Dict(), - rng = Random.default_rng(), - warn = true -) where {D,A<:AbstractMicrobe{D}} - properties = Dict( - DEFAULT_ABM_PROPERTIES..., - properties..., - :timestep => timestep - ) - UnremovableABM(T, space; - agent_step!, model_step!, scheduler, properties, rng, warn - ) -end - - """ StandardABM(MicrobeType, space, timestep; kwargs...) Extension of the `Agents.StandardABM` method for microbe types. Implementation of `AgentBasedModel` where agents can be added and removed at any time. -If agents removal is not required, it is recommended to use `UnremovableABM` for better performance. +If agents removal is not required, it is recommended to use the +keyword argument `container = Vector` for better performance. See `Agents.AgentBasedModel` for detailed information on the keyword arguments. **Arguments** @@ -107,9 +40,11 @@ function Agents.StandardABM( T::Type{A}, space::ContinuousSpace{D}, timestep::Real; agent_step! = microbe_step!, model_step! = _ -> nothing, + container = Dict, scheduler = Schedulers.fastest, properties = Dict(), rng = Random.default_rng(), + agents_first = true, warn = true, ) where {D,A<:AbstractMicrobe{D}} properties = Dict( @@ -118,7 +53,8 @@ function Agents.StandardABM( :timestep => timestep ) StandardABM(T, space; - agent_step!, model_step!, scheduler, properties, rng, warn + agent_step!, model_step!, container, + scheduler, properties, rng, agents_first, warn ) end diff --git a/src/neighborlists.jl b/src/neighborlists.jl index 3f9bce2..3c41a0b 100644 --- a/src/neighborlists.jl +++ b/src/neighborlists.jl @@ -98,13 +98,8 @@ function update_neighborlist!(microbe::AbstractMicrobe, model, listkey) neighbor_list.xpositions[microbe.id] = microbe.pos end - -@inline function make_position_vector(model::UnremovableABM) - [position(a) for a in allagents(model)] -end @inline function make_position_vector(model::StandardABM) - ids = sort(collect(allids(model))) - [position(model[i]) for i in ids] + map(position, allagents(model)) end @inline function make_position_vector(x::AbstractVector) [SVector{length(xᵢ)}(position(xᵢ)) for xᵢ in x] From 241d9d3e2f5438a1e5f52d5b7b9c65fd190b4a61 Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Fri, 10 Nov 2023 14:39:24 +0100 Subject: [PATCH 2/6] update tests --- test/model-creation.jl | 9 +-- test/model-stepping.jl | 8 +-- test/model.jl | 132 ----------------------------------------- test/neighborlists.jl | 2 +- 4 files changed, 8 insertions(+), 143 deletions(-) delete mode 100644 test/model.jl diff --git a/test/model-creation.jl b/test/model-creation.jl index f7fb20e..ea4f908 100644 --- a/test/model-creation.jl +++ b/test/model-creation.jl @@ -5,18 +5,15 @@ using LinearAlgebra: norm for D in 1:3 timestep = 1 space = ContinuousSpace(ones(SVector{D})) - model_unremovable = UnremovableABM(Microbe{D}, space, timestep) - model_standard = StandardABM(Microbe{D}, space, timestep) - @test model_unremovable isa UnremovableABM - @test model_standard isa StandardABM - @test Set(keys(abmproperties(model_standard))) == Set(( + model = StandardABM(Microbe{D}, space, timestep) + @test model isa StandardABM + @test Set(keys(abmproperties(model))) == Set(( :t, :timestep, :concentration_field, :concentration_gradient, :concentration_time_derivative, :compound_diffusivity, )) - @test abmproperties(model_standard) == abmproperties(model_unremovable) end @testset "Base Microbe type" begin diff --git a/test/model-stepping.jl b/test/model-stepping.jl index 329705e..426b548 100644 --- a/test/model-stepping.jl +++ b/test/model-stepping.jl @@ -3,12 +3,12 @@ using Random using LinearAlgebra: norm @testset "Model stepping" begin - for D in 1:3, ABM in (StandardABM, UnremovableABM) + for D in 1:3, container in (Dict, Vector) rng = Xoshiro(68) dt = 1 extent = fill(300.0, SVector{D}) space = ContinuousSpace(extent) - model = ABM(Microbe{D}, space, dt; rng) + model = StandardABM(Microbe{D}, space, dt; rng, container) pos = extent ./ 2 vel1 = random_velocity(model) speed1 = random_speed(rng, RunTumble()) @@ -30,7 +30,7 @@ using LinearAlgebra: norm # customize microbe affect! function # decreases microbe state value by D at each step MicrobeAgents.affect!(microbe::Microbe{D}, model) = (microbe.state -= D) - model = ABM(Microbe{D}, space, dt) + model = StandardABM(Microbe{D}, space, dt; container) add_agent!(model) run!(model, 1) @test model[1].state == -D @@ -42,7 +42,7 @@ using LinearAlgebra: norm # customize model_step! function model_step!(model) = model.t += 1 - model = ABM(Microbe{D}, space, dt; model_step!) + model = StandardABM(Microbe{D}, space, dt; model_step!, container) run!(model, 6) @test model.t == 6 end diff --git a/test/model.jl b/test/model.jl deleted file mode 100644 index f4396c5..0000000 --- a/test/model.jl +++ /dev/null @@ -1,132 +0,0 @@ -using MicrobeAgents, Test -using Random -using LinearAlgebra: norm - -@testset "Agent Based Model" begin - @testset "Model creation" begin - for D in 1:3 - timestep = 1 - extent = ntuple(_ -> 300, D) - space = ContinuousSpace(extent) - model = UnremovableABM(Microbe{D}, space, timestep) - model2 = StandardABM(Microbe{D}, space, timestep) - @test model isa UnremovableABM - @test model2 isa StandardABM - @test Set(keys(abmproperties(model))) == Set(( - :t, :timestep, - :concentration_field, - :concentration_gradient, - :concentration_time_derivative, - :compound_diffusivity, - :update! - )) - - # add agents with default constructor, random pos and vel - rng = MersenneTwister(1234) - model = StandardABM(Microbe{D}, space, timestep; rng) - add_agent!(model) - rng = MersenneTwister(1234) - pos = Tuple(rand(rng, D) .* extent) - vel = rand_vel(rng, D) - speed = rand_speed(rng, RunTumble()) - @test Set(keys(model.agents)) == Set((1,)) - @test model[1] isa Microbe{D} - @test model[1].pos == pos - @test model[1].vel == vel - @test model[1].speed == speed - @test model[1].motility isa RunTumble - m₀ = Microbe{D}() - for key in setdiff(fieldnames(Microbe{D}), (:id, :pos, :vel, :motility)) - @test getfield(model[1], key) == getfield(m₀, key) - end - - # add agents with keyword arguments - model = StandardABM(Microbe{D}, space, timestep) - motility = RunReverse(speed_backward=[24.0], motile_state=MotileState(Backward)) - add_agent!(model; turn_rate=0.55, motility) - @test model[1].turn_rate == 0.55 - @test model[1].motility isa RunReverse - @test norm(model[1].vel) ≈ 1.0 - @test model[1].speed ≈ 24.0 - vel = rand_vel(D) - speed = rand_speed(RunTumble()) - add_agent!(model; vel) - @test model[2].vel == vel - @test model[2].speed == speed - - # add agent to given position - model = StandardABM(Microbe{D}, space, timestep) - pos = extent ./ 2 - add_agent!(pos, model) - @test model[1] isa Microbe{D} - @test model[1].pos == pos - pos = extent ./ 3 - microbe = Microbe{D}(2) # id=2 - add_agent!(microbe, pos, model) - @test model[2].pos == pos - # conserve agent's own position - pos = extent ./ 6 - microbe = Microbe{D}(3, pos) - add_agent_pos!(microbe, model) - @test model[3].pos == pos - end - end - - @testset "Stepping" begin - for D in 1:3, ABM in (StandardABM, UnremovableABM) - dt = 1 - extent = ntuple(_ -> 300, D) - space = ContinuousSpace(extent) - model = ABM(Microbe{D}, space, dt) - pos = extent ./ 2 - vel1 = rand_vel(D) - speed1 = rand_speed(RunTumble()) - add_agent!(pos, model; vel=vel1, speed=speed1, turn_rate=0) - vel2 = rand_vel(D) - speed2 = rand_speed(RunReverse()) - add_agent!(pos, model; vel=vel2, speed=speed2, turn_rate=Inf, motility=RunReverse()) - run!(model) # performs 1 microbe_step! and 1 model.update! step - # x₁ = x₀ + vΔt - @test all(model[1].pos .≈ pos .+ vel1 .* speed1 .* dt) - @test all(model[2].pos .≈ pos .+ vel2 .* speed2 .* dt) - # v is the same for the agent with zero turn rate - @test all(model[1].vel .≈ vel1) - # v is changed for the other agent - @test ~all(model[2].vel .≈ vel2) - # and since it turned its motile state changed from Forward to Backward - @test model[2].motility.state == Backward - # model time counter was increased to 1 - @test model.t == 1 - # perform other 5 steps - run!(model, 5) - @test model.t == 6 - - # customize microbe affect! function - # decreases microbe state value by D at each step - MicrobeAgents.affect!(microbe::Microbe{D}, model) = (microbe.state -= D) - model = ABM(Microbe{D}, space, dt) - add_agent!(model) - run!(model) - @test model[1].state == -D - # restore default affect! function - MicrobeAgents.affect!(microbe::Microbe{D}, model) = nothing - run!(model) - # now the state has not changed from previous step - @test model[1].state == -D - - # customize model.update! function - model = ABM(Microbe{D}, space, dt) - tick_more!(model) = (model.t += 3) - model → tick_more! # now model.t increases by 4 (+1 +3) at each step - run!(model, 6) - @test model.t == 6 * 4 - decrease!(model) = (model.t -= 1) - model = ABM(Microbe{D}, space, dt) - # chain arbitrary number of functions - model → tick_more! → decrease! → decrease! → decrease! - # now we should be back at only +1 per step - run!(model, 20) - @test model.t == 20 - end - end -end diff --git a/test/neighborlists.jl b/test/neighborlists.jl index 27a95d8..6a83f99 100644 --- a/test/neighborlists.jl +++ b/test/neighborlists.jl @@ -46,7 +46,7 @@ using Agents extent = fill(float(L), SVector{D}) space = ContinuousSpace(extent) dt = 1 - model = UnremovableABM(Microbe{D}, space, dt) + model = StandardABM(Microbe{D}, space, dt; container=Vector) n = 10 foreach(_ -> add_agent!(model), 1:n) listkey = :neighbors From 4e1f675bb59d41e39c4e1d5d4e2219f3899379ae Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Fri, 10 Nov 2023 14:48:32 +0100 Subject: [PATCH 3/6] change testset names --- test/neighborlists.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/neighborlists.jl b/test/neighborlists.jl index 6a83f99..141f410 100644 --- a/test/neighborlists.jl +++ b/test/neighborlists.jl @@ -3,7 +3,7 @@ using MicrobeAgents using Agents @testset "Neighbor Lists" begin - @testset "StandardABM" begin + @testset "Removable agents" begin for D in 1:3 L = 100 extent = fill(float(L), SVector{D}) @@ -40,7 +40,7 @@ using Agents end end - @testset "UnremovableABM" begin + @testset "Unremovable agents" begin for D in 1:3 L = 100 extent = fill(float(L), SVector{D}) From 4ffb89482b45c1267e7a6aa45e5509865020e831 Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Fri, 10 Nov 2023 14:48:41 +0100 Subject: [PATCH 4/6] update examples --- examples/Analysis/msd_runtumble.jl | 2 +- examples/Analysis/run_distribution.jl | 2 +- examples/Analysis/velocity_autocorrelations.jl | 2 +- examples/Chemotaxis/linear_ramp.jl | 2 +- examples/Chemotaxis/xie_2D.jl | 2 +- examples/Chemotaxis/xie_response-function.jl | 2 +- examples/Encounters/sphere3D.jl | 2 +- examples/Pathfinder/chemotaxis_porous-medium.jl | 2 +- examples/Pathfinder/randomwalk_porous-medium.jl | 2 +- examples/RandomWalks/randomwalk1D.jl | 2 +- examples/RandomWalks/randomwalk2D_motilepatterns.jl | 2 +- examples/RandomWalks/randomwalk3D.jl | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/Analysis/msd_runtumble.jl b/examples/Analysis/msd_runtumble.jl index 97c4996..ed6d9a8 100644 --- a/examples/Analysis/msd_runtumble.jl +++ b/examples/Analysis/msd_runtumble.jl @@ -13,7 +13,7 @@ U = 30.0 # μm/s τ = 1.0 # s turn_rate = 1 / τ -models = map(_ -> UnremovableABM(Microbe{3}, space, dt), θs) +models = map(_ -> StandardABM(Microbe{3}, space, dt; container=Vector), θs) nmicrobes = 100 for (i,θ) in enumerate(θs) motility = RunTumble(speed=[U], polar=[θ,-θ]) diff --git a/examples/Analysis/run_distribution.jl b/examples/Analysis/run_distribution.jl index c493283..4115d8b 100644 --- a/examples/Analysis/run_distribution.jl +++ b/examples/Analysis/run_distribution.jl @@ -6,7 +6,7 @@ L = 1000 space = ContinuousSpace((L,L)) dt = 0.01 -model = UnremovableABM(Microbe{2}, space, dt) +model = StandardABM(Microbe{2}, space, dt; container=Vector) n = 500 Drot = 0.1 τ = 1.5 diff --git a/examples/Analysis/velocity_autocorrelations.jl b/examples/Analysis/velocity_autocorrelations.jl index b95792e..77ba5e3 100644 --- a/examples/Analysis/velocity_autocorrelations.jl +++ b/examples/Analysis/velocity_autocorrelations.jl @@ -8,7 +8,7 @@ turn_rate = 1 / τ_run # 1/s L = 1e4 # μm space = ContinuousSpace((L,L,L)) -model = UnremovableABM(Microbe{3}, space, Δt) +model = StandardABM(Microbe{3}, space, Δt; container=Vector) n = 200 for i in 1:n add_agent!(model; turn_rate, motility=RunTumble(speed=[U])) diff --git a/examples/Chemotaxis/linear_ramp.jl b/examples/Chemotaxis/linear_ramp.jl index a4d229e..7265a50 100644 --- a/examples/Chemotaxis/linear_ramp.jl +++ b/examples/Chemotaxis/linear_ramp.jl @@ -35,7 +35,7 @@ properties = Dict( :concentration_field => concentration_field, :concentration_gradient => concentration_gradient ) -model = UnremovableABM(BrownBerg{2}, space, Δt; properties) +model = StandardABM(BrownBerg{2}, space, Δt; properties) for i in 1:n add_agent!(model) end diff --git a/examples/Chemotaxis/xie_2D.jl b/examples/Chemotaxis/xie_2D.jl index dd84807..3cc80c8 100644 --- a/examples/Chemotaxis/xie_2D.jl +++ b/examples/Chemotaxis/xie_2D.jl @@ -24,7 +24,7 @@ properties = Dict( ) rng = MersenneTwister(12) -model = UnremovableABM(Xie{2}, space, timestep; rng, properties) +model = StandardABM(Xie{2}, space, timestep; rng, properties) foreach(_ -> add_agent!(model; chemotactic_precision=6.0), 1:300) nsteps = 5000 diff --git a/examples/Chemotaxis/xie_response-function.jl b/examples/Chemotaxis/xie_response-function.jl index 97d909b..b41f42a 100644 --- a/examples/Chemotaxis/xie_response-function.jl +++ b/examples/Chemotaxis/xie_response-function.jl @@ -29,7 +29,7 @@ properties = Dict( ) model_step!(model) = model.t += 1 -model = UnremovableABM(Xie{3}, space, timestep; properties, model_step!) +model = StandardABM(Xie{3}, space, timestep; properties, model_step!) add_agent!(model; turn_rate_forward=0, motility=RunReverseFlick(motile_state=MotileState(Forward))) add_agent!(model; turn_rate_backward=0, motility=RunReverseFlick(motile_state=MotileState(Backward))) diff --git a/examples/Encounters/sphere3D.jl b/examples/Encounters/sphere3D.jl index dd0654f..ee538f3 100644 --- a/examples/Encounters/sphere3D.jl +++ b/examples/Encounters/sphere3D.jl @@ -33,7 +33,7 @@ function setupmodel(R, L, n; dt=0.1, rng=Xoshiro(1)) :sphere => HyperSphere(extent./2, R), :encounters => 0, ) - model = UnremovableABM(Microbe{3}, space, dt; properties, rng) + model = StandardABM(Microbe{3}, space, dt; properties, rng, container=Vector) foreach(_ -> add_agent!(model; turn_rate=2.0), 1:n) model → encounters! abmproperties(model)[:old_positions] = map(m -> m.pos, allagents(model)) diff --git a/examples/Pathfinder/chemotaxis_porous-medium.jl b/examples/Pathfinder/chemotaxis_porous-medium.jl index d4b100e..053761d 100644 --- a/examples/Pathfinder/chemotaxis_porous-medium.jl +++ b/examples/Pathfinder/chemotaxis_porous-medium.jl @@ -44,7 +44,7 @@ properties = Dict( :C₂ => C₂, ) -model = UnremovableABM(BrownBerg{2}, space, dt; properties) +model = StandardABM(BrownBerg{2}, space, dt; properties, container=Vector) pathfinder!(model, wm) foreach(_ -> add_agent!((0.0, rand()*extent[2]), model), 1:nbacteria) adata = [:pos] diff --git a/examples/Pathfinder/randomwalk_porous-medium.jl b/examples/Pathfinder/randomwalk_porous-medium.jl index b1ac39d..e2253d8 100644 --- a/examples/Pathfinder/randomwalk_porous-medium.jl +++ b/examples/Pathfinder/randomwalk_porous-medium.jl @@ -21,7 +21,7 @@ bodies = [ ] wm = walkmap(bodies, extent, min_radius/25, 0) -model = UnremovableABM(BrownBerg{2}, space, dt) +model = StandardABM(BrownBerg{2}, space, dt; container=Vector) pathfinder!(model, wm) foreach(_ -> add_agent!(model), 1:nbacteria) adata = [:pos] diff --git a/examples/RandomWalks/randomwalk1D.jl b/examples/RandomWalks/randomwalk1D.jl index 8351d53..39bef03 100644 --- a/examples/RandomWalks/randomwalk1D.jl +++ b/examples/RandomWalks/randomwalk1D.jl @@ -9,7 +9,7 @@ n = 10 nsteps = 600 ## abm setup -model = UnremovableABM(Microbe{1}, space, dt) +model = StandardABM(Microbe{1}, space, dt) foreach(_ -> add_agent!((0,), model), 1:n) ## simulation diff --git a/examples/RandomWalks/randomwalk2D_motilepatterns.jl b/examples/RandomWalks/randomwalk2D_motilepatterns.jl index e840287..09b3650 100644 --- a/examples/RandomWalks/randomwalk2D_motilepatterns.jl +++ b/examples/RandomWalks/randomwalk2D_motilepatterns.jl @@ -9,7 +9,7 @@ dt = 0.1 nsteps = 600 ## abm setup -model = UnremovableABM(Microbe{2}, space, dt) +model = StandardABM(Microbe{2}, space, dt) # add bacteria with different motile properties add_agent!(model; motility=RunReverse(speed_forward=[55]), rotational_diffusivity=0.2) add_agent!(model; motility=RunTumble(speed=Normal(30,6)), turn_rate=0.5) diff --git a/examples/RandomWalks/randomwalk3D.jl b/examples/RandomWalks/randomwalk3D.jl index b4783ed..cf4ef11 100644 --- a/examples/RandomWalks/randomwalk3D.jl +++ b/examples/RandomWalks/randomwalk3D.jl @@ -9,7 +9,7 @@ dt = 0.1 nsteps = 600 ## abm setup -model = UnremovableABM(Microbe{3}, space, dt) +model = StandardABM(Microbe{3}, space, dt) # add bacteria with different motile properties add_agent!(model; motility=RunReverse(speed_forward=[55]), rotational_diffusivity=0.2) add_agent!(model; motility=RunTumble(speed=Normal(30,6)), turn_rate=0.5) From fc776a8aeee3aec721cfeb88cd235eb024abf9c7 Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Fri, 10 Nov 2023 14:50:15 +0100 Subject: [PATCH 5/6] update benchmark --- benchmark/benchmarks.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index a845cfb..a1126c3 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -20,7 +20,7 @@ for D in dimensions evals = 10, samples = 1000, setup = ( - model = UnremovableABM(S, $T, dt), + model = StandardABM(S, $T, dt; container=Vector), S = ContinuousSpace(SVector{$D}(10.0 for _ in $D)), dt = 0.1 ) @@ -45,7 +45,7 @@ open("benchmarks.md", "a") do io for D in dimensions space = ContinuousSpace(ntuple(_ -> 10.0, D)) dt = 0.1 - model = UnremovableABM(T{D}, space, dt) + model = StandardABM(T{D}, space, dt; container=Vector) add_agent!(model; turn_rate = 1/dt) # reorients at each step nsteps = 1000 b = @benchmark run!($model, $(nsteps)) From b2f10d2582b4aaa509951e85f1d8662416ad4b25 Mon Sep 17 00:00:00 2001 From: Riccardo Foffi Date: Fri, 10 Nov 2023 14:53:33 +0100 Subject: [PATCH 6/6] update docs --- docs/src/chemotaxis.md | 2 +- docs/src/firststeps.md | 7 +++---- docs/src/randomwalks.md | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/src/chemotaxis.md b/docs/src/chemotaxis.md index 37ec936..9fa6653 100644 --- a/docs/src/chemotaxis.md +++ b/docs/src/chemotaxis.md @@ -56,7 +56,7 @@ properties = Dict( :concentration_field => concentration_field, :concentration_gradient => concentration_gradient ) -model = UnremovableABM(BrownBerg{2}, space, Δt; periodic, properties) +model = StandardABM(BrownBerg{2}, space, Δt; periodic, properties, container=Vector) for i in 1:n add_agent!(model) end diff --git a/docs/src/firststeps.md b/docs/src/firststeps.md index 8a1266b..77b6fec 100644 --- a/docs/src/firststeps.md +++ b/docs/src/firststeps.md @@ -88,11 +88,10 @@ MicrobeAgents.jl exploits the `AgentBasedModel` interface from Agents.jl. While the standard Agents.jl syntax will always work, it is typically more convenient to use the method extensions provided by MicrobeAgents.jl, which also includes some default parameters required by the simulations. -Both `StandardABM` and `UnremovableABM` are supported. Whenever removal of microbes during the simulation is not needed, -`UnremovableABM` is the recommended choice. +it is recommended to call `StandardABM` with the `container=Vector` +keyword argument to improve performance. ```@docs -UnremovableABM StandardABM ``` @@ -104,7 +103,7 @@ object. extent = (1000.0, 500.0) # size of 2D simulation domain space = ContinuousSpace(extent) dt = 0.1 # integration timestep -model = UnremovableABM(Microbe{2}, space, dt) +model = StandardABM(Microbe{2}, space, dt) ``` Now bacteria can be added with the `add_agent!` function. diff --git a/docs/src/randomwalks.md b/docs/src/randomwalks.md index 4135e1e..e150599 100644 --- a/docs/src/randomwalks.md +++ b/docs/src/randomwalks.md @@ -19,10 +19,10 @@ dt = 0.1 n = 10 nsteps = 600 -model = UnremovableABM(Microbe{1}, space, dt) +model = StandardABM(Microbe{1}, space, dt; container=Vector) foreach(_ -> add_agent!((0,), model), 1:n) ``` -By default, `UnremovableABM` will create a periodic domain; this will +By default, `ContinuousSpace` will create a periodic domain; this will allow us to mimic an "infinite" system. All the microbes have been initialized from position 0, without specifying any further property, so they will be initialized with a random @@ -62,7 +62,7 @@ space = ContinuousSpace((L,L)) dt = 0.1 nsteps = 600 -model = UnremovableABM(Microbe{2}, space, dt) +model = StandardABM(Microbe{2}, space, dt; container=Vector) ``` But we can now add bacteria with different motility patterns (we import Distributions.jl to use a Normal distribution for the speed of