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

Implement EventQueueABM #917

Closed
wants to merge 27 commits into from
Closed

Implement EventQueueABM #917

wants to merge 27 commits into from

Conversation

Tortar
Copy link
Member

@Tortar Tortar commented Nov 7, 2023

Fixes #902

Still very bad but the new example at least works :-)

@Tortar Tortar marked this pull request as draft November 7, 2023 11:46
@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2023

Codecov Report

Attention: 54 lines in your changes are missing coverage. Please review.

Comparison is base (fa03585) 92.26% compared to head (23812ed) 90.51%.
Report is 3 commits behind head on main.

❗ Current head 23812ed differs from pull request most recent head cb0519b. Consider uploading reports for the commit cb0519b to get more accurate results

Files Patch % Lines
src/simulations/step.jl 0.00% 26 Missing ⚠️
src/core/model_event_queue.jl 34.48% 19 Missing ⚠️
src/core/model_validation.jl 89.36% 5 Missing ⚠️
src/submodules/schedulers.jl 50.00% 2 Missing ⚠️
src/core/model_abstract.jl 0.00% 1 Missing ⚠️
src/core/model_accessing_API.jl 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #917      +/-   ##
==========================================
- Coverage   92.26%   90.51%   -1.75%     
==========================================
  Files          33       36       +3     
  Lines        2274     2331      +57     
==========================================
+ Hits         2098     2110      +12     
- Misses        176      221      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Datseris
Copy link
Member

Datseris commented Nov 8, 2023

I am confused about the existence of model_step and agents_first, as the whole point of this event based system is that there is no model step and there cannot be "before" or "after" the step, as events happen on a continuous time line and hence don't have an end; they go on until exhaustion or hitting a user-provided time limit.

I would argue that if a user wants "agent steps" and "model steps" they should just go ahead and use the StandardABM and hence here we should focus on just the quing system and simplify everything.,

@Tortar
Copy link
Member Author

Tortar commented Nov 8, 2023

I agree 👍

event_function! = abmevents(model)[agent_type][event_idx]
event_function!(agent, model)
!haskey(agent_container(model), id) && return
propensities = abmrates(agent, model) .* nagents(model)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really clear to me why here we multiply by nagents(model), shouldn't it be the number of agents of the related agent type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually to me is not clear why applying a function such as nagents in general? shouldn't the user define his own rates? Given that we let choosing a function then every transformation of the propensities seems not useful. But it's not entirely clear to me how the algorithm should work, so I could be mistaken

Copy link
Member Author

@Tortar Tortar Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MA-Ramirez @Datseris I'd need some help on this if you can give some it would really appreciated :-)

Copy link
Member Author

@Tortar Tortar Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nobody has insights on this I will remove it, it is in any case possible to achieve through passing a function in abmrates

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late reply. Yes, you should remove this part and if the user needs to they can call nagents in abmrates.

@@ -8,10 +8,11 @@ In this page we list the remaining API functions, which constitute the bulk of A
Besides the generic interface of [`AgentBasedModel`](@ref), and the [`StandardABM`](@ref), highlighted in the tutorial, there is also:

```@docs
UnremovableABM
EventQueueABM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move AgentBasedModel here as well, and only expand the docstring of StandardABM in the tutorial. In the tutorial we just mention explicitly part of the interface by showing how it works in terms of examples. E.g., do something like model[2]. I can do this after this PR is merged.

@@ -138,7 +138,7 @@ end
# The first type parameter of any `ABM` subtype must be the space type.
spacetype(::ABM{S}) where {S} = S

agenttype(model::ABM) = notimplemented(model)
tuple_agenttype(model::ABM) = getfield(model, :agents_types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we renaming agenttype? I think tuple_agenttype is a bit of a mouthful as a getter. I think we can just accept that agenttype can return either a type or a union, and if not we can have agenttypes for unions and agenttype using only to ensure a single return type.

@Datseris
Copy link
Member

@Tortar what is remaining for this to be finished? It's the last PR before v6, right?

@Tortar Tortar added this to the v6.0 milestone Nov 23, 2023
@Tortar
Copy link
Member Author

Tortar commented Nov 23, 2023

Mainly some docstrings need to be finished and we need to add some more tests for the new model type. We agreed with @fbanning to put also #934 in the v6 milestone. I'm a bit overwhelmed by other tasks at the moment, I think I can work on this monday. But if someone else wants to help feel free to add your commits to the branch

@jacobusmmsmit
Copy link
Member

Can I ask what happened with the ConcurrentSim implementation? Did anyone try doing a comparison? I looked into CS.jl and it was rather complicated. I think it raises the complexity barrier for contributers even if none of the internals are exposed.

@Tortar
Copy link
Member Author

Tortar commented Nov 23, 2023

I think that we can add the CS.jl integration later, I'm not sure that internal with CS.jl will become too complicated, maybe it is so but it is worth trying in my opinion. I don't think it's a priority though

@jacobusmmsmit
Copy link
Member

At one point we can make a performance comparison with "from scratch continuous abm", "Agents-v6 continuous abm", and a "CS Agents continuous abm" and see if it's worth it, and if so how much.

@Datseris
Copy link
Member

I can take over this PR. I realized there are some things we need to improve. For example, if an agent is added to the model via e.g., replicate!, this agent will never get an event assigned to it. My proposal is that when an agent gets added to the model, we immediatelly trigger the event generatrion function for it. This also solves the "what's the starting event" problem. Because as soon as we populate the model with agents, there is also an event que.

I also want to do two more improvements: using the concept of probability mass to decide how events are chosen, and simplifying significantly the events. I will add a generic type AgentEvent that takes in an event function and the type of agent it applies over. In this way an event may be applicable to many agents by providing the AbstractAgent as the agent type, which will also be the deafult value.

@Datseris
Copy link
Member

Datseris commented Nov 24, 2023

I have had great progress in the eventqueuv2 branch, but I am not finished yet. I take a break now but I will finish this soon!

The new code gives more power to the user (more possible configurations and flexibility) while requiring the user to input less information due to two default options!

@Datseris Datseris mentioned this pull request Nov 25, 2023
@Tortar
Copy link
Member Author

Tortar commented Dec 28, 2023

Closing in favor of #940

@Tortar Tortar closed this Dec 28, 2023
@Tortar Tortar deleted the eventqueueabm branch January 25, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Design discussion for an Event-Based (Gillespie-like) agent based model in Agents.jl
4 participants