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

Allow to use random seed in make_synthetic_data #1286

Merged
merged 8 commits into from
Sep 27, 2023
Merged

Conversation

santisoler
Copy link
Member

@santisoler santisoler commented Sep 20, 2023

Summary

Add a new random_seed argument to the make_synthetic_data method.
Switch to the Numpy's random number generator object and pass the
random_seed argument to np.random.default_rng, allowing users to
specify a random seed for the synthetic noise. Set random seeds in some
tests that were failing due to the new random state that the usage of
make_synthetic_data with random_seed created in the test suite.

PR Checklist

  • If this is a work in progress PR, set as a Draft PR
  • Linted my code according to the style guides.
  • Added tests to verify changes to the code.
  • Added necessary documentation to any new functions/classes following the
    expect style.
  • Marked as ready for review (if this is was a draft PR), and converted
    to a Pull Request
  • Tagged @simpeg/simpeg-developers when ready for review.

Reference issue

Related to #1289

What does this implement/fix?

Additional information

Add a new `random_seed` argument to the `make_synthetic_data` method.
Switch to the Numpy's random number generator object and pass the
`random_seed` argument to `np.random.default_rng`, allowing users to
specify a random seed for the synthetic noise.
Replace calls to `np.random.rand` in some tests functions that were
failing locally for calls to methods of Numpy's random number generator,
defined with a hard-coded seed. It would be ideal to make these changes
in the whole test suite.
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Merging #1286 (38fdc64) into main (875fc32) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1286   +/-   ##
=======================================
  Coverage   82.36%   82.36%           
=======================================
  Files         164      164           
  Lines       25098    25099    +1     
=======================================
+ Hits        20673    20674    +1     
  Misses       4425     4425           
Files Coverage Δ
SimPEG/simulation.py 95.57% <100.00%> (+0.01%) ⬆️

@santisoler
Copy link
Member Author

santisoler commented Sep 21, 2023

@jcapriot I managed to get the tests to pass here. But at some point I would love to see all tests run with a hard coded seed. Do you think it worth tackling that in this PR or should we merge this one and tackle the rest in a separate one?

Copy link
Member

@lheagy lheagy left a comment

Choose a reason for hiding this comment

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

Thanks @santisoler! It will be valuable to have better practices in place for dealing with randomness. This looks good to me 🚀

I know there are a lot of other places across SimPEG to do this, one of the higher priority places to look to next would be the directives: I am specifically thinking of the beta-estimator. We can start an issue if you like, I am just commenting here as it is top-of-mind as I look at these updates

SimPEG/simulation.py Show resolved Hide resolved
SimPEG/simulation.py Outdated Show resolved Hide resolved
Co-authored-by: Lindsey Heagy <lindseyheagy@gmail.com>
@santisoler santisoler merged commit c477bbb into main Sep 27, 2023
16 checks passed
@santisoler santisoler deleted the synthetic-data-random branch September 27, 2023 17:33
@lheagy lheagy added this to the 0.21.0 milestone Nov 29, 2023
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.

None yet

2 participants