RocketPy icon indicating copy to clipboard operation
RocketPy copied to clipboard

ENH: Simulation Save and Load in JSON Files

Open phmbressan opened this issue 1 year ago • 1 comments

Pull request type

  • [X] Code changes (bugfix, features)

Checklist

  • [X] Tests for the changes have been added (if needed)
  • [ ] Docs have been reviewed and added / updated
  • [X] Lint (black rocketpy/ tests/) has passed locally
  • [X] All tests (pytest tests -m slow --runslow) have passed locally
  • [ ] CHANGELOG.md has been updated (if relevant)

New behavior

This PR improves rocketpy encoding and introduces decoding functionalities. The way this works is:

  • If the is a to_dict or from_dict method, they are used to perform the (de)encoding;
  • Otherwise, a default encoding of all vars() and constructor based decoding is done.

Breaking change

  • [ ] Yes
  • [X] No

Additional information

PR #679 should be merged first.

Here are some of the steps that could be improved:

  • [ ] Verify why the test for hybrid motor flight requires higher tolerances;
  • [ ] Test if all of the atmospheric models of Environments can be decoded without requiring re-read of files or API;
  • [ ] Evaluate whether we should encode outputs or only the minimum required information to decode the class from its init;
  • [ ] (Optional) Expand implementation to AirBrakes + Controllers and new classes.

Some important remarks:

  • The simple getting started simulation is essentially identical comparing the store & load, the only difference is the random lag and noise from Parachute class. I could not found a simple solution to reset those and always get the same results.

phmbressan avatar Sep 22 '24 15:09 phmbressan

Codecov Report

Attention: Patch coverage is 81.19891% with 69 lines in your changes missing coverage. Please review.

Project coverage is 76.38%. Comparing base (7c18881) to head (5d1c585). Report is 3 commits behind head on enh/sim-encoding.

Files with missing lines Patch % Lines
rocketpy/environment/environment.py 63.82% 17 Missing :warning:
rocketpy/_encoders.py 81.25% 9 Missing :warning:
rocketpy/motors/tank.py 80.48% 8 Missing :warning:
...ocketpy/rocket/aero_surface/fins/free_form_fins.py 33.33% 6 Missing :warning:
rocketpy/motors/tank_geometry.py 83.87% 5 Missing :warning:
...cketpy/rocket/aero_surface/fins/elliptical_fins.py 37.50% 5 Missing :warning:
rocketpy/simulation/flight.py 37.50% 5 Missing :warning:
rocketpy/motors/motor.py 76.47% 4 Missing :warning:
rocketpy/rocket/components.py 42.85% 4 Missing :warning:
rocketpy/mathutils/vector_matrix.py 66.66% 3 Missing :warning:
... and 2 more
Additional details and impacted files
@@                 Coverage Diff                  @@
##           enh/sim-encoding     #695      +/-   ##
====================================================
+ Coverage             76.37%   76.38%   +0.01%     
====================================================
  Files                    94       94              
  Lines                 11343    11341       -2     
====================================================
  Hits                   8663     8663              
+ Misses                 2680     2678       -2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Sep 22 '24 16:09 codecov[bot]

@phmbressan , as previously discussed, can you leave only one of the #679 and #695 open please?

Gui-FernandesBR avatar Nov 10 '24 00:11 Gui-FernandesBR