Skip to content

feat(contrib): cache resampled trajectory and store options - #100

Open
reginaldalfret wants to merge 1 commit into
nasa:mainfrom
reginaldalfret:fix/66-cache-resample-options
Open

reginaldalfret wants to merge 1 commit into
nasa:mainfrom
reginaldalfret:fix/66-cache-resample-options

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

Resolves #66 by storing resample options on resampled TrajectoryAnalysis instances and caching the resampled instances in an internal _resample_cache dictionary on the original simulation instance.

Details

  • Caches resampled trajectories keyed by (dt, include_output, include_events, max_deg) on self._resample_cache.
  • On repeated calls to resample() with the same options, returns the cached instance immediately to skip redundant spline fitting, evaluations, and dynamic output recalculations.
  • If called on a resampled trajectory, original_instance.resample(...) checks the original instance's cache and returns the existing resampled instance in $O(1)$.
  • Stores _resample_options as a tuple attribute on returned resampled trajectory instances for inspection.

Validation

  • Added comprehensive unit test test_resample_caching_and_options in tests/test_trajectory_analysis.py covering cache hits, distinct option recalculations, and chaining from already-resampled instances.
  • Full pytest test suite passed (93 passed, 2 skipped).
  • ruff check . passed with 0 lint errors.
  • git diff --check passed cleanly.

Closes #66

Store resample options on resampled TrajectoryAnalysis instances and cache results by options to avoid redundant calculations when called repeatedly with the same arguments.

Closes nasa#66

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>

This branch has not been deployed

No deployments
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.

TrajectoryAnalysis.resample could store options and skip calculations if called with the same

1 participant