Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

At-rest theta conversions return NaN energy or mass

Aperta
#752 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@vera-rubin ci sta già lavorando.

Dal 19/10/2026.

  • #753 di @vera-rubin — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
backend

Direzione di ricerca

Start with the theta branches in src/vector/_compute/spatial/mag2.py and src/vector/_compute/spatial/mag.py, which the issue identifies as dividing zero by zero at the origin. Reproduce the failure with the supplied script across object and NumPy backends, then inspect the coordinate conversion paths that use these calculations. Done means all eight conversions return energy or mass 5 without NaN.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Converting a finite particle at rest to theta coordinates gives NaN energy or mass instead of 5.

Vector Version

Version: 1.9.1.dev4+gcaf34cddf from source at caf34cddf9fa2cebc4d9c8c7ed090006ed4687cc, NumPy 2.5.4 and 1.26.4, SymPy 1.14.0

Python Version

Python 3.12.3.

OS / Environment

Linux x86_64.

Describe the bug

Save the script below as repro.py and run:

git clone https://github.com/scikit-hep/vector.git vector
git -C vector checkout --detach caf34cddf9fa2cebc4d9c8c7ed090006ed4687cc
python3 -m venv venv
venv/bin/python -m pip install --only-binary=:all: numpy==2.5.4 sympy==1.14.0 mpmath==1.3.0
venv/bin/python -m pip install -e ./vector
venv/bin/python repro.py

The old NumPy stack fails the same way:

python3 -m venv venv-old
venv-old/bin/python -m pip install --only-binary=:all: numpy==1.26.4 sympy==1.14.0 mpmath==1.3.0
venv-old/bin/python -m pip install -e ./vector
venv-old/bin/python repro.py

Reproducer: CC0.

"""A finite particle at rest acquires NaN energy after coordinate conversion."""
import numpy as np
import sympy as sp
import vector

mass = sp.Integer(5)
momentum2 = sp.Integer(0)**2 + sp.Integer(0)**2 + sp.Integer(0)**2
energy = sp.sqrt(mass**2 + momentum2)
expected_energy = float(energy)
expected_mass = float(sp.sqrt(energy**2 - momentum2))
failures = []

for backend in ("object", "numpy"):
    for temporal, value in (("mass", float(mass)), ("E", expected_energy)):
        coordinates = dict(px=0.0, py=0.0, pz=0.0, **{temporal: value})
        original = (vector.obj(**coordinates) if backend == "object" else
                    vector.array({k: [v] for k, v in coordinates.items()}))
        assert np.allclose(original.E, expected_energy)
        assert np.allclose(original.mass, expected_mass)
        for method in (("to_pxpythetamass", "to_ptphithetamass") if temporal == "mass"
                       else ("to_pxpythetaenergy", "to_ptphithetaenergy")):
            converted = getattr(original, method)()
            actual = float(np.asarray(converted.E if temporal == "mass"
                                      else converted.mass).reshape(-1)[0])
            expected = expected_energy if temporal == "mass" else expected_mass
            print(f"{backend} {method}: expected {expected}, actual {actual}")
            if not np.isclose(actual, expected):
                failures.append((backend, method, actual))

assert not failures, f"{len(failures)} coordinate conversions corrupt energy or mass"

All eight conversions should return 5, since the temporal contract says “If t is derived from τ, it is not allowed to be NaN.” Instead every mass layout returns NaN energy, every energy layout returns NaN mass, and the script exits 1.

The theta branches of mag2.py and mag.py divide zero by zero at the theta=0 the conversion generates for the origin.

Any additional but relevant log output

Both backends print this:

to_pxpythetamass: expected 5.0, actual nan
to_ptphithetamass: expected 5.0, actual nan
to_pxpythetaenergy: expected 5.0, actual nan
to_ptphithetaenergy: expected 5.0, actual nan
AssertionError: 8 coordinate conversions corrupt energy or mass

— ChipLab

Lingua principale
Python
Stelle
101
Fork
43
Merge medio
4h 11m
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scikit-hep/vector

Tutte le issue di scikit-hep/vector

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.