Skip to content

FEAT: add precessing spin transformation - #1104

Open
ColmTalbot wants to merge 12 commits into
bilby-dev:mainfrom
ColmTalbot:precessing-spin-transform
Open

FEAT: add precessing spin transformation#1104
ColmTalbot wants to merge 12 commits into
bilby-dev:mainfrom
ColmTalbot:precessing-spin-transform

Conversation

@ColmTalbot

Copy link
Copy Markdown
Collaborator

This is a replacement for #1044 that includes the backend changes rather than attempting to rebase.

@ColmTalbot
ColmTalbot requested a review from a team June 26, 2026 16:04
@ColmTalbot ColmTalbot added enhancement New feature or request >100 lines labels Jun 26, 2026

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

Broadly looks good to me - albeit the checks are failing

Comment thread bilby/gw/geometry.py
Comment thread bilby/gw/geometry.py Outdated
@ColmTalbot
ColmTalbot force-pushed the precessing-spin-transform branch 2 times, most recently from 7a82a82 to 6b7f838 Compare July 6, 2026 17:39
@ColmTalbot
ColmTalbot force-pushed the precessing-spin-transform branch from 1c0807a to 34fcfc3 Compare August 11, 2026 18:11
@ColmTalbot
ColmTalbot requested a review from a team August 11, 2026 18:45

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

I like this change! I am worried about regressions that it introduces though. Quick checks run on my laptop show that this could make up ~10% of a single phenomPv2 call, as opposed to <1% before. It might be an okay tradeoff in anticipation of future developments. Any thoughts @ColmTalbot?

Also, I was a bit surprised to find the function in geometry.py. I have always assumed that it pertains to detector geometry and location. Not totally opposed to this being in geometry.py, but I still think it fits better in conversion.py.

Comment thread bilby/gw/source.py
Comment on lines +146 to +155
try:
iota, spin_1x, spin_1y, spin_1z, spin_2x, spin_2y, spin_2z = bilby_to_lalsimulation_spins(
theta_jn=theta_jn, phi_jl=phi_jl, tilt_1=tilt_1, tilt_2=tilt_2,
phi_12=phi_12, a_1=a_1, a_2=a_2, mass_1=mass_1, mass_2=mass_2,
reference_frequency=reference_frequency, phase=phase)
except ZeroDivisionError:
if catch_waveform_errors:
return None
else:
raise

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.

Would it be possible to abstract this out to a separate function? It is repeated three times in the same file.

Comment thread bilby/gw/geometry.py
"three_by_three_matrix_contraction",
"time_delay_geocentric",
"time_delay_from_geocenter",
"zenith_azimuth_to_theta_phi",

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 transform_precessing_spins should be added here.

@ColmTalbot

ColmTalbot commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator Author

@adivijaykumar, thanks! I'm happy to move it.

Quick checks run on my laptop show that this could make up ~10% of a single phenomPv2 call, as opposed to <1% before.

I hadn't thought to properly benchmark this, but it makes sense to.
I made some changes to try to work around some numpy allocation penalties for small arrays.
I've pasted in some profiling data before and after my most recent changes.
I now find that this is <1% of the waveform call for the fast tutorial.
I guess this will slow down the extremely fast likelihoods a little, but hopefully we can shift those over to jax or pytorch where we can just compile this away.
Most of the gains come from removing xp.stack which does various shape checks.

image image

@ColmTalbot
ColmTalbot force-pushed the precessing-spin-transform branch from 34fcfc3 to e8dab28 Compare August 17, 2026 18:29
@adivijaykumar

Copy link
Copy Markdown
Collaborator

Thanks @ColmTalbot! This is encouraging. I had performed the test by making waveform calls over a bunch of parameters, but I agree that one of the tutorials is probably the best to benchmark this. I also found really massive improvements with jax calls over a large number of parameters (even on CPU), so I am in favor of adding this in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request >100 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants