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

Concurrency #1920

Open
noahyor opened this issue Jun 9, 2024 · 9 comments
Open

Concurrency #1920

noahyor opened this issue Jun 9, 2024 · 9 comments
Labels
C-Project A larger project, more suitable for experienced contributors. G-CESK machine This issue has to do with the CESK machine (the Swarm language interpreter). S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-Feature A new feature to be added to the game. Z-Performance This issue concerns memory or time efficiency of the Swarm game. Z-User Experience This issue seeks to make the game more enjoyable to play.

Comments

@noahyor
Copy link
Member

noahyor commented Jun 9, 2024

Currently, Swarm runs on one thread.

At first, this is not really a problem, as Swarm does not have to do much computation. However, as you build more robots, the maximum tick rate decreases due to the constraints of the single core it is running on.

In the extreme case of the Conway's Game of Life Scenario, I took these screenshots. (using WSL, see #1825)

Screenshot (6)

Screenshot (7)

I think one of the most obvious places to add concurrency is in the CESK evaluation of robots.

We could use the async package to do so.

@noahyor noahyor added Z-User Experience This issue seeks to make the game more enjoyable to play. Z-Feature A new feature to be added to the game. C-Project A larger project, more suitable for experienced contributors. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. G-CESK machine This issue has to do with the CESK machine (the Swarm language interpreter). Z-Performance This issue concerns memory or time efficiency of the Swarm game. labels Jun 9, 2024
@kostmo
Copy link
Member

kostmo commented Jun 10, 2024

I would love to make use of concurrency somehow. It may be tricky to apply to evaluation of the robot CESK machines, since <robot 2> must be able to see the new the state of the world after <robot 1> has modified it. Within a single "tick", robots strictly "take turns" without ever executing at the same time.

If it is any help, I started working on a "timing diagram" of the robot execution sequence.

However, there may be an opportunity to run "goal evaluation" in parallel with robot execution, since "goal evaluation" cannot mutate the state of the world. We might need to be able to "roll back" to a previous world state after robot execution if the goal evaluation decided that the scenario has been won/lost.

@kostmo
Copy link
Member

kostmo commented Jun 10, 2024

Actually there may be an interesting opportunity to impose restrictions (through some kind of effect monad?) on the radius of observability/influence of robots, so that they might be executed concurrently without risk of "race conditions" so long as their "circles of influence" do not intersect.

Since there are quite a few robot commands that act at a distance (as well as system robots for which distance restrictions can be ignored), it would take some effort to cover all of the edge cases.

@xsebek
Copy link
Member

xsebek commented Jun 10, 2024

@kostmo perhaps we could analyze if the robot could influence others at a distance.

I imagine a lot of robots only run commands that affect neighborhood cells and the others we could run before them.

@noahyor
Copy link
Member Author

noahyor commented Jun 10, 2024

Maybe we could have it such that each robot runs asynchronously for their one tick, then returns say, a pair of a new CESK state and some outward-facing action they want to perform. A main thread would then perform said actions deterministically.

@noahyor
Copy link
Member Author

noahyor commented Jun 10, 2024

@xsebek Some ideas:

There are some actions which cannot affect other robots, but most of them take 0 ticks to execute. (e.g. scan)

@noahyor
Copy link
Member Author

noahyor commented Jun 10, 2024

so that they might be executed concurrently without risk of "race conditions" so long as their
"circles of influence" do not intersect.

However a robot's "circle of influence" is infinite because of the improbable effects of the teleport command.

@noahyor
Copy link
Member Author

noahyor commented Jun 10, 2024

Actually, thinking about it some more, since the teleport command places random things on the ground, determinism is already gone.

@xsebek
Copy link
Member

xsebek commented Jun 10, 2024

@noahyor my point was that we could identify robots that want to teleport etc. and do only those synchronously.

@byorgey
Copy link
Member

byorgey commented Jun 10, 2024

Just wrote up some thoughts inspired by this discussion at #1925. Eager to hear what others think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Project A larger project, more suitable for experienced contributors. G-CESK machine This issue has to do with the CESK machine (the Swarm language interpreter). S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-Feature A new feature to be added to the game. Z-Performance This issue concerns memory or time efficiency of the Swarm game. Z-User Experience This issue seeks to make the game more enjoyable to play.
Projects
None yet
Development

No branches or pull requests

4 participants