Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

At-rest theta conversions return NaN energy or mass

Đang mở
#752 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@vera-rubin đang làm issue này rồi.

Từ ngày 19/10/2026.

  • #753 của @vera-rubin — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
numpy, python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
102
Fork
45
Merge trung bình
4 giờ 11 phút
Pull request đã merge (30 ngày)
6

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của scikit-hep/vector

Tất cả issue của scikit-hep/vector

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.