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

SNR optimisation options for pycbc_live #4432

Merged
merged 24 commits into from
Sep 12, 2023

Conversation

ArthurTolley
Copy link
Contributor

This is a recreation of #4398 which is now closed due to my mistake of creating the PR using Gareth's branch and then not being able to make changes to that branch.

This PR includes a new directory containing two new files:
pycbc/live -> __init__.py + snr_optimizer.py

snr_optimizer.py contains the functions required to do the snr optimization (the snr optimizers themselves, but not the boundary calculations)

The following two files have also been modified:
pycbc_live - includes the new snr_optimizer options group.
pycbc_optimize_snr - removing the functionality that has been moved to snr_optimizer.py

I am yet to fully test these changes and will do so pronto.

pycbc/live/snr_optimizer.py Outdated Show resolved Hide resolved
@ArthurTolley
Copy link
Contributor Author

Currently the example in examples/live/run.sh works with --optimizer pso but when using differential_evolution there is an issue with the command line options. Giving the two differential evolution options, maxiter and popsize, there is a bug when trying to run the optimizer which says:
pycbc_optimize_snr: error: unrecognized arguments: --differential_evolution-maxiter 50.0 --differential_evolution-popsize 100.0

I've looked at how the option group is generated and the option group looks fine, I'm thinking maybe there is an issue with how the option is being passed from the command line in to the program. Not sure and i can't figure it out.

@ArthurTolley
Copy link
Contributor Author

Another comment, I've had to explicitly make the inputs to some of the functions within snr_optimizer ints because the option group creating function makes them all floats. I will try and modify this function to make them require ints for those functions otherwise the --help descriptions will be wrong.

Copy link
Contributor

@GarethCabournDavies GarethCabournDavies left a comment

Choose a reason for hiding this comment

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

As this is moving a lot of code into a new module, we will lose the blame information. So it is easy(ish) to find, here's the LINK

(It may be good to add this to the description)

pycbc/live/snr_optimizer.py Outdated Show resolved Hide resolved
@GarethCabournDavies
Copy link
Contributor

Currently the example in examples/live/run.sh works with --optimizer pso but when using differential_evolution there is an issue with the command line options. Giving the two differential evolution options, maxiter and popsize, there is a bug when trying to run the optimizer which says: pycbc_optimize_snr: error: unrecognized arguments: --differential_evolution-maxiter 50.0 --differential_evolution-popsize 100.0

Looks like the options above have underscores where they should have hyphens

@ArthurTolley
Copy link
Contributor Author

@GarethCabournDavies They do but I don't know why they do. Surely unrecognized arguments means it's being given the wrong arguments but I'm giving it arguments which have hyphens and not underscores.

@ArthurTolley ArthurTolley requested a review from tdent July 18, 2023 09:32
pycbc/live/snr_optimizer.py Outdated Show resolved Hide resolved
pycbc/live/snr_optimizer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tdent tdent left a comment

Choose a reason for hiding this comment

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

Only a few formatting / comment requests

@GarethCabournDavies
Copy link
Contributor

So far as I can tell, we just need someone to merge it - @ArthurTolley, is that right?

@ArthurTolley
Copy link
Contributor Author

I made some more changes in response to comments made in some of the conversations still not marked 'resolved', mainly regarding naming conventions I believe. I think I did ask for one final review but it's been a while. If it all looks good then another ✅ would be all I need to hit the merge button.

I'm pretty sure it's all tested but if I get some time tomorrow I can re-do all the tests just to triple check.

@tdent tdent requested a review from titodalcanton September 11, 2023 14:34
@tdent
Copy link
Contributor

tdent commented Sep 12, 2023

Codeclimate has some weird looking error ..

warning: Could not find remote branch live_options to clone.
fatal: Remote branch live_options not found in upstream origin

@ArthurTolley
Copy link
Contributor Author

That is a really weird error, as far as I can tell the branch should be available 🤷🏻‍♂️

@ArthurTolley ArthurTolley enabled auto-merge (squash) September 12, 2023 14:59
@spxiwh
Copy link
Contributor

spxiwh commented Sep 12, 2023

CodeClimate is visible now, and it does need some placating :-)

@spxiwh
Copy link
Contributor

spxiwh commented Sep 12, 2023

... Although it's probably the case that most of these issues are from me, not from this patch. So maybe not fair to enforce that.

@ArthurTolley
Copy link
Contributor Author

I did clean the codeclimate of any issues relating to this PR.

@tdent
Copy link
Contributor

tdent commented Sep 12, 2023

@spxiwh @ArthurTolley why are we using numpy.random.mtrand._rand ? Isn't there a more 'standard' way to get a random number?

@tdent
Copy link
Contributor

tdent commented Sep 12, 2023

Out of the remaining codeclimate whines, I think removing the unused argparse import is worth noting

