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

Use composition for multiagents #1089

Merged
merged 12 commits into from
Oct 14, 2024
Merged

Use composition for multiagents #1089

merged 12 commits into from
Oct 14, 2024

Conversation

Tortar
Copy link
Member

@Tortar Tortar commented Oct 9, 2024

I didn't know about this feature but it is sweet in this case I think :-)

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.

I didn't know about this either... But, If two people that develop such a complex library don't know something about Julia, what does this say for the average user...? I think the average user would have no clue what this piece of code even means. This seems a cool feature, but probably should be highlighted as an advanced illustration. My suggestion would be to keep the the tutorial as-is and add another sentence afterwards that says something "actually, julia even allows for composition. You can use this character (with unicode \name and tab) and then compose functions" and then show the new code. Or something like that?

@Tortar
Copy link
Member Author

Tortar commented Oct 10, 2024

yeah, I had the same feeling, let's go with suggesting it after the constructor calls

@Tortar Tortar requested a review from Datseris October 12, 2024 01:28
@Datseris
Copy link
Member

I've improved the tutorial a bit. @Tortar I noticed that the two approaches aren't interchangeable per se:

julia> polit_constr = constructor(MultiSchelling, Politician)
#4 (generic function with 1 method)

julia> MultiSchelling ∘ Schelling
MultiSchelling ∘ Schelling

I assume this doens't have any impact on performance? To finish this do you want to replace the syntax in the docstring of @multiagent with the compsosition unicode?

@Tortar
Copy link
Member Author

Tortar commented Oct 13, 2024

Both return a function so they are interchangeable for our scopes and the composition shouldn't change any perf characteristics.

Replaced the composition in multiagent, I also changed a bit the constructor stuff in the tutorial, let me know what do you think. In general to construct single agents we have three options:

  • Multi(Agent(...))
  • (Multi∘Agent)(...)
  • constructor(Multi, Agent)(...)

I mean, in a sense, now that I know about the ∘ operator I would completely drop constructor(Multi, Agent)(...) and I would explain the logic more than anything else, e.g. if we woudn't have the composition operator we would need a closure to build the Multi(Agent(...)) syntax

src/core/agents.jl Outdated Show resolved Hide resolved
@Datseris Datseris merged commit 79e70cf into main Oct 14, 2024
3 of 5 checks passed
@Datseris Datseris deleted the Tortar-patch-2 branch October 14, 2024 07:58
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.

2 participants