Skip to content

TST: change all likelihood and waveform tests to use more recent waveforms (#791) - #897

Open
akjm99 wants to merge 16 commits into
bilby-dev:mainfrom
akjm99:update-waveforms-in-tests
Open

akjm99 wants to merge 16 commits into
bilby-dev:mainfrom
akjm99:update-waveforms-in-tests

Conversation

@akjm99

@akjm99 akjm99 commented Jan 29, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

@akjm99 akjm99 linked an issue Jan 29, 2025 that may be closed by this pull request
@akjm99
akjm99 requested a review from GregoryAshton January 29, 2025 16:28

@GregoryAshton GregoryAshton 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.

Overall looks good thanks @akjm99. Just need to revert the cases where it is using an ROQ.


trial_roq_paths = [
"/roq_basis",
os.path.join(os.path.expanduser("~"), "ROQ_data/IMRPhenomPv2/4s"),

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.

Here, I don't think we have ROQ data for XPHM yet, so this will need to be reverted (and may be why the CI is failing).

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.

@mj-will I assume #897 was a "move towards" modern waveforms and it is okay to use the older waveforms for the ROQs to avoid having to figure out how to package them?

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.

Yes, I think that's fine.

I'll note there is definitely ROQ data for XPHM on CIT but I don't think it's public (and is also huge).

Comment thread test/gw/likelihood_test.py Outdated
# Possible locations for the ROQ: in the docker image, local, or on CIT
trial_roq_paths = [
"/roq_basis",
os.path.join(os.path.expanduser("~"), "ROQ_data/IMRPhenomPv2/4s"),

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.

Same as the case above

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.

And applied to the comments as well

Comment thread test/gw/likelihood_test.py Outdated
# Possible locations for the ROQ: in the docker image, local, or on CIT
trial_roq_paths = [
"/roq_basis",
os.path.join(os.path.expanduser("~"), "ROQ_data/IMRPhenomPv2/4s"),

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.

And again.

Comment thread test/gw/likelihood_test.py Outdated
# Possible locations for the ROQ: in the docker image, local, or on CIT
trial_roq_paths = [
"/roq_basis",
os.path.join(os.path.expanduser("~"), "ROQ_data/IMRPhenomPv2/4s"),

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.

And here

@mj-will

mj-will commented Feb 4, 2025

Copy link
Copy Markdown
Collaborator

@akjm99 it looks like a commit from main has made it into the branch and is showing in the diff. I don't think it's from a merge or rebase so I'm slightly unsure what's happened to the history. @GregoryAshton any ideas?

@akjm99
akjm99 requested a review from GregoryAshton February 4, 2025 13:41
@akjm99

akjm99 commented Feb 4, 2025 •

Copy link
Copy Markdown
Collaborator Author

Hi @mj-will. I am not sure how that happened sorry! I followed the contributing guidelines which said to pull upstream, make edits, and then push to fork (?). When I tried to push my changes to my fork, it said there were conflicts and that I had to merge my new changes and merge/rebase my branch to my main (?) (which I think I managed to do, at least I was able to push to my fork after that...)

@mj-will mj-will added the testing label Feb 4, 2025
@mj-will

mj-will commented Feb 4, 2025

Copy link
Copy Markdown
Collaborator

Hi @mj-will. I am not sure how that happened... I followed the contributing guidelines which said to pull upstream. When I tried to push my changes to my fork, it then said there were conflicts and that I had to merge my new changes and merge/rebase my branch to main (?) (which I think I managed to do, at least I was able to push to my fork after that...)

Hmm, I think the upstream changed between you initially making the branch and now (the commit is from another recent PR). I think you've followed the contributing guidelines correctly but we're missing a section on updating a PR with changes from main after it has been made. I've opened an issue to track this: #901.

Given we'll squash, this probably doesn't matter in this case, and it's probably more work to fix than it's worth.

@mj-will

mj-will commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

@akjm99 do you have time to have another look at this? I think ROQ tests just need switch to IMRPhenomPv2.

Comment thread test/gw/source_test.py
frequency_nodes_linear=fnodes_linear,
frequency_nodes_quadratic=fnodes_quadratic,
reference_frequency=50.0,
waveform_approximant="IMRPhenomPv2",

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.

I think this line should be using IMRPhenomPv2 since we are passing in the ROQ terms just above

@mj-will

mj-will commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Hi @akjm99 do you have capacity to have another look at this? Unfortunately, I can't see what the test failures are but hopefully it's an easy fix.

@akjm99

akjm99 commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

Hi @mj-will, apologies; I thought I had managed to fix this already! I think you should be able to see the tests again now. Some of the unit tests are failing, but I am unsure why. I have a lot of work at the moment, but I will have another go at trying to debug this after I am back from the LVK.

GregoryAshton and others added 2 commits October 14, 2026 20:29
Switching the test suite to IMRPhenomXPHM (PR bilby-dev#897) exposed two issues:

- catch_waveform_errors only matched the exact IMRPhenomPv2 EDOM string, so
  out-of-domain errors from XPHM (XLAL_EFUNC) and XAS/D (XLAL_EINVAL) leaked
  out instead of returning None. Add a shared _is_waveform_domain_error helper
  recognising all three LAL domain-error codes, applied at all three
  catch_waveform_errors sites.

- test_lalsim_SimInspiralChooseFDWaveform passed raw SI numbers as masses
  (~35 kg). Pv2 tolerated this but XPHM aborts the process. Scale the masses
  by lal.MSUN_SI so the inputs are physical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@GregoryAshton

Copy link
Copy Markdown
Collaborator

@akjm99 and @mj-will, I got my French friend to look at this, and it turns out it is more interesting than just a CI failure. In short, it surfaced that we are not handling LALSimulation waveform errors well.

Root cause of the failing tests on #897

Switching the test suite from IMRPhenomPv2 to IMRPhenomXPHM/the X-family exposed two distinct problems, because XPHM reports bad inputs differently than Pv2 did.

1. catch_waveform_errors no longer caught domain errors (library bug)

TestRelbinBBH::test_waveform_error_catching_binned feeds a negative mass with catch_waveform_errors=True and expects the source model to return None. The error-swallowing logic in bilby/gw/source.py only matched the exact Pv2 error string:

EDOM = (e.args[0] == 'Internal function call failed: Input domain error')

Different approximants surface an out-of-domain point through different XLAL error codes:

Approximant Exception message LAL code Caught before?
IMRPhenomPv2 / XP Internal function call failed: Input domain error XLAL_EDOM ✅
IMRPhenomXPHM (freq. sequence) Internal function call failed XLAL_EFUNC ❌
IMRPhenomXAS / D Invalid argument XLAL_EINVAL ❌

So with XPHM the error propagated instead of being converted to a -inf likelihood, and the test failed.

Fix: a shared _is_waveform_domain_error() helper that recognises all three LAL domain-error messages, applied at all three catch_waveform_errors sites (standard FD path, frequency-sequence/relative-binning path, and the gwsignal path). This also closes a latent gap where XAS/D (Invalid argument) errors were never caught on the standard path.

2. Unit test fed unphysical masses (test bug)

test/gw/utils_test.py::test_lalsim_SimInspiralChooseFDWaveform passed raw SI numbers as the masses, so mass_1=35.2 meant 35.2 kg (~3×10⁻²⁹ M☉). IMRPhenomPv2 tolerated these nonsense values, but IMRPhenomXPHM aborts the process (SIGKILL) on them — which is why the run died mid-test with no traceback.

Fix: scale the masses by lal.MSUN_SI so the test passes physically valid inputs.

The XLAL_EFUNC message ("Internal function call failed") is fairly generic, so catch_waveform_errors=True now swallows a slightly broader class of nested LAL failures as -inf. This is consistent with the feature's intent (opt-in robustness during sampling),

The pre-commit pretty-format-toml hook (v2.14.0) now adds spaces inside
inline-table braces. These files predated that style, causing the
pre-commit CI job to fail. Purely cosmetic; no semantic changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@GregoryAshton

Copy link
Copy Markdown
Collaborator

We now have one failure in the CI

FAILED test/gw/likelihood/roq_test.py::TestROQLikelihood::test_create_roq_weights_with_params - AssertionError: np.float64(407.93544108302456) != np.float64(407.93544108302467)
= 1 failed, 512 passed, 895 skipped, 59 warnings, 3 rerun in 576.63s (0:09:36) =

Tagging @ColmTalbot and @mj-will - can we just found these numbers as it looks like floating point precession rounding?

@ColmTalbot

Copy link
Copy Markdown
Collaborator

We now have one failure in the CI

FAILED test/gw/likelihood/roq_test.py::TestROQLikelihood::test_create_roq_weights_with_params - AssertionError: np.float64(407.93544108302456) != np.float64(407.93544108302467) = 1 failed, 512 passed, 895 skipped, 59 warnings, 3 rerun in 576.63s (0:09:36) =

Tagging @ColmTalbot and @mj-will - can we just found these numbers as it looks like floating point precession rounding?

Yeah, happy to make these almost equal at some sensible level.

@ColmTalbot

Copy link
Copy Markdown
Collaborator

I think we had deliberately not caught all of these previously, for example, is the error for the aligned waveforms due to passing precessing spins? I think we should not catch this error.

GregoryAshton and others added 2 commits October 15, 2026 21:34
The two log-likelihood ratios can differ at the level of floating-point
round-off, causing the exact equality check to fail on CI.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@GregoryAshton

Copy link
Copy Markdown
Collaborator

I think we had deliberately not caught all of these previously, for example, is the error for the aligned waveforms due to passing precessing spins? I think we should not catch this error.

Good point @ColmTalbot I've now pushed a change which reverts the catching of "Invalid argument". There is a comment blocki above it which describes the behaviour - let me know if you prefer that to be removed. I then decided to add a test checking the behaviour across the different possible errors to check we are understand how the likelihood is behaving. I can update the PR accordingly if people are happy with this. Or I can remove it.

This branch has not been deployed

No deployments
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.

Change all likelihood and waveform tests to use more recent waveforms

4 participants