Skip to main content

Numerical leapfrog solvers for scalar-induced gravitational waves.

Project description

SimuSIGW

Small numerical package for evolving scalar-induced gravitational-wave source fields on periodic 3-D grids.

Backends

  • run_evolution: CPU FFT pseudospectral backend.
  • run_evolution_fd: CPU Numba finite-difference backend, with fd_order=2 or fd_order=4.
  • run_evolution_torch: optional PyTorch dense Fourier-matrix backend for the original GPU-style calculation.
  • run_evolution_torch_fft: optional PyTorch FFT pseudospectral backend.

Install

pip install -e .

For the optional PyTorch backend, install a PyTorch build that matches your CUDA setup. If you use the package metadata extra:

pip install -e ".[gpu]"

Custom Model

Users provide a dimensional power spectrum function power_spectrum(k) and, optionally, a non-Gaussian transform non_gaussian_transform(zeta_g).

import numpy as np

from SimuSIGW import (
    EvolutionConfig,
    gaussian_random_fields,
    run_evolution_fd,
)


def my_power_spectrum(k):
    kstar = 20.0
    width = 0.1
    amplitude = 1e-2
    return (
        amplitude
        * (1 / kstar) ** 3
        / (np.sqrt(2 * np.pi) * width)
        * np.exp(-((k / kstar - 1) ** 2) / (2 * width**2))
        * (2 * np.pi**2)
    )


def my_non_gaussian_transform(zeta_g):
    return zeta_g + 0.5 * (zeta_g**2 - np.mean(zeta_g**2))


config = EvolutionConfig(
    n=128,
    max_steps=1000,
    output_every=1000,
    output_path="log/custom_run",
    workers=-1,
    fd_order=4,
    save_initial=False,
)

field_g, phi_initial = gaussian_random_fields(
    config.n,
    power_spectrum=my_power_spectrum,
    non_gaussian_transform=my_non_gaussian_transform,
    seed=1234,
    workers=config.workers,
    dtype=config.dtype,
)

final_state = run_evolution_fd(phi_initial, config)

The default non-Gaussian transform is the logarithmic transform used in the original notebook. For exploratory finite-difference runs, dtype=np.float32 can be faster; use np.float64 for reference runs.

GPU Backend

from SimuSIGW import run_evolution_torch

final_state = run_evolution_torch(phi_initial, config, device="cuda")

The dense backend follows the original Fourier differentiation-matrix approach. For larger grids, prefer the FFT backend:

from SimuSIGW import run_evolution_torch_fft

config = EvolutionConfig(...)
final_state = run_evolution_torch_fft(
    phi_initial,
    config,
    device="cuda",
    dtype=np.float32,  # or np.float64
)

Both PyTorch backends accept dtype=np.float32 or dtype=np.float64. If omitted, they use config.dtype. Choose np.float32 for speed and lower GPU memory use, or np.float64 for reference runs. They are optional and import PyTorch only when called.

Benchmarks

python benchmark_leapfrog_workers.py
python benchmark_leapfrog_backends.py
python benchmark_torch_backends.py --dtype float32
python benchmark_torch_backends.py --dtype float64 --skip-dense

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

simusigw-0.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simusigw-0.1.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file simusigw-0.1.0.tar.gz.

File metadata

  • Download URL: simusigw-0.1.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for simusigw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 37bde376ef679ece26e4e92bf8446a717c00a4a0f84c7ff10618bb3e44da1801
MD5 8fbe2778de1abe3a462fcf22cc8d1081
BLAKE2b-256 ff5e80904c07ea9bada16fdff67a5338e17d37706f6d0362f05f832d01ab8232

See more details on using hashes here.

File details

Details for the file simusigw-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: simusigw-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for simusigw-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21d59afd4b9b3d3f1130d492738805389b7fb823c6bfda23056b8cc7a7cd2f32
MD5 23ac76ffe8bc4e398584217cbb2fd899
BLAKE2b-256 8f9d57725d4768cc155e4b63b7df8bf5beba4b52011199b9dd52a50656c6be66

See more details on using hashes here.

Supported by

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