You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GSoC: Integration of Agents.jl with RL methods (#1170)
* Create .gitkeep
* Add files via upload
* Add files via upload
* Delete examples/rl/.gitkeep
* Implement ReinforcementLearningABM and integrate with POMDPs/Crux interface for RL
- Reorganized old interface examples
- Added ReinforcementLearningABM and RLEnvironmentWrapper to enable compatibility with POMDPs-based RL algorithms provided by Crux.
- Implemented necessary POMDPs functions: actions, observations, observation, initialstate, initialobs, gen, isterminal, discount, and state_space.
- Added step_rl! and rl_agent_step! functions for RL agent behavior.
- Added examples to show how the new model type works
* ignore log
* fix wolfsheep
* fix indexing, stepping with policies and training config
* fix wolfsheep
* add scheduler
* add scheduler
* add discount rates to rl config
* add plot + start refactoring as extension
* refactor in extension and fix plotting
* Use less restrictive versions of libs
* remove piracy
* add documentation for rl functions + refactor rl code
* fix
* fix
* fix docstring
* fix exports
* fix interface observation function
* delete old files and rename examples
* delete old files
* add tests for rlabm
* create tutorial + fix training wolfsheep + add deps for tests
* fix tests
* fix makie version
* Update Project.toml
* Update Project.toml
* remove debug prints
* edit api docs
* edit docs
* Update Agents.jl
* Update rl_boltzmann.jl
* fix
* improve boltzmann tutorial + fixes
* refactor observation_radius + fixes
* fix example
* fix tutorial
* add tests for extension + improve docs for RLABM
* fix tests
* Update examples/rl_boltzmann.jl
* Update examples/rl_boltzmann.jl
* Update examples/rl_boltzmann.jl
* Update examples/rl_boltzmann.jl
* Update examples/rl_boltzmann.jl
* Update examples/rl_boltzmann.jl
* update example
* Update Project.toml
* fix stepping
* Update rl_boltzmann.jl
* Update rl_boltzmann.jl
* Update rl_boltzmann.jl
* Update ext/AgentsVisualizations/src/interaction.jl
Co-authored-by: George Datseris <datseris.george@gmail.com>
* Refactor RL training functions and update documentation
- Simplified the `train_model!` function signature to read agent types from the model's RL configuration.
- Set default `max_steps` to 100 in `setup_rl_training` and related functions.
- Updated observation and reward functions to accept agent objects instead of IDs.
- Removed redundant arguments and examples from documentation.
- Improved test cases to reflect changes in function signatures and configurations.
- Cleaned up unused code and comments in RL utility functions.
* Update Project.toml
* Update Project.toml
* Refactor RL configuration to use RLConfig struct and update related tests
* Refactor RLConfig constructor to improve parameter organization and readability
* add changelog and cross reference the RLABM struct
* add note about `using Crux`
* more cross linkage and stating the obvious
* reverse order of arguments in observation function: (agent, model).
* show videos in the RL example online
* rmove colorschemes dependency
* Add some info of what the obserrvation function is and why it is important
* clarify reward docs
* add new version for model init docs
* clarify RL libarry extension
* remove figures uploaded
---------
Co-authored-by: Adriano Meligrana <68152031+Tortar@users.noreply.github.com>
Co-authored-by: George Datseris <datseris.george@gmail.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+8-1Lines changed: 8 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,13 @@
1
1
# v6.3
2
2
3
-
**Experimental**: The `StructVector` container type, that supports a Struct-of-Arrays (SoA) layout, has been added. It currently only works with single agent types.
3
+
This new version brings two powerful, but both **experimental** features:
4
+
5
+
1. Allowing the agent container to be based on `StructVectors`, using a Struct-of-Arrays internal layout. Currently it only supports single agent types. To use this, pass `container = StructVector` to `StandardABM` or `EventQueueABM` constructors, as well as use the helper construct `SoAType{A}` for dispatch purposes instead of your agent type `A` (read the docstring of `SoAType`).
6
+
2. Native integration of ABMs with Reinforcement Learning is now provided by the new model type `ReinforcementLearningABM`. To learn how to use this functionality checkout the new tutorial on the Boltzmann Wealth Model with Reinforcement Learning.
7
+
8
+
These two features are labelled experimental because they did not yet undergo extensive testing by a broader pool of users. As versions progress and bug reports come in, and get solved, the features will mature to fully stable.
9
+
10
+
The experimental status allows us as developers to make breaking changes, if need be, to either feature, in order to fully stabilize them.
Copy file name to clipboardExpand all lines: README.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,13 @@
10
10
Agents.jl is a pure [Julia](https://julialang.org/) framework for agent-based modeling (ABM): a computational simulation methodology where autonomous agents react to their environment (including other agents) given a predefined set of rules.
11
11
Some major highlights of Agents.jl are:
12
12
13
-
1. It is fast (faster than MASON, NetLogo, or Mesa)
13
+
1. It is fast (typically [faster than established competitors](https://github.com/JuliaDynamics/ABMFrameworksComparison))
14
14
2. It is simple: has a very short learning curve and requires writing minimal code
15
15
3. Has an extensive interface of thousands of out-of-the box possible agent actions
16
16
4. Straightforwardly allows simulations on Open Street Maps
17
17
5. Allows both traditional discrete-time ABM simulations as well as continuous time
18
-
"event queue based" ABM simulations.
18
+
"event queue" based ABM simulations.
19
+
6. Provides native and unrestricted integration of ABM simulations with Reinforcement Learning (RL).
19
20
20
21
More information and an extensive list of features can be found in the documentation, which you can either find [online](https://juliadynamics.github.io/Agents.jl/stable/) or build locally by running the `docs/make.jl` file.
@@ -205,6 +228,7 @@ Most iteration in Agents.jl is **dynamic** and **lazy**, when possible, for perf
205
228
206
229
**Dynamic** means that when iterating over the result of e.g. the [`ids_in_position`](@ref) function, the iterator will be affected by actions that would alter its contents.
207
230
Specifically, imagine the scenario
231
+
208
232
```@example docs
209
233
using Agents
210
234
# We don't need to make a new agent type here,
@@ -218,16 +242,20 @@ for id in ids_in_position((1, 1, 1, 1), model)
218
242
end
219
243
collect(allids(model))
220
244
```
245
+
221
246
You will notice that only 1 agent was removed. This is simply because the final state of the iteration of `ids_in_position` was reached unnaturally, because the length of its output was reduced by 1 _during_ iteration.
222
247
To avoid problems like these, you need to `collect` the iterator to have a non dynamic version.
223
248
224
249
**Lazy** means that when possible the outputs of the iteration are not collected and instead are generated on the fly.
225
250
A good example to illustrate this is [`nearby_ids`](@ref), where doing something like
251
+
226
252
```julia
227
253
a =random_agent(model)
228
254
sort!(nearby_ids(random_agent(model), model))
229
255
```
256
+
230
257
leads to error, since you cannot `sort!` the returned iterator. This can be easily solved by adding a `collect` in between:
258
+
231
259
```@example docs
232
260
a = random_agent(model)
233
261
sort!(collect(nearby_agents(a, model)))
@@ -248,13 +276,13 @@ index_mapped_groups
248
276
```
249
277
250
278
## Data collection and analysis
279
+
251
280
```@docs
252
281
run!
253
282
ensemblerun!
254
283
paramscan
255
284
```
256
285
257
-
258
286
### Manual data collection
259
287
260
288
The central simulation function is [`run!`](@ref).
@@ -269,6 +297,7 @@ dataname
269
297
```
270
298
271
299
For example, the core loop of `run!` is just
300
+
272
301
```julia
273
302
df_agent =init_agent_dataframe(model, adata)
274
303
df_model =init_model_dataframe(model, mdata)
@@ -287,6 +316,7 @@ while until(t, t0, n, model)
287
316
end
288
317
return df_agent, df_model
289
318
```
319
+
290
320
(here `until` and `should_we_collect` are internal functions)
You can use [Function-like objects](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects) to make your scheduling possible of arbitrary events.
315
346
For example, imagine that after the `n`-th step of your simulation you want to fundamentally change the order of agents. To achieve this you can define
347
+
316
348
```julia
317
349
mutable struct MyScheduler
318
350
n::Int# step number
319
351
w::Float64
320
352
end
321
353
```
354
+
322
355
and then define a calling method for it like so
356
+
323
357
```julia
324
358
function (ms::MyScheduler)(model::ABM)
325
359
ms.n +=1# increment internal counter by 1 each time its called
@@ -334,17 +368,20 @@ function (ms::MyScheduler)(model::ABM)
To use the `parallel=true` option of [`ensemblerun!`](@ref) you need to load `Agents` and define your fundamental types at all processors. See the [Performance Tips](@ref) page for parallelization.
346
382
347
383
## Path-finding
384
+
348
385
```@docs
349
386
Pathfinding
350
387
Pathfinding.AStar
@@ -354,6 +391,7 @@ Pathfinding.random_walkable
354
391
```
355
392
356
393
### Pathfinding Metrics
394
+
357
395
```@docs
358
396
Pathfinding.DirectDistance
359
397
Pathfinding.MaxDistance
@@ -364,8 +402,10 @@ Building a custom metric is straightforward, if the provided ones do not suit yo
364
402
See the [Developer Docs](@ref) for details.
365
403
366
404
## Save, Load, Checkpoints
405
+
367
406
There may be scenarios where interacting with data in the form of files is necessary. The following
368
407
functions provide an interface to save/load data to/from files.
408
+
369
409
```@docs
370
410
AgentsIO.save_checkpoint
371
411
AgentsIO.load_checkpoint
@@ -374,6 +414,7 @@ AgentsIO.dump_to_csv
374
414
```
375
415
376
416
It is also possible to write data to file at predefined intervals while running your model, instead of storing it in memory:
0 commit comments