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

Add first saving functions in local simulation run #50

Closed
wants to merge 9 commits into from

Conversation

corentinlger
Copy link
Collaborator

@corentinlger corentinlger commented Mar 15, 2024

Description

Partially save the state history in local simulation.

I implemented 5 new methods in the simulator.py file :

  • start_recording() : sets recording to true, instantiates a list called records, and creates a directory inside a 'Results/' folder to save recorded frames (with an optional name, else create something with experiment_{current date and time})
  • record(): add the desired data to records, called in the step function when recording is True
  • save_records(): save the records in the created saving_dir
  • stop_recording(): set recording to False, call save_records, and set records to [].
  • load(): load the records list from the desired saving_dir

I also modified the run and _run functions to accept save and saving_name as arguments, to enable saving simulations launched in standalone mode (without the interface)

If this logic is ok, we can add recording attribute to the simulator state so we can trigger it from the GUI.

At the moment I only save the nve_state, there is an error when trying to save the whole State with pickle (due to the gettatr method, I tried to see if we can remove it but it is used in other parts of the code). It is not very important because the data structure we use might change in the future.

Also added a test for this new feature. The saving and loading works but I saw that the values saved and loaded differ a bit (with a small numerical error on the positions for example). It is also something that could change with the way we save the data (we might save the entire state, maybe without pickle ...). That's why I keep the test that doesn't pass at the moment, we will modify it later.

What would you like to modify from the PR atm @clement-moulin-frier ?

Related Issue (if applicable)

#30

How to Test

Launch the server

python3 scripts/run_simulation.py --saving_name example_simulation
``

@corentinlger corentinlger linked an issue Mar 21, 2024 that may be closed by this pull request
@corentinlger corentinlger changed the title [WIP] Add first saving functions in local simulation run Add first saving functions in local simulation run Mar 26, 2024
@corentinlger
Copy link
Collaborator Author

Done in #85

@corentinlger corentinlger deleted the corentin/saving_loading branch July 4, 2024 10:09
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.

Implement saving/loading a simulation
2 participants