Skip to main content

Optimized functionality for Bilby

Project description

pipeline status coverage report Latest Release Conda Forge License

bilby-cython

Optimized cython implementations of specific Bilby operations.

For very fast waveform models, computing the antenna response and time delays uses a significant amount of run time, see, e.g., this issue.

This repo provides optimized cython implementations of the existing Python functions. Most of the speed up comes from leveraging the fact that these are operations of 3-element vectors.

Installation

bilby.cython is available through conda-forge and pypi and can be installed with either of the following

$ conda install -c conda-forge bilby.cython
$ python -m pip install bilby.cython

There are prebuilt versions for many architectures/OSs, however, non-standard systems will require a version of Cython to build from the source with

Usage

In order to use the functions implemented here you can import them from the bilby.cython package

from bilby_cython import geometry
geometry.get_polarization_tensor(ra=0.0, dec=0.0, time=0.0, psi=0.0, mode="plus")

Ported functions

  • time_delay_geocentric: calculating time delays between two interferometers
  • get_polarization_tensor: calculation of polarization tensors
  • three_by_three_matrix_contraction: rojecting polarization tensors against detector response tensors
  • calculate_arm: calculate an interferometer arm vector
  • zenith_azimuth_to_theta_phi: rotating the reference from from detector-based coordinates to celestial

New functions

  • time_delay_from_geocenter: calculate the time delay between an interferometer and the geocenter. This removes an array allocation that was slow for some reason.
  • get_polarization_tensor_multiple_modes: compute multiple polarization tensors in a single function call. This reduces the overheads per call.

Testing

test/test_geometry.py verifies that the new functions agree with the old versions at sufficient precision. The old code is deliberately copied from the current Bilby to enable testing after Bilby switches to use this code.

Timing

This is the output of test/timing.py when run on a 2020 M1 MacBook Pro. The new functions are 5-40x faster than the old versions. These times are comparable with the lal` equivalents with greater flexibility.

Timing time delay calculation over 10000 trials.
Cython time: 2.366e-06
Numpy time: 1.026e-05
Timing polarization tensor calculation over 1000 trials.
Cython time: 2.470e-06
Numpy time: 4.247e-05
Timing two mode polarization tensor calculation over 1000 trials.
Cython time: 1.790e-06
Numpy time: 2.907e-05
Timing six mode polarization tensor calculation over 1000 trials.
Cython time: 1.250e-06
Numpy time: 4.111e-05
Timing antenna response calculation over 1000 trials.
Cython time: 4.269e-06
Numpy time: 4.709e-05
Timing frame conversion calculation over 1000 trials.
Cython time: 2.516e-06
Numpy time: 2.243e-05

Profiling the standard Bilby fast_tutorial.py example for a very fast waveform model reduces the amount of time spent computing the antenna response from 16% to 3% and computing time delays from 3% to 1%.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bilby_cython-0.5.0.tar.gz (326.3 kB view hashes)

Uploaded Source

Built Distributions

bilby.cython-0.5.0-cp311-cp311-win_amd64.whl (497.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

bilby.cython-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

bilby.cython-0.5.0-cp311-cp311-macosx_12_0_x86_64.whl (487.8 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ x86-64

bilby.cython-0.5.0-cp310-cp310-win_amd64.whl (497.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

bilby.cython-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

bilby.cython-0.5.0-cp310-cp310-macosx_12_0_x86_64.whl (487.8 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

bilby.cython-0.5.0-cp39-cp39-win_amd64.whl (498.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

bilby.cython-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

bilby.cython-0.5.0-cp39-cp39-macosx_12_0_x86_64.whl (489.0 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

bilby.cython-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

bilby.cython-0.5.0-cp38-cp38-macosx_12_0_x86_64.whl (488.0 kB view hashes)

Uploaded CPython 3.8 macOS 12.0+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page