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

Synchronization Issue in ML-Agents Decision Timing #6175

Open
matinmoezzi opened this issue Nov 22, 2024 · 1 comment
Open

Synchronization Issue in ML-Agents Decision Timing #6175

matinmoezzi opened this issue Nov 22, 2024 · 1 comment
Labels
request Issue contains a feature request.

Comments

@matinmoezzi
Copy link

Is your feature request related to a problem? Please describe.
Yes, the problem arises from the desynchronization between the decision time (when Python produces an action) and Academy.EnvironmentStep() (when Unity applies actions). This desync can lead to duplicate actions being taken or duplicate states being read, which is frustrating when trying to maintain consistency and synchronization during training. The issue seems to stem from the non-blocking websocket communication between Unity and Python.

Describe the solution you'd like
I’d like a blocking mechanism in Unity that pauses rendering until the next action from Python is available. This would ensure that Academy.EnvironmentStep() only processes actions and states in sync with the decision-making process, preventing duplicates.

Describe alternatives you've considered

  • Increasing the frequency of EnvironmentStep() updates to match decision-making timing, but this doesn't fully address the synchronization issue.
  • Adjusting Time.timeScale and FixedUpdate() to better align the two processes, though this approach is limited by the non-blocking nature of the websocket mechanism.

Additional context
This issue is likely caused by the asynchronous nature of websocket-based communication. A blocking mechanism could help bridge the gap between Unity and Python processes. Feedback or alternative solutions from the community would be greatly appreciated.

@matinmoezzi matinmoezzi added the request Issue contains a feature request. label Nov 22, 2024
@wlsdn2749
Copy link

wlsdn2749 commented Dec 4, 2024

Howdy!

Have you ever used RequestDecision method instead of Decision Requester Components?

main usage is

public class Test : Agent
...
private bool isShootable;
void FixedUpdate()
{
  if(isShootable)
  {
    RequestDecision();
  }
}

...

The RequestDecision method works exactly the same as the Decision Requester component.
However, decisions can be almost perfectly controlled as much as you want, so it will likely be more useful than you think

It follows the same process, such as RequestDecision -> CollectObservation -> OnActionReceived, and so on.

https://docs.unity3d.com/Packages/[email protected]/api/Unity.MLAgents.Agent.html#Unity_MLAgents_Agent_RequestDecision

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Issue contains a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants