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

Is this engine fully deterministic? #820

Closed
tzvc opened this issue Jan 30, 2020 · 8 comments
Closed

Is this engine fully deterministic? #820

tzvc opened this issue Jan 30, 2020 · 8 comments

Comments

@tzvc
Copy link

tzvc commented Jan 30, 2020

Hi there,

Awesome project, I love it!

A while back I made a project for experimenting with genetic algorithms using Matter.js.
It worked, but there was a problem. I noticed that, given the exact same input parameters, the simulations would sometimes give me different results. I tried to track down the problem but eventually gave up.

My question is, therefore: Is this engine fully deterministic? And If yes, what could I be missing in my code? https://github.com/theochampion/genetic-playground

Cheers!

@BNTFryingPan
Copy link

I can't say for sure if it is or not, but I believe it is. When you create new bodies, and your render.options.wireframes == false, it renders with, as stated in the documentation, a random color. however, if you refresh your whole browser page, the colors of all random colors (at least, made by the engine itself) will be the same.

a good place to see this is in this example, when you first open it, wireframes are enabled, you can turn them off by going to the sidebar on the right, and scrolling down, and it should be the first option under Render

@tzvc
Copy link
Author

tzvc commented Feb 11, 2020

@LeotomasMC This would imply that they in fact use a predefined random seed, but I don't think it's enough to say the engine is deterministic.

For example, in this example https://brm.io/matter-js/demo/#wreckingBall the initial condition are the same when you refresh and the results are still different each time :/

@liabru
Copy link
Owner

liabru commented Mar 6, 2020

Nice project! Watching them evolve is pretty mesmerising. Seems to work well?

Yes, as far as I know the engine should be deterministic given the exact same conditions and using a fixed timestep, the work I've been doing on testing recently seems to show this too.

Do you have a specific example that seems to fail? Are you sure there is no randomness used in the setup and the timestep is definitely fixed? Any idea how big the (initial) difference might be? Did you try different browsers?

@tzvc
Copy link
Author

tzvc commented Mar 7, 2020

Hi @liabru, all the initial conditions in my genetic algorithm and defined with a seeded random at the beginning of the run and I did a lot of debugging to ensure it was the case. However, I'm not sure about the fixed timestep, I don't remember setting anything particular in the engine to configure the timestep. Did I miss something here? 😃

As an example, in this example, the initial conditions are the same (I suppose) but the result of the simulation change on every re run

@liabru
Copy link
Owner

liabru commented Mar 7, 2020

The built in runner currently uses a dynamic timestep by default to prevent visual slow down, but this means the examples don't appear deterministic if your FPS fluctuates at all.

This behaviour is due to change in a future update using a more advanced approach, but for now if you're using the built in runner try using a fixed timestep e.g. Runner.create({ isFixed: true}).

@tzvc
Copy link
Author

tzvc commented Mar 8, 2020

Makes sense 😃 I looked at my code, and apparently I did set the timestep to be fixed here line 41

Also, what I found during my tests is that the less elements are rendered in the scene (so the better the performance) the more deterministic is seems to be.

@liabru
Copy link
Owner

liabru commented Jun 24, 2024

As of 0.20.0 there is now built in Matter.Runner support for fixed timestep with high refresh displays see #1300.

Now that fixed timestep is default, output should also be deterministic by default now too without needing to set runner.isFixed.

Closing this one. Thanks for the report!

@liabru liabru closed this as completed Jun 24, 2024
@DuleMdev
Copy link

Hey @liabru I am still facing issues with non deterministic behaviour. I have a ball drop merger game built with matter.js. Currently I am working on async feature where once I play a game I record all the moves and send them to my friend so he can play against me. Saving the moves and replaying them doesnt show the same output even on same device.

Because of the size limit I cant send videos...

I have found out that when having balls are spawned and moving slowly it works fine but when you are playing at a higher pace there are a lot of balls moving around it is not deterministic still. Any ideas here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants