Skip to main content

Neutrino Interferometry - nu-waves

What is it?

Neutrino Interferometry, or nu_waves, is a simple Python library that calculate flavor oscillation of neutrinos. You can input your own parameters and get the oscillation probabilities.

How to install?

pip install nu-waves

Features

  • Embedded GPU acceleration (MPS, CUDA)
  • Oscillation framework with N neutrinos
  • Vacuum oscillations
  • Custom smearing function (L and E)
  • Constant matter MSW
  • Multi-layer matter MSW
  • Earth model (PREM) with cosz
  • Adiabatic transitions

Oscillation convention

The active three-flavor PMNS matrix uses the PDG convention, U_e3 = sin(theta13) * exp(-1j * deltaCP). The evolution operator stores S[energy, detected, emitted], while public probabilities retain the order P[energy, emitted, detected] = abs(S[energy, detected, emitted])**2 (singleton axes may be squeezed). Antineutrinos conjugate the mixing matrix and reverse the matter potential. Matter layers are ordered from source to detector.

The CP convention correction changes predictions from earlier implementations that transposed transition amplitudes. Remove any external phase-sign or channel-swap workarounds when adopting this correction, and regenerate affected predictions. The notebook notebooks/04_vacuum_executor_benchmarks.ipynb checks an independent PDG amplitude before benchmarking; tests/TestPdgConvention.py also covers matter, antineutrinos, layer ordering and decoherence.

Some nice pictures

vacuum_pmns.jpg matter_constant_test.jpg matter_prem_test.jpg adiabatic_sun_ssm_test.jpg vacuum_2d_pmns.jpg vacuum_2flavors.jpg

Examples

2 flavors oscillation in vacuum

import numpy as np
import matplotlib.pyplot as plt
from nu_waves.models.mixing import Mixing
from nu_waves.models.spectrum import Spectrum
from nu_waves.propagation.oscillator import Oscillator
from nu_waves.hamiltonian import vacuum
from nu_waves.utils import flavors

# sterile test
osc_amplitude = 0.1  # sin^2(2\theta)
angles = {(1, 2): np.arcsin(np.sqrt(osc_amplitude)) / 2}
dm2={(2, 1): 1}

mixing = Mixing(n_neutrinos=2, mixing_angles=angles)
spectrum = Spectrum(n_neutrinos=2, m_lightest=0., dm2={(2, 1): 1})
H = vacuum.Hamiltonian(
    mixing=mixing,
    spectrum=spectrum,
    antineutrino=False
)

# oscillator object that calculates the oscillation probability
osc = Oscillator(hamiltonian=H)

# get the oscillation probabilities
E_fixed = 3E-3
L_min, L_max = 1e-3, 20e-3
L_list = np.linspace(L_min, L_max, 200)
print(L_list)
P = osc.probability(
    L_km=L_list, E_GeV=E_fixed,
    flavor_emit=flavors.electron,
    flavor_det=flavors.electron  # muon could be sterile
)

# draw it
plt.figure(figsize=(6.5, 4.0))

plt.plot(L_list * 1000, P, label=r"$P_{e e}$ disappearance", lw=2)
plt.plot(L_list * 1000, [1] * len(L_list), "--", label="Total probability", lw=1.5)

plt.xlabel(r"$L_\nu$ [m]")
plt.ylabel(r"Probability")
plt.title(f"eV$^2$ sterile with $E_\\nu$ = {E_fixed * 1000} MeV")
# plt.xlim(L_min, L_max)
plt.ylim(0, 1.05)
plt.legend()
plt.tight_layout()
plt.show()

Analytic probability gradients

Vacuum, constant-density and layered matter Hamiltonians support physical parameter Jacobians through the same interface as probability evaluation:

from nu_waves.propagation.gradient import MixingAngle, DiracPhase, MassSquaredDifference

probabilities, gradients = osc.probability(
    L_km=295.0, E_GeV=energies,
    flavor_emit=flavors.muon, flavor_det=flavors.electron,
    parameterBasis=[MixingAngle(2, 3), DiracPhase(1, 3), MassSquaredDifference(3, 2)],
)

For constant matter, the basis may also contain density and electron fraction:

from nu_waves.propagation.gradient import MatterDensity, ElectronFraction

