Skip to content

Conversation

@Lucas-Prates
Copy link
Contributor

@Lucas-Prates Lucas-Prates commented Apr 13, 2025

Pull request type

  • Code changes (bugfix, features)
  • Code maintenance (refactoring, formatting, tests)

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 (if relevant)

Current behavior

Currently, the user must use distributions that are specified in numpy.

New behavior

Allows the user to build upon the abstract class CustomSampler which must contain two methods: sample and reset_seed. Note that the user may implement very complex samplers that use real data, so long as it conforms to returning the data in the format specified.

Breaking change

  • No

Additional information

  • Add example to Monte Carlo class usage notebook
  • Verify that the seed is being properly reset in parallel Monte Carlo simulations

@Lucas-Prates Lucas-Prates requested a review from a team as a code owner April 13, 2025 19:24
@Lucas-Prates Lucas-Prates changed the title ENH: first implementation of CustomSampler ENH: allow users to provide custom samplers Apr 13, 2025
@Lucas-Prates Lucas-Prates self-assigned this Apr 13, 2025
@Lucas-Prates
Copy link
Contributor Author

@Gui-FernandesBR, @MateusStano and @phmbressan, I would like, if possible, a design check in this feature. I am not sure if this is what you had in mind.

In order to allow the user to specify his own sampler, I thought of providing an abstract class CustomSampler and allow him to implement two methods: sample and reset_seed. These are completely abstracted away from the Stochastic classes, and we only care about the return value. The sample itself might be very complex and even fetch outside data if the user wants to.

I provided a notebook to test the feature design. There, I implemented a MixtureOfGaussian distribution which is not natively implemented in numpy. (Think of a bimodal gaussian distribution if you want, as exemplified below.

image

@Lucas-Prates Lucas-Prates added Enhancement New feature or request, including adjustments in current codes Monte Carlo Monte Carlo and related contents labels Apr 13, 2025
@Lucas-Prates Lucas-Prates linked an issue Apr 13, 2025 that may be closed by this pull request
17 tasks
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.

Plrase update the changelog

@github-project-automation github-project-automation bot moved this from Backlog to Next Version in LibDev Roadmap Apr 13, 2025
@codecov
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

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

Project coverage is 79.84%. Comparing base (4df0b38) to head (f1f7220).
Report is 19 commits behind head on develop.

Files with missing lines Patch % Lines
rocketpy/stochastic/stochastic_model.py 75.00% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #803      +/-   ##
===========================================
+ Coverage    79.11%   79.84%   +0.72%     
===========================================
  Files           96       98       +2     
  Lines        11575    11958     +383     
===========================================
+ Hits          9158     9548     +390     
+ 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.

@MateusStano
Copy link
Member

Just missing changelog, then we can merge

@MateusStano MateusStano merged commit 3fe2b62 into develop Apr 28, 2025
10 checks passed
@MateusStano MateusStano deleted the enh/user_sampler branch April 28, 2025 13:23
@github-project-automation github-project-automation bot moved this from Next Version to Closed in LibDev Roadmap Apr 28, 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 Monte Carlo Monte Carlo and related contents

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

ENH: Monte Carlo Analysis Enhancements

4 participants