@GarethCabournDavies
Copy link
Contributor

@spxiwh @ArthurTolley why are we using numpy.random.mtrand._rand ? Isn't there a more 'standard' way to get a random number?

Thats from a previous PR - #4393, but its basically one of a few ways of getting the global random state (see https://stackoverflow.com/a/41985898)

@tdent
Copy link
Contributor

tdent commented Sep 12, 2023

(should be fixed now)

@ArthurTolley
Copy link
Contributor Author

@tdent Thank you for that, I'm getting some strange problems with trying to use VSCode today and I'm really rusty using the terminal to do changes.

@ArthurTolley ArthurTolley enabled auto-merge (squash) September 12, 2023 16:48
@ArthurTolley ArthurTolley merged commit 5542985 into gwastro:master Sep 12, 2023
@ArthurTolley ArthurTolley deleted the live_options branch September 14, 2023 11:21
jakeb245 pushed a commit to jakeb245/pycbc that referenced this pull request Sep 28, 2023
* Moving the live optimizer option changes to my own branch

* Completing the snr optimization argument group

* updating pycbc_live

* re-adding bug fix

* removing TODO message

* Bug with d_e options

* Adding optimizer-seed

* fixing the d_e optimizer

* replacing run.sh code

* resolve merge conflict

* fixing run.sh

* cleaning up args_to_string func

* changing comment

* codeclimate fixes

* module docstring

* Update module docstring copyright

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Add gareth

* removing argv

* argument changing

* removing duplicated arguments

* minor CC points

* remove bug introduced when making CC happier

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>
GarethCabournDavies added a commit to GarethCabournDavies/pycbc that referenced this pull request Oct 11, 2023
* Moving the live optimizer option changes to my own branch

* Completing the snr optimization argument group

* updating pycbc_live

* re-adding bug fix

* removing TODO message

* Bug with d_e options

* Adding optimizer-seed

* fixing the d_e optimizer

* replacing run.sh code

* resolve merge conflict

* fixing run.sh

* cleaning up args_to_string func

* changing comment

* codeclimate fixes

* module docstring

* Update module docstring copyright

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Add gareth

* removing argv

* argument changing

* removing duplicated arguments

* minor CC points

* remove bug introduced when making CC happier

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>
PRAVEEN-mnl pushed a commit to PRAVEEN-mnl/pycbc that referenced this pull request Nov 3, 2023
* Moving the live optimizer option changes to my own branch

* Completing the snr optimization argument group

* updating pycbc_live

* re-adding bug fix

* removing TODO message

* Bug with d_e options

* Adding optimizer-seed

* fixing the d_e optimizer

* replacing run.sh code

* resolve merge conflict

* fixing run.sh

* cleaning up args_to_string func

* changing comment

* codeclimate fixes

* module docstring

* Update module docstring copyright

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Add gareth

* removing argv

* argument changing

* removing duplicated arguments

* minor CC points

* remove bug introduced when making CC happier

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>
titodalcanton pushed a commit to titodalcanton/pycbc that referenced this pull request Jan 19, 2024
* Moving the live optimizer option changes to my own branch

* Completing the snr optimization argument group

* updating pycbc_live

* re-adding bug fix

* removing TODO message

* Bug with d_e options

* Adding optimizer-seed

* fixing the d_e optimizer

* replacing run.sh code

* resolve merge conflict

* fixing run.sh

* cleaning up args_to_string func

* changing comment

* codeclimate fixes

* module docstring

* Update module docstring copyright

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Add gareth

* removing argv

* argument changing

* removing duplicated arguments

* minor CC points

* remove bug introduced when making CC happier

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>
titodalcanton added a commit that referenced this pull request Feb 6, 2024
* Remove reference to relative_example in docs

* Use RTLD_GLOBAL for libgomp (#4353)

* Use RTLD_GLOBAL for libgomp

In conda-forge/pycbc-feedstock#74 it was suggested to use RTLD_GLOBAL for libgomp. Let's see if this works fine with the test suite (which should answer @josh-willis 's concerns).

* Move import of ctypes/gomp into __enter__

* Try this

* Revert "Revert "Allow SNR optimizer to use candidate point in initial array (#4393)""

This reverts commit 7be12f1.

We are now catching up with master, where the bug originally introduced
by #4393 is fixed properly, so here I am undoing the temporary fix.

* SNR optimisation options for pycbc_live (#4432)

* Moving the live optimizer option changes to my own branch

* Completing the snr optimization argument group

* updating pycbc_live

* re-adding bug fix

* removing TODO message

* Bug with d_e options

* Adding optimizer-seed

* fixing the d_e optimizer

* replacing run.sh code

* resolve merge conflict

* fixing run.sh

* cleaning up args_to_string func

* changing comment

* codeclimate fixes

* module docstring

* Update module docstring copyright

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Add gareth

* removing argv

* argument changing

* removing duplicated arguments

* minor CC points

* remove bug introduced when making CC happier

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>

* Improvements to single-detector trigger fitting code for PyCBC Live (#4486)

* Cleanup

* Cleanup

* Refactor duration bin parsing code and add support for reading from bank

* Minor fix/cleanup to logging

* Update CLI checks for duration bins

* Cleanup

* Ignore inconsistent config when combining

* Fix bug

* Fix typo

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Comment from Gareth

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* [pycbc live] Don't add snr options to command if they don't exist (#4518)

* Don't run snr optimizer setup if not optimizing snr

* moving the check to a more appropraite place

* setting snr_opt_options to None if not optimizing

* [pycbc live] Allowing the use of psd variation in the ranking statistic for pycbc live (#4533)

* Modifying files to include psd variation in single detector statistic calculation

* ending variation.py with a blank line

* Changing to an increment agnostic solution

* removing change already fixed

* Updating function names and docstrings

* removing ToDos and adding more helpful comments

* Removing unused import

* Codeclimate fixes

* Removing excess logging and whitespace mistakes

* Removing unused objects + codeclimate fixes

* Updating comments and docstrings, removing matchedfilter changes

* Revert "Updating comments and docstrings, removing matchedfilter changes"

This reverts commit 0e6473a.

* Removing matchedfilter changes, updating comments and docstrings

* Move --verbose to the end of the commands

* more comment updates

* Repositioning filter recreation

* Changes to comments and removing whitespace

Co-authored-by: Thomas Dent <[email protected]>

* removing refchecks

* Adding option veification for psd variation

* Apply suggestions from code review

Co-authored-by: Thomas Dent <[email protected]>

* fixing EOL error

* Refactoring the filter creation function

* codeclimate fixes

* undo

* full_filt func

* removing indentation

* code climate

* code climate

* try to quiet codeclimate

* codeclimate doesn't know PEP8

* brackets obviate line continuation

---------

Co-authored-by: Thomas Dent <[email protected]>

* added scaling of initial pop in snr_optimizer (#4561)

* added scaling of initial pop

* init popn in optimize_di & pso func

* added changes in optimize_pso

* usig logging.debug for snr

* Do not set matplotlib's backend in internal modules (#4592)

* Set version to 2.1.4

* Remove reference to single_template_examples in docs

* Remove reference to hierarchical_model in docs

* Live: produce empty trigger fit plot for detectors with no triggers (#4600)

* Live: produce empty trigger fit plot for detectors with no triggers

* allow for below-threshold triggers

* fix thinko in option parsing for defaults (#4615)

* fix thinko in option parsing for defaults

When an option is not given at all getattr on the args object gives None, but we don't want to translate that into "--option-name None" on the command line.

* bugfix 

obviously we needed to define 'key_name' first ..

* Improvements to single fit plots (#4509)

* Improvements to single fit plots

* Apply suggestions from Gareth

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

---------

Co-authored-by: Ian Harry <[email protected]>
Co-authored-by: Arthur Tolley <[email protected]>
Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>
Co-authored-by: Praveen Kumar <[email protected]>
bhooshan-gadre pushed a commit to bhooshan-gadre/pycbc that referenced this pull request Mar 4, 2024
* Moving the live optimizer option changes to my own branch

* Completing the snr optimization argument group

* updating pycbc_live

* re-adding bug fix

* removing TODO message

* Bug with d_e options

* Adding optimizer-seed

* fixing the d_e optimizer

* replacing run.sh code

* resolve merge conflict

* fixing run.sh

* cleaning up args_to_string func

* changing comment

* codeclimate fixes

* module docstring

* Update module docstring copyright

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Add gareth

* removing argv

* argument changing

* removing duplicated arguments

* minor CC points

* remove bug introduced when making CC happier

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>
acorreia61201 pushed a commit to acorreia61201/pycbc that referenced this pull request Apr 4, 2024
* Moving the live optimizer option changes to my own branch

* Completing the snr optimization argument group

* updating pycbc_live

* re-adding bug fix

* removing TODO message

* Bug with d_e options

* Adding optimizer-seed

* fixing the d_e optimizer

* replacing run.sh code

* resolve merge conflict

* fixing run.sh

* cleaning up args_to_string func

* changing comment

* codeclimate fixes

* module docstring

* Update module docstring copyright

Co-authored-by: Gareth S Cabourn Davies <[email protected]>

* Add gareth

* removing argv

* argument changing

* removing duplicated arguments

* minor CC points

* remove bug introduced when making CC happier

---------

Co-authored-by: Gareth S Cabourn Davies <[email protected]>
Co-authored-by: Thomas Dent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants