Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New model with agent_step! and model_step! #889

Merged
merged 34 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6edb7d6
new model with agent_step! and model_step! inside
Tortar Sep 25, 2023
3663c87
fix
Tortar Sep 26, 2023
b171537
apply suggestions
Tortar Sep 26, 2023
7e19fad
more stuff
Tortar Sep 26, 2023
859add9
warnings
Tortar Sep 26, 2023
26fd68d
docstrings
Tortar Sep 26, 2023
7b5ba86
partial tests
Tortar Sep 27, 2023
37c5fe8
more tests
Tortar Sep 27, 2023
a0e3f6a
tests
Tortar Sep 28, 2023
8785fdf
almost ready
Tortar Sep 28, 2023
2aa6e65
fix
Tortar Sep 28, 2023
0e19cfe
improvements
Tortar Sep 28, 2023
86e3461
remove documenter compat
Datseris Sep 28, 2023
e0a273d
re-write enumerated list
Datseris Sep 29, 2023
678078c
remove mentioning of random device
Datseris Sep 29, 2023
5f25c83
write new step rule sections 3.1 and 3.2
Datseris Sep 29, 2023
9af7011
adjust docstrings to concrete implementation
Datseris Sep 30, 2023
288e48e
finish model evolution rules section
Datseris Sep 30, 2023
56d684e
finish section 4
Datseris Sep 30, 2023
bff452c
remove `agents_First` and correct teh step.jl file
Datseris Sep 30, 2023
05bf93c
fix add_agent docstring
Datseris Sep 30, 2023
080e850
update schelling
Datseris Sep 30, 2023
65346fd
add schedule for schedulers
Tortar Sep 30, 2023
0138484
Update schedulers.jl
Tortar Sep 30, 2023
3e1b8d4
Update schedulers.jl
Tortar Sep 30, 2023
3656057
Update docs/src/tutorial.md
Datseris Oct 1, 2023
59ce193
Update schedulers.jl
Tortar Oct 1, 2023
7dc5757
scheduling with schedule
Tortar Oct 1, 2023
57bd13d
simplify
Tortar Oct 1, 2023
97993b2
simplify schedule
Tortar Oct 1, 2023
05a57d7
fix tests
Tortar Oct 1, 2023
df206ec
fix model access
Tortar Oct 1, 2023
63b5f0d
Update tutorial.md
Tortar Oct 5, 2023
a95f61d
update changelog
Datseris Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
# v6
- The `@agent` macro has been rewritten to support fields with default and const values. The old version still works but it's deprecated. Since now the macro supports these features, using `@agent` is the only supported way to create agent types for Agents.jl.
- Manually setting or altering the ids of agents is no longer allowed. The agent id is now considered a read-only field, and is set internally by Agents.jl to enable hidden optimizations in the future. As a consequence, `add_agent!(agent::AbstractAgent, pos::ValidPos, model::ABM)` and `add_agent!(agent::AbstractAgent, model::ABM)` have been deprecated. See issue #861 for more.
- Agent types in `ContinuousSpace` now use `SVector` for their `pos` and `vel` fields rather than `NTuple`.
- Two new functions `random_id_in_position` and `random_agent_in_position` can be used to select a random id/agent in a position in discrete spaces (even with filtering).
# v6 - New Major release!

## Major and/or BREAKING

_We tried to deprecate every major change, resulting in practically no breakage from v5 to v6. However, in version v6.2 we will remove all deprecations (and hence un-updated code will break)_

- Deprecations that were in place in v5 (see section `# v5` of this CHANGELOG) have been removed.
- The way the evolution rule (`agent_step!, model_step!`) is handled has changed. Now, the stepping functions must be given to the agent based model during construction of the model instead of given to `step!, run!, abmplot, ...`. This change is important and allows us to:
- Have Agents.jl have the same mental model as DifferentialEquations.jl, DynamicalSystems.jl, and other dynamical modelling packages, where the evolution rules are part of the central simulation struct.
- Allows us to develop new types of models that may have rules that are defined differently, without being based on e.g., two particular functions.
- Allows us to develop (in the future) a new model type that is optimized for multi-agent simulations.
- The `@agent` macro has been rewritten to support fields with default and const values. It has a new usage syntax now that parallelizes more Julia's native `struct` declaration. The old macro version still works but it's deprecated. Since now the macro supports these features, using `@agent` is the only supported way to create agent types for Agents.jl.
- Manually setting or altering the ids of agents is no longer allowed. The agent id is now considered a read-only field, and is set internally by Agents.jl to enable hidden optimizations in the future. As a consequence, `add_agent!(agent::AbstractAgent, pos::ValidPos, model::ABM)` and `add_agent!(agent::AbstractAgent, model::ABM)` have been deprecated. See issue #861 for more.
- Agent types in `ContinuousSpace` now use `SVector` for their `pos` and `vel` fields rather than `NTuple`. `NTuple` usage in `ContinuousSpace` is officially deprecated, but backward compatibility is *mostly* maintained. Known breakages include the comparison of agent position and/or velocity with user-defined tuples, e.g., doing `agent.pos == (0.5, 0.5)`. This will always be `false` in v6 as `agent.pos` is an `SVector`. The rest of the functionality should all work without problems, such as moving agents to tuple-based positions etc.

## New features

- Two new functions `random_id_in_position` and `random_agent_in_position` can be used to select a random id/agent in a position in discrete spaces (even with filtering).
- A new argument `alloc` can be used to select a more performant version in relation to the expensiveness of the filtering for all random methods selecting ids/agents/positions.
- The `sample!` function is up to 2x faster than before.
- All spaces support boundaries with mixed periodicity, specified by tuples with a `Bool` value for each dimension, e.g. `GridSpace((5,5); periodic=(true,false))` is periodic along the first dimension but not along the second.

## BREAKING
- `NTuple` in `ContinuousSpace` is officially deprecated, but backward compatibility is *mostly* maintained. Known breakages include the comparison of agent position and/or velocity with user-defined tuples, e.g., doing `agent.pos == (0.5, 0.5)`. This will always be `false` in v6 as `agent.pos` is an `SVector`. The rest of the functionality should all work without problems, such as moving agents to tuple-based positions etc.
- Grid and continuous spaces support boundaries with mixed periodicity, specified by tuples with a `Bool` value for each dimension, e.g. `GridSpace((5,5); periodic=(true,false))` is periodic along the first dimension but not along the second.

# v5.17

- New function `replicate!` allows to create a new instance of a given agent at the same position with the possibility to specify some
fields with new values.
- The `sample!` function is 3x faster than before.

# v5.16

- New function `offline_run!` allows writing data to file at predefined intervals during `run!` instead of storing it in memory. Currently supports [CSV](https://csv.juliadata.org/stable/) and [Arrow](https://apache.github.io/arrow-julia/stable/) files.
Expand Down
3 changes: 0 additions & 3 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,3 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
CellListMap = "69e1c6dd-3888-40e6-b3c8-31ac5f578864"

[compat]
Documenter = "0.24.6"
2 changes: 1 addition & 1 deletion docs/logo/example_zoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function forest_fire(; density = 0.7, griddims = (100, 100), seed = 2)
## Empty = 0, Green = 1, Burning = 2, Burnt = 3
forest = ABM(GridAgent{2}, space; rng, properties = (trees = zeros(Int, griddims),))
for I in CartesianIndices(forest.trees)
if rand(forest.rng) < density
if rand(abmrng(forest)) < density
## Set the trees at the left edge on fire
forest.trees[I] = I[1] == 1 ? 2 : 1
end
Expand Down
6 changes: 4 additions & 2 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
The API of Agents.jl is defined on top of the fundamental structures [`AgentBasedModel`](@ref), [Space](@ref Space), [`AbstractAgent`](@ref) which are described in the [Tutorial](@ref) page.
In this page we list the remaining API functions, which constitute the bulk of Agents.jl functionality.

## [Concrete ABM implementations](@id ABM_Implementations)
## [More ABM implementations](@id ABM_Implementations)

Besides the generic interface of [`AgentBasedModel`](@ref), and the [`StandardABM`](@ref), highlighted in the tutorial, there is also:

```@docs
StandardABM
UnremovableABM
```

Expand Down
Loading