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

ENH: Expansion of Encoders Implementation for Full Flights. #679

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

phmbressan
Copy link
Collaborator

@phmbressan phmbressan commented Aug 30, 2024

Pull request type

  • Code changes (bugfix, features)

Checklist

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

Current behavior

Currently the _encoding module is just a stub and cannot still encode full simulations into a JSON like format.

New behavior

This PR expand this module bringing the following:

  • Custom Encoding for more types;
  • Customized behavior for some required classes with methods to_dict;
  • Support for Function encoding.

Breaking change

  • Yes
  • No

Additional information

There is much to discuss here on the implementation and maintainability side of things. Main discussion points:

  • Should we add a to_dict and (in the future) a from_dict method to some (or all) rocketpy classes?
    • My Opinion: I think adding the methods to everything might be the only way out. But there is some work and maintainability considerations.
  • The current status of the encoding can be fully deserialized?
    • My Opinion: All the information is there, but the typing should be improved to know which objects to decode (deserialize) into. For that reason, I kept the _encoders private.
  • Are there any other modules to make our work easier?
    • From my research, I have tested the following:
      • simplejson: brings some more types and speed into encoding, but does not help much with custom types;
      • jsonpickle: really great for the typing handler (already writes by default each object type) and is able to serialize. The problem is that is does not handle functions/lambdas and I did not find a good way to implement custom handlers for our use case;
      • pickle / dill: the most plug and play solution, however the output is not human readable and not generally compatible between different rocketpy versions.

Of course, this is what I understood upon researching and testing, feel free to make any comments or suggest other modules.

@phmbressan phmbressan added the Enhancement New feature or request, including adjustments in current codes label Aug 30, 2024
@phmbressan phmbressan added this to the Release v1.X.0 milestone Aug 30, 2024
@phmbressan phmbressan self-assigned this Aug 30, 2024
@phmbressan phmbressan requested a review from a team as a code owner August 30, 2024 21:32
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 77.41935% with 7 lines in your changes missing coverage. Please review.

Project coverage is 75.96%. Comparing base (3a4c742) to head (1519f44).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
rocketpy/mathutils/function.py 71.42% 4 Missing ⚠️
rocketpy/_encoders.py 88.88% 1 Missing ⚠️
rocketpy/motors/tank_geometry.py 50.00% 1 Missing ⚠️
rocketpy/rocket/components.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #679      +/-   ##
===========================================
+ Coverage    75.87%   75.96%   +0.08%     
===========================================
  Files           85       85              
  Lines        10085    10110      +25     
===========================================
+ Hits          7652     7680      +28     
+ Misses        2433     2430       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to complain about, good work.

@@ -5,3 +5,4 @@ netCDF4>=1.6.4
requests
pytz
simplekml
dill
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you searched about this lib before adding it to the requirements? is this stable enough?

Also, you must edit the pyproject.toml file otherwise this change is useless.

}

@classmethod
def from_dict(cls, func_dict):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I`d like to see an example of you loading a class from the dict.

@@ -186,3 +186,18 @@ def sort_by_position(self, reverse=False):
None
"""
self._components.sort(key=lambda x: x.position, reverse=reverse)

def to_dict(self):
"""Return a dictionary representation of the components.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Youre gonna have to make a lot of to_dict` methods. My recommendation is to avoid documenting all of them.
It's still experimental feature, so let's be "lazy" this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request, including adjustments in current codes
Projects
Status: Next Version
Development

Successfully merging this pull request may close these issues.

2 participants