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

Add seed parameter to UseCase #128

Merged
merged 4 commits into from
May 13, 2024

Conversation

JW-Kraft
Copy link
Collaborator

@JW-Kraft JW-Kraft commented Apr 5, 2024

Added the ability to provide a seed parameter for a UseCase as discussed in #127.

Manual testing with the existing input files gives reproducible results as expected.
Writing unit tests for this feature is tricks though, since pytest resets the random generator before each test to the same state (seed). This is exactly what this new feature is doing. Testing for it with pytest is therefore not useful: The test will not fail even if there is something wrong with setting the seed when initializing a UseCase.

@Bachibouzouk
Copy link
Collaborator

I think this feature does not need to be tested, but we could now write some tests thanks to it. The first one I would have in mind would be to save outputs from input_file_i.py computed with given seed (maybe not 30 runs but just 1) and then automatically make sure those results are the same (this would mean save the outputs once as csv file for comparison)

@FLomb FLomb added the enhancement New feature or request label Apr 11, 2024
@FLomb
Copy link
Contributor

FLomb commented Apr 11, 2024

This looks like a sensible way to implement the random.seed. Is there a reason why the PR is still labelled as a work in progress?

Could you perhaps show a couple of example outputs with the random seed?

@JW-Kraft JW-Kraft marked this pull request as ready for review April 11, 2024 09:28
@JW-Kraft
Copy link
Collaborator Author

Hi Francesco,
no reason it's still work in progress. I just changed the status.
I also just added an example file to demonstrate the functionality (random_seed_example.py in the example directory)

It generates this output of three example use cases (based on input_file_1) with and without fixed random seed.
image

Copy link
Contributor

@FLomb FLomb left a comment

Choose a reason for hiding this comment

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

The changes proposed look good, and the provided example confirms that they work as expected.

The only doubt I have is whether we want to keep the random_seed_example.py as part of the merged code or not. If we do, we may want to add some documentation that explains why it is there.

Additionally: check out the guidelines for contributing; I believe you are missing the addition of your name to the AUTHORS list.

@JW-Kraft
Copy link
Collaborator Author

Good point, I just added myself to the AUTHORS list.

It's just a small feature so I believe it would be fine without demonstration example. Alternatively I could create a notebook based on random_seed_example.py and include a short documentation there.
What do you think?

@FLomb
Copy link
Contributor

FLomb commented Apr 25, 2024

Hi, sorry for the delayed response. I think that it wouldn't be a bad idea to have an example of how to employ the random seed, given that we think this could be useful for a few cases. If you can build a notebook with short documentation, I'd be happy to have it included in the docs.

@JW-Kraft
Copy link
Collaborator Author

JW-Kraft commented May 8, 2024

Hi, sorry for my delayed reaction. I just added a notebook demonstrating the functionality. Does that look good?

@Bachibouzouk Bachibouzouk self-requested a review May 8, 2024 20:26
@@ -100,6 +105,10 @@ def __init__(
if self.date_start is not None and self.date_end is not None:
self.initialize()

# Set global random seed if it is specified
if self.random_seed:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if self.random_seed:
if self.random_seed is not None:

I prefer the defensive coding :)

Copy link
Collaborator

@Bachibouzouk Bachibouzouk left a comment

Choose a reason for hiding this comment

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

@JW-Kraft - could you rebase this branch onto the latest joss-paper and force push it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants