Skip to content

tests: make test_orbit energy/Jacobi conservation backend-tolerant (numpy.asarray)#982

Merged
jobovy merged 1 commit into
feat/backendsfrom
backend/test-orbit-harness-coercion
Jun 20, 2026
Merged

tests: make test_orbit energy/Jacobi conservation backend-tolerant (numpy.asarray)#982
jobovy merged 1 commit into
feat/backendsfrom
backend/test-orbit-harness-coercion

Conversation

@jobovy

@jobovy jobovy commented Jun 20, 2026

Copy link
Copy Markdown
Owner

What

Burndown Phase-1 PR (2 of 2 test-only). Makes the energy/Jacobi conservation asserts in tests/test_orbit.py tolerant of a forced jax/torch backend.

Why

test_energy_jacobi_conservation and test_energy_conservation_linear compute numpy.std(tEs)/numpy.mean(tEs) with tEs = o.E(ttimes) (and tJacobis = o.Jacobi). Under forced torch, o.E()/o.Jacobi() return a torch tensor (galpy computes the correct values), and numpy.std(<tensor>) dispatches to torch's Tensor.std(ddof=,dtype=,out=,axis=) which rejects numpy's kwargs → TypeError. jax passed only because numpy ufuncs auto-materialise it. Test-harness issue, not a galpy bug.

Change (test-only)

Wrap every o.E(...)/o.Jacobi(...) output that feeds a numpy host op — the std/mean feeders and the deeper firstTest (a-b)**2 arithmetic asserts — in numpy.asarray(...) (the #952 convention). 73 wraps; Orbits.py and the ledger are not touched.

Byte-identity

numpy.asarray(<numpy array>) is an identity no-op → numpy path byte-identical. Verified: both functions give 192 passed / 0 skipped, identical on parent (feat/backends) and branch (AST of the two functions is identical after stripping the wraps). Adversarially reviewed.

Validation (CPU, CI-parity)

  • numpy: 192/192 both functions, unchanged from parent.
  • torch: pure-harness failures now pass — ~27/40 energy_jacobi + ~23/30 energy_linear ledger nodeids flip to pass (verified the assertions pass numerically, not just dodge the TypeError).

Scope note

Nodeids that fail earlier — in galpy setup (tp.normalize scalar coercion under forced torch), in Orbit.L() (the numpy.ndarray * Tensor cross-product), or in the leapfrog integrator — are not fixed here and stay correctly ledgered; they're handled by the central-coercion / Orbits.L() / integrator source PRs. This PR only clears the numpy.std(tensor) harness failures.

🤖 Generated with Claude Code

…umpy.asarray)

test_energy_jacobi_conservation and test_energy_conservation_linear compute
numpy.std(tEs)/numpy.mean(tEs) with tEs = o.E(ttimes) (and tJacobis = o.Jacobi).
Under the forced torch backend o.E()/o.Jacobi() return a torch tensor (galpy
computes the CORRECT values), and numpy.std(<tensor>) dispatches to torch's
Tensor.std which rejects numpy's kwargs -> TypeError; jax materialises so passed.

Wrap every o.E(...)/o.Jacobi(...) output that feeds a numpy host op in
numpy.asarray(...) (the #952 convention). numpy.asarray on a numpy array is an
identity no-op, so the numpy path is byte-identical (192 passed / 0 skipped,
identical on parent and branch). Test-only; Orbits.py and the ledger untouched.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.93%. Comparing base (44f92c7) to head (2ec9935).

Additional details and impacted files
@@              Coverage Diff               @@
##           feat/backends     #982   +/-   ##
==============================================
  Coverage          99.93%   99.93%           
==============================================
  Files                253      253           
  Lines              39803    39803           
  Branches             840      844    +4     
==============================================
  Hits               39778    39778           
  Misses                25       25           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jobovy jobovy enabled auto-merge (squash) June 20, 2026 03:24
@github-actions

Copy link
Copy Markdown
Contributor

All-backend test status (jax / torch)

Commit 6f73b7b6ede058a1c014b369663b3cad39f4368a

Green is achieved via the checked-in xfail-ledger (tests/backend_xfail.txt, applied xfail(strict=False)), so the metric to watch is the shrinking xfail count (burndown), not a raw pass count. A FAIL/ERR is an un-ledgered regression (reds the run). Because the ledger is non-strict, a now-passing ledgered test is a plain pass here (no per-push XPASS); burndown candidates -- in both directions -- are surfaced by the scheduled regen run, which rewrites the ledger from real outcomes. deferred is a separate burndown: tests skipped because they are unrunnable under the backend until the port is vectorized (see tests/backend_slow_skip.txt), e.g. the jax spherical-DF sampling/quadrature tests pending the Track F DF migration.

Overall: jax: 1051 passed · 271 xfail · 725 deferred | torch: 764 passed · 1279 xfail · 1 deferred

Ledger size: 2357 entries (jax=284, torch=2073).

Test shard jax torch
actionAngle ✅ 112 pass · 89 xfail ✅ 26 pass · 175 xfail
sphericaldf ✅ 164 pass · 26 xfail · 28 deferred ✅ 8 pass · 210 xfail
conversion + util + misc ✅ 86 pass · 5 xfail · 1 deferred ✅ 41 pass · 51 xfail
potential + scf + multipole — (no result) — (no result)
quantity + coords ✅ 281 pass · 55 xfail ✅ 189 pass · 147 xfail
orbit (energy/Jacobi + from_name) ✅ 0 pass · 0 xfail · 115 deferred ✅ 53 pass · 62 xfail
orbit + orbits (main) ✅ 0 pass · 0 xfail · 578 deferred ✅ 189 pass · 386 xfail
evolveddiskdf ✅ 35 pass · 0 xfail ✅ 32 pass · 3 xfail
jeans + dynamfric ✅ 17 pass · 2 xfail · 2 deferred ✅ 7 pass · 13 xfail · 1 deferred
qdf + pv2qdf + streamgapdf_impulse + noninertial ✅ 57 pass · 75 xfail · 1 deferred ✅ 14 pass · 119 xfail
streamgapdf ✅ 28 pass · 2 xfail ✅ 27 pass · 3 xfail
diskdf ✅ 129 pass · 0 xfail ✅ 112 pass · 17 xfail
streamdf + streamspraydf + streamTrack ✅ 142 pass · 17 xfail ✅ 66 pass · 93 xfail
Per-shard counts
Test shard backend pass xfail deferred XPASS fail error
actionAngle jax 112 89 0 0 0 0
actionAngle torch 26 175 0 0 0 0
sphericaldf jax 164 26 28 0 0 0
sphericaldf torch 8 210 0 0 0 0
conversion + util + misc jax 86 5 1 0 0 0
conversion + util + misc torch 41 51 0 0 0 0
potential + scf + multipole jax
potential + scf + multipole torch
quantity + coords jax 281 55 0 0 0 0
quantity + coords torch 189 147 0 0 0 0
orbit (energy/Jacobi + from_name) jax 0 0 115 0 0 0
orbit (energy/Jacobi + from_name) torch 53 62 0 0 0 0
orbit + orbits (main) jax 0 0 578 0 0 0
orbit + orbits (main) torch 189 386 0 0 0 0
evolveddiskdf jax 35 0 0 0 0 0
evolveddiskdf torch 32 3 0 0 0 0
jeans + dynamfric jax 17 2 2 0 0 0
jeans + dynamfric torch 7 13 1 0 0 0
qdf + pv2qdf + streamgapdf_impulse + noninertial jax 57 75 1 0 0 0
qdf + pv2qdf + streamgapdf_impulse + noninertial torch 14 119 0 0 0 0
streamgapdf jax 28 2 0 0 0 0
streamgapdf torch 27 3 0 0 0 0
diskdf jax 129 0 0 0 0 0
diskdf torch 112 17 0 0 0 0
streamdf + streamspraydf + streamTrack jax 142 17 0 0 0 0
streamdf + streamspraydf + streamTrack torch 66 93 0 0 0 0

@jobovy jobovy merged commit fcad3f7 into feat/backends Jun 20, 2026
146 checks passed
@jobovy jobovy deleted the backend/test-orbit-harness-coercion branch June 20, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant