-
Notifications
You must be signed in to change notification settings - Fork 52
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
Parallel semantics for stepping robots #1925
Comments
System robots would need special consideration, since multiple commands can run in one tick with And in #1736 we achieved the ability for a robot's actions in one tick to be fully responded to by the system before that robot's next tick. There should be some way to preserve that ability. |
Very good points, I had not thought of these! But I think they are ultimately solvable:
|
Why not fallback to sequential processing for the conflicting actions? Most of the work would be done at that time and you would get less exceptions for a bit of perf cost. Maybe even derive conflicting sets of actions and process different sets concurrently (if this is indeed need) |
That would certainly be possible. My main argument against it would simply be that it is less theoretically elegant, and it introduces extra complication for little benefit. If we fall back to sequential processing for conflicting actions, then once again to predict what will happen you need to know the secret order in which the conflicting robots will be executed. And if we think ahead to networked play, how will you even decide how to order the robots (since the ID numbers may not be globally unique across different clients)? You cannot just say "mine first, then theirs" since all the participating clients would have to agree on a sequential order to use in the case of conflicts. With a more symmetric, purely parallel approach, on the other hand, there is nothing to agree on, and the robots are truly unordered. |
Nice write-up @byorgey! Splitting out the world updates from CESK evaluation sounds great. Like @kostmo I also immediately thought about I think we could even retrict the instant command if it simplifies this feature. Because of hypothetical computation we should not lose any power. |
I was thinking making this order intentionally random. It would introduce some uncertainty into the environment that might be a fun/challenging new feature in the game itself. I was not considering networked play though. |
Yes, exactly, we are going to be dealing with sets of world updates anyway, so it makes sense for one robot to be able to generate an entire set. However, I just realized one tricky thing about this: let's say a system robot executes I don't know, this sounds rather complex. Maybe there is a simpler approach... perhaps system robots never conflict? e.g. if a system robot grabs a rock at the same time as a user robot, then the system robot gets the rock and the user robot gets a "no rock to grab" error. And if two system robots grab a rock at the same time, they both get a rock. |
Ah, I see. That's definitely better than having the order depend on robot ID. Then at least it would be "predictably unpredictable". However, the game is currently completely deterministic, in the sense that executing the exact same commands from the exact same starting state (i.e. same world with same seed) will always yield exactly the same results. I would be sad to lose that property---partly on aesthetic grounds, but partly also practical grounds, e.g. determinism makes possible (or at least easier) potential features like networked play and playback of recorded game sessions. |
We should probably develop a benchmark up front to estimate the best-case performance improvement of parallelism. One concern I have is that of "context switching". In some games, the parallelism is distributed "vertically", with one dedicated processor to physics, another to rendering, etc. which minimizes context switching. In our case, "horizontal" parallelism may entail evaluating a batch of robots for a single tick with Update: |
Just to record some points from our discussion today:
|
#1920 really got me thinking. The main reason concurrency is tricky, as @kostmo says there, is because robots take turns executing, and each robot can see modifications to the world by the previous robot. Thus, currently, if we want to run CESK machines in parallel we would have to work very hard to make sure we respect such dependencies (or else give up on determinism, which I definitely don't want to do).
However, perhaps this is an opportunity to rethink our semantics. I'm kind of thinking out loud here, so I'm not yet sure how strongly I want to argue for this, but this issue is a proposal just for the sake of discussion.
The main idea: parallel semantics
The main idea is to adopt a parallel semantics in which, every tick,
i.e. think of the way cellular automata are typically defined: every cell decides what its state is going to be in the next tick based on the state of neighboring cells on the current tick, and then all the cells update at once.
Benefits
I think adopting this semantics could have a lot of benefits:
Downsides
grab
in an empty cell).Practical implementation details
Practically, it might work as follows:
GameState
to all robots and run them for one tick, each one resulting in an updated robot and a set of planned world updates (probably at most one world update, but in theory I suppose there could be more than one). There will be lots of kinds of world updates but they will be things like "place entity E at location (X,Y)", and so on. Each world update also records the robot ID of the robot that caused it.Impacts
Even though this would technically be a breaking change, in most cases I don't think it would make a difference. Differences would only be observable in the case of conflicts, which are rare. So I expect the vast majority of our test suite would continue to work. Perhaps one or two things where we specifically measure tick timings etc. might need some adjustment.
Having written all this, I think I'm still pretty positive about this idea. Eager to hear others' thoughts.
The text was updated successfully, but these errors were encountered: