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 multiagent macro #957

Merged
merged 54 commits into from
Jan 31, 2024
Merged

Implement multiagent macro #957

merged 54 commits into from
Jan 31, 2024

Conversation

Tortar
Copy link
Member

@Tortar Tortar commented Jan 16, 2024

Fixes #947

Because I'm a bit crazy I've already implemented it :D

(Notice that the more complicated example in #947 works and also the rabbit_fox_hawk example I modified)

@Tortar Tortar changed the title implement compact macro Implement compact macro Jan 16, 2024
@Tortar Tortar requested a review from Datseris January 16, 2024 01:14
@Tortar
Copy link
Member Author

Tortar commented Jan 16, 2024

Now even this more complicated compactification works

@compact struct Animal{T,N,J}(GridAgent{2})
    @agent struct Wolf{T,N}
        energy::T = 0.5
        ground_speed::N
        const fur_color::Symbol
    end
    @agent struct Hawk{T,N,J}
        energy::T = 0.1
        ground_speed::N
        flight_speed::J
    end
end

@Tortar
Copy link
Member Author

Tortar commented Jan 17, 2024

Seems kind of fine to me!!

Copy link
Member

@Datseris Datseris left a comment

Choose a reason for hiding this comment

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

This is fantastic!!! I assume you have tested it locally and tests passs, and we have the same roblem as with the other PR?

Should we rename the @compact to @multiagent? The front-end user doesn't really need to care about what the implementation detail does (compactifies), they only care that they get a multi-agent or mixed-agent model.

docs/src/performance_tips.md Outdated Show resolved Hide resolved
src/core/agents.jl Outdated Show resolved Hide resolved
Co-authored-by: George Datseris <datseris.george@gmail.com>
@Tortar Tortar marked this pull request as ready for review January 25, 2024 17:54
@Tortar
Copy link
Member Author

Tortar commented Jan 25, 2024

Hi George, should be okay now if you want to take a look

@Tortar
Copy link
Member Author

Tortar commented Jan 25, 2024

I updated the performance tips, I don't anymore mention the problem with working many types, I think our macro is good enough for many use cases already.

However, I don't consider the problem totally solved, and I consider #841 and its variations worth exploring.

E.g. our macro falls short when the types have a memory footprint very different from one another, because when we use the memory efficient version we are actually occupying anyway the memory of the agent with highest memory footprint (instead of the sum of their footprints which happens with :opt_speed) which can be sometimes too much anyway

@Datseris
Copy link
Member

great, I will review this on the weekend!

@Tortar Tortar changed the title Implement compact macro Implement multiagent macro Jan 26, 2024
@Datseris
Copy link
Member

Okay I will review this now and tomorrow. If you are around, any chance I can get a summary of this PR in a comment here?

@Datseris
Copy link
Member

all tests fail, I guess this is the "known" problem and everything passes locally?

@Tortar
Copy link
Member Author

Tortar commented Jan 28, 2024

In practice I implemented the multiagent macro where I also give to the user the possibility to choose between a more optimized version for speed or for memory by passing :opt_speed or :opt_memory as the first argument of the macro, by default it optimizes speed. Then I extended internals when needed, and I edited the branching_faster_than_dispatch.jl file so that to see how the two versions perform, you can find the results at the end of the file.

all tests fail, I guess this is the "known" problem and everything passes locally?

exactly, also strangely when we merge tests pass instead

docs/src/api.md Outdated Show resolved Hide resolved
docs/src/performance_tips.md Outdated Show resolved Hide resolved
src/core/agents.jl Outdated Show resolved Hide resolved
src/core/agents.jl Outdated Show resolved Hide resolved
src/core/agents.jl Outdated Show resolved Hide resolved
src/core/agents.jl Outdated Show resolved Hide resolved
@Datseris
Copy link
Member

@Tortar can you remind me what is the performance comparison of this method and the standard Union method that we used before? How much faster this is here? There was some benchmarks somewhere , right?

@Tortar
Copy link
Member Author

Tortar commented Jan 30, 2024

Yes, I updated two benchmarks in this PR, I described the results for variable_agent_types_simple_dynamics.jl in the other review comment, for the results of the other, see the bottom of branching_faster_than_dispatch.jl

@Datseris
Copy link
Member

right, the first file does not have any comments with the results, but from the second one

# Results:
# multiple types: 3.732 s (39242250 allocations: 2.45 GiB)
# @multiagent :opt_speed: 577.185 ms (25818000 allocations: 1.05 GiB)
# @multiagent :opt_memory: 870.460 ms (25868000 allocations: 1.05 GiB)
it appears that performance is up to 7x which is fantastic.

@Datseris
Copy link
Member

i'll merge this in when you adress the comments for the performance tips documentation. then i'll work on a re-worked tutorial and docs.

---------

Co-authored-by: George Datseris <datseris.george@gmail.com>
@Tortar
Copy link
Member Author

Tortar commented Jan 31, 2024

Docs updated!

@Tortar Tortar requested a review from Datseris January 31, 2024 17:00
Copy link
Member

@Datseris Datseris left a comment

Choose a reason for hiding this comment

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

right, i am merging this in, the plotting PR whcih is the last blocker left I think

@Datseris Datseris merged commit 481518a into main Jan 31, 2024
1 of 5 checks passed
@Datseris Datseris deleted the compact-macro branch January 31, 2024 21:18
@Datseris
Copy link
Member

oh, btw, what impliciations does this have for the Event queue abm? does it make it much faster as well? I Guess we should have a specialization there if there are no different agent types?

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.

A compactify macro to help to create a unique-type agent for multi-agent models
3 participants