diff --git a/Project.toml b/Project.toml index 2dc8c03..a5146a3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MicrobeAgents" uuid = "b17a4bac-8667-4a2d-84f7-1883ae0b8dbb" authors = ["Riccardo Foffi and contributors"] -version = "0.4.1" +version = "0.4.2" [deps] Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" @@ -9,9 +9,9 @@ Autocorrelations = "b9118d5e-f165-4cbd-b2ae-b030566b7b26" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" +LightSumTypes = "f56206fc-af4c-5561-a72a-43fe2ca5a923" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MeanSquaredDisplacement = "13c93d70-909c-440c-af92-39d48ffa2ba2" -MixedStructTypes = "3d69f371-6fa5-5add-b11c-3293622cad62" Quaternions = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" @@ -23,8 +23,8 @@ Autocorrelations = "0.1" DataFrames = "1" Distributions = "0.25" GeometryBasics = "0.4" +LightSumTypes = "4" MeanSquaredDisplacement = "0.2" -MixedStructTypes = "0.2" Quaternions = "0.7" StaticArrays = "1" StatsBase = "0.34" diff --git a/benchmark/benchmarks_0.4.2.md b/benchmark/benchmarks_0.4.2.md new file mode 100644 index 0000000..588f01a --- /dev/null +++ b/benchmark/benchmarks_0.4.2.md @@ -0,0 +1,20 @@ +# MicrobeAgents.jl benchmarks - 0.4.2 + +## Simple stepping +Type | Time (μs) | Allocs | Memory + --- | --- | --- | --- +Microbe{1} | 5.23e-01 | 1.10e+01 | 1.79e+02 +Microbe{2} | 6.60e-01 | 1.50e+01 | 3.07e+02 +Microbe{3} | 7.39e-01 | 1.50e+01 | 3.07e+02 +BrownBerg{1} | 6.13e-01 | 1.70e+01 | 7.55e+02 +BrownBerg{2} | 7.35e-01 | 2.10e+01 | 9.79e+02 +BrownBerg{3} | 8.29e-01 | 2.10e+01 | 1.08e+03 +Brumley{1} | 6.11e-01 | 1.65e+01 | 7.47e+02 +Brumley{2} | 7.55e-01 | 2.05e+01 | 9.71e+02 +Brumley{3} | 8.49e-01 | 2.05e+01 | 1.07e+03 +Celani{1} | 5.47e-01 | 1.30e+01 | 3.71e+02 +Celani{2} | 7.36e-01 | 1.70e+01 | 5.31e+02 +Celani{3} | 8.00e-01 | 1.70e+01 | 5.63e+02 +SonMenolascina{1} | 6.65e-01 | 1.60e+01 | 7.39e+02 +SonMenolascina{2} | 8.02e-01 | 2.00e+01 | 9.64e+02 +SonMenolascina{3} | 8.90e-01 | 2.00e+01 | 1.06e+03 diff --git a/src/MicrobeAgents.jl b/src/MicrobeAgents.jl index 511dc81..b79c24e 100644 --- a/src/MicrobeAgents.jl +++ b/src/MicrobeAgents.jl @@ -7,8 +7,8 @@ export add_agent!, add_agent_own_pos! export move_agent!, walk!, run! using Distributions +using LightSumTypes using LinearAlgebra -using MixedStructTypes using Random using Quaternions using StaticArrays diff --git a/src/microbe_step.jl b/src/microbe_step.jl index 6cb2e9c..e62ad2c 100644 --- a/src/microbe_step.jl +++ b/src/microbe_step.jl @@ -24,7 +24,7 @@ function microbe_step!(microbe::AbstractMicrobe, model::AgentBasedModel) # if the new motile state is a TurnState with duration 0 # immediately turn and transition to another state new_motilestate = motilestate(microbe) - if kindof(new_motilestate) === :TurnState && iszero(duration(new_motilestate)) + if variantof(new_motilestate) === TurnState && iszero(duration(new_motilestate)) turn!(microbe, model) update_motilestate!(microbe, model) end @@ -53,7 +53,7 @@ function microbe_pathfinder_step!(microbe::AbstractMicrobe, model::AgentBasedMod # if the new motile state is a TurnState with duration 0 # immediately turn and transition to another state new_motilestate = motilestate(microbe) - if kindof(new_motilestate) === :TurnState && iszero(duration(new_motilestate)) + if variantof(new_motilestate) === TurnState && iszero(duration(new_motilestate)) turn!(microbe, model) update_motilestate!(microbe, model) end diff --git a/src/motility.jl b/src/motility.jl index aa592cc..98bb260 100644 --- a/src/motility.jl +++ b/src/motility.jl @@ -5,28 +5,30 @@ export motilepattern, motilestate, state, states, transition_weights export duration, speed, polar, azimuthal export Arccos # from Agents -@compact_structs MotileState begin - @kwdef struct RunState - duration - speed - polar = nothing - azimuthal = nothing - end - @kwdef struct TurnState - duration - speed = [zero(duration)] - polar - azimuthal - end -end -function biased(s::MotileState) - if kindof(s) === :RunState - return true - else # TurnState - return false - end +struct RunState + duration + speed + polar + azimuthal end +struct TurnState + duration + speed + polar + azimuthal +end +@sumtype MotileState(RunState, TurnState) +function RunState(; duration, speed, polar=nothing, azimuthal=nothing) + MotileState(RunState(duration, speed, polar, azimuthal)) +end +function TurnState(; duration, speed=[zero(duration)], polar, azimuthal) + MotileState(TurnState(duration, speed, polar, azimuthal)) +end + +biased(s::MotileState) = biased(variant(s)) +biased(::RunState) = true +biased(::TurnState) = false # Base motile states Run(duration::Real, speed) = RunState(; duration, speed)