Skip to content

[BUG] Fix random seed consistency - #43

Merged
sappelhoff merged 12 commits into
sappelhoff:masterfrom
a-hurst:random_seed_fix
Dec 4, 2020
Merged

sappelhoff merged 12 commits into
sappelhoff:masterfrom
a-hurst:random_seed_fix

Conversation

@a-hurst

@a-hurst a-hurst commented Dec 2, 2020

Copy link
Copy Markdown
Collaborator

PR Description

This PR is meant to fix the secondary issue discovered in issue #41: that is, the inability to get consistent robust re-referencing results with a random seed if different numbers of chunks were used across runs. I've tested it locally with data and it's consistent across different manually-set chunk sizes, so I think it's working okay, but please let me know if you can think of any problems with this approach!

Merge Checklist

To merge your PR we need to first take the following points into account:

  • the PR has been reviewed and all comments are resolved
  • all CI checks pass
  • (if applicable): the PR description includes the phrase closes #<issue-number> to automatically close an issue
  • (if applicable): bug fixes, new features, or API changes are documented in whats_new.rst

@a-hurst

a-hurst commented Dec 2, 2020

Copy link
Copy Markdown
Collaborator Author

Huh, I guess one of the tests passes n_samples to find_bads_by_ransac as a float. I just changed the code to always coerce n_samples to an integer to make sure everything else checks out, but should I add proper type-checking instead? Or is this fix fine?

@sappelhoff

Copy link
Copy Markdown
Owner

Did you use

git clone https://github.com/sappelhoff/pyprep
cd pyprep
pip install -r requirements-dev.txt
pre-commit install
pip install -e .

as described in https://github.com/sappelhoff/pyprep#installation ?

@sappelhoff
sappelhoff requested a review from yjmantilla December 2, 2020 17:29
@sappelhoff

Copy link
Copy Markdown
Owner

but should I add proper type-checking instead?

a proper check would be much nicer if it provides a reasonable error

Comment thread pyprep/find_noisy_channels.py Resolved
Comment thread pyprep/find_noisy_channels.py Resolved
@sappelhoff

Copy link
Copy Markdown
Owner

The general idea looks good to me 🤔 I'll let @yjmantilla chime in before merging.

@a-hurst thanks for your first PR to pyprep 🎉 can you please also add a changelog entry and add yourself to the list of authors? (including an RST link to a page that you want users to find if they click on your name)

https://github.com/sappelhoff/pyprep/blob/master/docs/whats_new.rst

@yjmantilla yjmantilla left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The only thing that bugs me is that (I think) we can remove the n_pred_chns parameter in:

  • self.ransac_correlations()
  • self.self.run_ransac()
  • self.get_ransac_pred()

I mean one passes it to the other until get_ransac_pred just trashes it.

So I guess that for staying on the good programming practices we should remove it from the code and the functions documentations.

What do you think?

Now regarding the pytest stuff, Im looking at it to see what went wrong. A configuration issue?

@a-hurst

a-hurst commented Dec 3, 2020

Copy link
Copy Markdown
Collaborator Author

Good catch @yjmantilla, just implemented the suggestion! As for the tests, I'm wondering if it's just a fluke or whether I've somehow broken, hopefully the new push will let us know what's what. If it continues, we can add the -s flag to pytest and get the full printed RANSAC output to help debug.

@yjmantilla yjmantilla left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a minor suggestion... btw im not really accustomed to use this review stuff so bear with me, while i learn how to do it.

Comment thread pyprep/find_noisy_channels.py Resolved

@sappelhoff sappelhoff left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think the test failures may be due to GitHub Actions capping the amount of RAM we are allowed to use 🤔

are the tests passing locally for you?

Comment thread docs/whats_new.rst Resolved
@a-hurst

a-hurst commented Dec 4, 2020

Copy link
Copy Markdown
Collaborator Author

lol so I figured out the CI issue: because we're now pre-generating random channel picks for each sample, and we're testing the memory error exception by asking it to do 10^100 samples, it gets stuck generating a list of billions upon billions of picks and the process eventually gets killed due to RAM consumption.

I've fixed the issue by adding another RAM check prior to the channel picks so that we don't generate random samples for impossibly-high sample counts. To avoid reduplicating code and clean things up a bit, I moved the RAM check stuff to its own separate function, also implementing the max ram proportion from the other PR while I'm at it. Hopefully everything should work now!

@codecov-io

codecov-io commented Dec 4, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #43 (59da611) into master (89a0550) will decrease coverage by 0.72%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
- Coverage   97.08%   96.36%   -0.73%     
==========================================
  Files           5        5              
  Lines         515      523       +8     
==========================================
+ Hits          500      504       +4     
- Misses         15       19       +4     
Impacted Files Coverage Δ
pyprep/prep_pipeline.py 100.00% <ø> (ø)
pyprep/find_noisy_channels.py 95.73% <100.00%> (-1.54%) ⬇️
pyprep/utils.py 97.67% <100.00%> (+0.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89a0550...b3617ad. Read the comment docs.

Comment thread docs/whats_new.rst Resolved

@sappelhoff sappelhoff left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Haha, okay good that you caught it. Can you now rebase this PR on master and resolve the merge conflicts, please?

I also added one more comment for the changelog. Other than that, I think this PR is good to be merged as well.

@a-hurst

a-hurst commented Dec 4, 2020

Copy link
Copy Markdown
Collaborator Author

Ah, whoops, messed the rebase process up. Let me try again.

@a-hurst

a-hurst commented Dec 4, 2020

Copy link
Copy Markdown
Collaborator Author

@sappelhoff Okay, everything should be good to go now! I also fixed some warnings I was getting from sphinxdoc when testing the changes I made to all the docstrings.

Comment thread docs/whats_new.rst Resolved
Comment thread docs/api.rst Resolved
Comment thread pyprep/prep_pipeline.py Resolved
Comment thread pyprep/utils.py Resolved

@sappelhoff sappelhoff left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Glad the rebase worked out at the second try :)

some minor nitpicks, then we are good to go!

@a-hurst

a-hurst commented Dec 4, 2020

Copy link
Copy Markdown
Collaborator Author

@sappelhoff Okay, hopefully that does it!

@sappelhoff
sappelhoff merged commit afc8190 into sappelhoff:master Dec 4, 2020
@sappelhoff

Copy link
Copy Markdown
Owner

Thanks a lot @a-hurst!

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.

4 participants