Skip to content

ENH: Discretized and No-Pickle Encoding Options #827

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

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

Conversation

phmbressan
Copy link
Collaborator

@phmbressan phmbressan commented Jun 14, 2025

Pull request type

  • Code changes (bugfix, features)

Checklist

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

Current behavior

The standard RocketPyEncoder currently does not support custom options for users/clients that may have the following needs:

  • Discrete encoding: as documented, this is useful to have the callable defined Functions written out in a human readable format. Of course, this has the drawback that the original callable cannot be exactly reproduced on decoding;
  • No-Pickle encoding: as it is common on I/O libraries/functions (e.g. NumPy save) having a toggle for pickling is beneficial for allowing the user/client having better control of security and output size (pickled objects might get large). This specially useful if there is no interest in decoding the result.

New behavior

The added options discretize and allow_pickle work as described above. The biggest challenge of the PR (which required a bit of hard coding) was setting discretization bounds for some of RocketPy callable Functions.

Breaking change

  • Yes
  • No

@phmbressan phmbressan added this to the Release v1.X.0 milestone Jun 14, 2025
@phmbressan phmbressan self-assigned this Jun 14, 2025
@phmbressan phmbressan requested a review from a team as a code owner June 14, 2025 11:29
@phmbressan phmbressan added Enhancement New feature or request, including adjustments in current codes Outputs Dedicated to visualizations enhancements like prints and plots labels Jun 14, 2025
if kwargs.get("include_outputs", False):
cl = self.cl
if kwargs.get("discretize", False):
cl = cl.set_discrete(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@MateusStano , could you give some insights if these boundary values make sense (angle of attack from -15 to 15 and mach 0 to 2)?

total_mass_flow_rate = self.total_mass_flow_rate
center_of_propellant_position = self.center_of_propellant_position

if discretize:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I admit this part of the code is not exactly pretty, but it was the way I found that better guarantees the necessary variables will be discrete.

Copy link

codecov bot commented Jun 14, 2025

Codecov Report

Attention: Patch coverage is 89.72973% with 19 lines in your changes missing coverage. Please review.

Project coverage is 80.14%. Comparing base (4df0b38) to head (dac833e).
Report is 22 commits behind head on develop.

Files with missing lines Patch % Lines
rocketpy/environment/environment.py 62.50% 6 Missing ⚠️
rocketpy/motors/hybrid_motor.py 50.00% 3 Missing ⚠️
rocketpy/motors/tank_geometry.py 62.50% 3 Missing ⚠️
...cketpy/rocket/aero_surface/fins/elliptical_fins.py 33.33% 2 Missing ⚠️
...ocketpy/rocket/aero_surface/fins/free_form_fins.py 33.33% 2 Missing ⚠️
rocketpy/mathutils/function.py 75.00% 1 Missing ⚠️
rocketpy/motors/tank.py 90.00% 1 Missing ⚠️
rocketpy/rocket/parachute.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #827      +/-   ##
===========================================
+ Coverage    79.11%   80.14%   +1.02%     
===========================================
  Files           96       98       +2     
  Lines        11575    12137     +562     
===========================================
+ Hits          9158     9727     +569     
+ Misses        2417     2410       -7     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Gui-FernandesBR Gui-FernandesBR requested a review from Copilot June 17, 2025 01:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces new encoding options—discretization and no‐pickle encoding—for RocketPy objects by refactoring the to_dict methods across many modules to accept keyword arguments (including include_outputs, discretize, and pickle_callables) instead of a fixed boolean flag. The changes affect multiple areas of the codebase including rocket components, aero surfaces, motors, math utilities, environment modules, and the custom JSON encoder.

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rocketpy/rocket/components.py Updated to_dict signature to accept **kwargs, removing the fixed include_outputs parameter.
rocketpy/rocket/aero_surface/*.py Refactored to_dict implementations within tail, rail_buttons, nose_cone, and fins modules to support new kwargs for discretization.
rocketpy/motors/*.py Updated to_dict methods in tank_geometry, tank, solid_motor, motor, liquid_motor, and hybrid_motor to use **kwargs with discretize handling.
rocketpy/motors/fluid.py Modified to_dict signature to accept **kwargs.
rocketpy/mathutils/vector_matrix.py Updated to_dict method to use **kwargs instead of a fixed include_outputs flag.
rocketpy/mathutils/function.py Refactored to_dict to incorporate discretize and pickle_callables flags and updated related logic.
rocketpy/environment/environment.py Added discretize handling for environmental data in to_dict.
rocketpy/_encoders.py Modified the custom JSON encoder to pass the updated kwargs to to_dict.
CHANGELOG.md Documented the enhancement with an entry for "Discretized and No-Pickle Encoding Options".
Comments suppressed due to low confidence (2)

rocketpy/_encoders.py:50

  • Consider updating the initializer docstring to clearly document the new 'discretize' and 'pickle_callables' kwargs, so users know how to control encoding behavior.
self.pickle_callables = kwargs.pop("pickle_callables", True)

rocketpy/motors/motor.py:1273

  • Ensure that the updated kwargs usage (including 'discretize' and 'include_outputs') is accurately reflected in the method docstring and accompanying tests, to avoid potential confusion with legacy behavior.
if kwargs.get("discretize", False):

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.

LGTM

@github-project-automation github-project-automation bot moved this from Backlog to Next Version in LibDev Roadmap Jun 17, 2025
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 Outputs Dedicated to visualizations enhancements like prints and plots
Projects
Status: Next Version
Development

Successfully merging this pull request may close these issues.

2 participants