probabilities, gradients = osc.probability(
    events,
    parameterBasis=[MixingAngle(2, 3), MatterDensity(), ElectronFraction()],
)

The density derivative uses g/cm³ as its input unit; electron fraction is dimensionless. Each partial derivative holds the other parameters fixed. These parameters require a matter Hamiltonian and can be mixed, reordered or repeated in the basis. Their contributions are added directly to the Hamiltonian tangent, reusing the same eigendecomposition. No division by density or electron fraction is needed, so zero values are supported. Since the potential depends on their product, the derivatives satisfy rho * dP/drho = Ye * dP/dYe.

For layered profiles, select each density or electron fraction using an explicit zero-based layerIndex:

from nu_waves.hamiltonian.matter import MatterProfile

osc.hamiltonian.set_matter_profile(MatterProfile.from_fractions(
    rho_gcm3=[2.6, 4.1], Ye=[0.5, 0.47], fractions=[0.4, 0.6],
))
probabilities, gradients = osc.probability(
    events,
    parameterBasis=[MixingAngle(2, 3), MatterDensity(layerIndex=0),
                    ElectronFraction(layerIndex=1)],
)

Both fractional profiles and absolute segments (from_segments, lengths in km) are supported. Layers are applied in their declared traversal order. Layer widths remain fixed; oscillation parameters affect every layer, while an indexed matter parameter affects only its selected layer. A missing or invalid layer index is rejected for layered profiles. Constant-density media continue to use MatterDensity() and ElectronFraction() without an index.

Probability-only evaluation and gradients share the same layer-product kernel. Derivatives use d(U S) = dU S + U dS, reusing one eigendecomposition per layer and event for all requested parameters. No tangent arrays are allocated when parameterBasis is omitted. NumPy and Torch CPU/CUDA/MPS use the same kernels; MPS retains the backend's existing CPU fallback for eigendecomposition.

Parameterized variable-density profiles

ParameterizedMatterProfile samples a continuous density and electron fraction at fixed layer midpoints. In fractional slicing, coordinates run from 0 to 1 along the baseline; in absolute slicing, coordinates and edges are in km.

from nu_waves.matter.ParameterizedProfile import ParameterizedMatterProfile
from nu_waves.propagation.gradient import ProfileParameter

profile = ParameterizedMatterProfile(
    edges=np.linspace(0., 1., 33),
    parameters={"scale": 1., "slope": 0.8, "ye": 0.5},
    density=lambda x, p: p["scale"] * (2.6 + p["slope"] * x),
    electronFraction=lambda x, p: p["ye"],
    densityGradient=lambda x, p: {
        "scale": 2.6 + p["slope"] * x, "slope": p["scale"] * x,
    },
    electronFractionGradient=lambda x, p: {"ye": 1.},
)
osc.hamiltonian.set_matter_profile(profile)
probabilities, gradients = osc.probability(
    events,
    parameterBasis=[MixingAngle(2, 3), ProfileParameter("scale"),
                    ProfileParameter("slope"), ProfileParameter("ye")],
)

Metadata

Release files for nu-waves 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nu-waves 1.3.0
File Size Uploaded Provenance Actions
nu_waves-1.3.0.tar.gz 48.2 kB With provenance Details for nu_waves-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nu-waves 1.3.0
File Interpreter ABI Platform Actions
nu_waves-1.3.0-py3-none-any.whl Python 3 none any Details for nu_waves-1.3.0-py3-none-any.whl

Total release size: 107.9 kB

Release files / nu_waves-1.3.0.tar.gz

Download URL nu_waves-1.3.0.tar.gz
Size 48.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ad9950e0d3a4c327b5bf024c588977926ce01e7cec52db3cd8f1e65660095f48
BLAKE2b-256 checksum
How to use checksums
be15d8929b5fdef797a6c40c764477954801ec93d01eadec6acffafb758bb664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / nu_waves-1.3.0-py3-none-any.whl

Download URL nu_waves-1.3.0-py3-none-any.whl
Size 59.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4c7bb5ea7842956370311b0d9c8517785c82b863ad910445b07b4645529dfa2
BLAKE2b-256 checksum
How to use checksums
a39bd2bee35a28832247775d3af23f5c78d74805024de38a72a353caa880b8ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for nu-waves 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nu_waves-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page