orbix 4.1.0__tar.gz → 4.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. {orbix-4.1.0 → orbix-4.2.0}/CHANGELOG.md +7 -0
  2. {orbix-4.1.0 → orbix-4.2.0}/PKG-INFO +1 -1
  3. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/_version.py +2 -2
  4. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/system/charts.py +12 -12
  5. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/system/core.py +71 -21
  6. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/system/frame_orbit.py +15 -2
  7. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/system/observables.py +3 -1
  8. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/system/rotation.py +17 -3
  9. {orbix-4.1.0 → orbix-4.2.0}/tests/test_system_ephemeris.py +50 -0
  10. {orbix-4.1.0 → orbix-4.2.0}/.codespellrc +0 -0
  11. {orbix-4.1.0 → orbix-4.2.0}/.editorconfig +0 -0
  12. {orbix-4.1.0 → orbix-4.2.0}/.gitattributes +0 -0
  13. {orbix-4.1.0 → orbix-4.2.0}/.github/dependabot.yml +0 -0
  14. {orbix-4.1.0 → orbix-4.2.0}/.github/scripts/ci_summary.py +0 -0
  15. {orbix-4.1.0 → orbix-4.2.0}/.github/sibling-pins.txt +0 -0
  16. {orbix-4.1.0 → orbix-4.2.0}/.github/workflows/ci.yml +0 -0
  17. {orbix-4.1.0 → orbix-4.2.0}/.github/workflows/dependabot-automerge.yml +0 -0
  18. {orbix-4.1.0 → orbix-4.2.0}/.github/workflows/docs.yml +0 -0
  19. {orbix-4.1.0 → orbix-4.2.0}/.github/workflows/hygiene.yml +0 -0
  20. {orbix-4.1.0 → orbix-4.2.0}/.github/workflows/publish-to-pypi.yml +0 -0
  21. {orbix-4.1.0 → orbix-4.2.0}/.github/workflows/release-please.yml +0 -0
  22. {orbix-4.1.0 → orbix-4.2.0}/.github/workflows/upstream.yml +0 -0
  23. {orbix-4.1.0 → orbix-4.2.0}/.github/zizmor.yml +0 -0
  24. {orbix-4.1.0 → orbix-4.2.0}/.gitignore +0 -0
  25. {orbix-4.1.0 → orbix-4.2.0}/.pre-commit-config.yaml +0 -0
  26. {orbix-4.1.0 → orbix-4.2.0}/.python-version +0 -0
  27. {orbix-4.1.0 → orbix-4.2.0}/.readthedocs.yaml +0 -0
  28. {orbix-4.1.0 → orbix-4.2.0}/.zenodo.json +0 -0
  29. {orbix-4.1.0 → orbix-4.2.0}/CITATION.cff +0 -0
  30. {orbix-4.1.0 → orbix-4.2.0}/LICENSE +0 -0
  31. {orbix-4.1.0 → orbix-4.2.0}/README.md +0 -0
  32. {orbix-4.1.0 → orbix-4.2.0}/SECURITY.md +0 -0
  33. {orbix-4.1.0 → orbix-4.2.0}/docs/conf.py +0 -0
  34. {orbix-4.1.0 → orbix-4.2.0}/docs/examples/orbits.md +0 -0
  35. {orbix-4.1.0 → orbix-4.2.0}/docs/examples/prepared.md +0 -0
  36. {orbix-4.1.0 → orbix-4.2.0}/docs/gallery.md +0 -0
  37. {orbix-4.1.0 → orbix-4.2.0}/docs/index.md +0 -0
  38. {orbix-4.1.0 → orbix-4.2.0}/pyproject.toml +0 -0
  39. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/__init__.py +0 -0
  40. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/equations/__init__.py +0 -0
  41. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/equations/lambert.py +0 -0
  42. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/equations/orbit.py +0 -0
  43. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/equations/phase.py +0 -0
  44. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/equations/propagation.py +0 -0
  45. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/__init__.py +0 -0
  46. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/core.py +0 -0
  47. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/longitude.py +0 -0
  48. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/markley.py +0 -0
  49. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/shortcuts/__init__.py +0 -0
  50. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/shortcuts/fixed_e.py +0 -0
  51. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/shortcuts/grid.py +0 -0
  52. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/kepler/shortcuts/guess.py +0 -0
  53. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/observatory/__init__.py +0 -0
  54. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/observatory/data/L2_halo_orbit_six_month.npz +0 -0
  55. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/observatory/keepout.py +0 -0
  56. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/observatory/observatory.py +0 -0
  57. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/observatory/orbit.py +0 -0
  58. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/observatory/solar_system.py +0 -0
  59. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/orbit.py +0 -0
  60. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/py.typed +0 -0
  61. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/system/__init__.py +0 -0
  62. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/viz/__init__.py +0 -0
  63. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/viz/_prepare.py +0 -0
  64. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/viz/_require.py +0 -0
  65. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/viz/anim.py +0 -0
  66. {orbix-4.1.0 → orbix-4.2.0}/src/orbix/viz/orbit.py +0 -0
  67. {orbix-4.1.0 → orbix-4.2.0}/tests/conftest.py +0 -0
  68. {orbix-4.1.0 → orbix-4.2.0}/tests/test_charts.py +0 -0
  69. {orbix-4.1.0 → orbix-4.2.0}/tests/test_dependency_floors.py +0 -0
  70. {orbix-4.1.0 → orbix-4.2.0}/tests/test_equations_grads.py +0 -0
  71. {orbix-4.1.0 → orbix-4.2.0}/tests/test_fixed_e_solvers.py +0 -0
  72. {orbix-4.1.0 → orbix-4.2.0}/tests/test_frame_orbit.py +0 -0
  73. {orbix-4.1.0 → orbix-4.2.0}/tests/test_grid_solvers.py +0 -0
  74. {orbix-4.1.0 → orbix-4.2.0}/tests/test_internal_refs_guard.py +0 -0
  75. {orbix-4.1.0 → orbix-4.2.0}/tests/test_kepler_core.py +0 -0
  76. {orbix-4.1.0 → orbix-4.2.0}/tests/test_kepler_grads.py +0 -0
  77. {orbix-4.1.0 → orbix-4.2.0}/tests/test_kepler_longitude.py +0 -0
  78. {orbix-4.1.0 → orbix-4.2.0}/tests/test_kepler_markley.py +0 -0
  79. {orbix-4.1.0 → orbix-4.2.0}/tests/test_lambert.py +0 -0
  80. {orbix-4.1.0 → orbix-4.2.0}/tests/test_observatory.py +0 -0
  81. {orbix-4.1.0 → orbix-4.2.0}/tests/test_observatory_wrapper.py +0 -0
  82. {orbix-4.1.0 → orbix-4.2.0}/tests/test_orbit.py +0 -0
  83. {orbix-4.1.0 → orbix-4.2.0}/tests/test_sky_convention.py +0 -0
  84. {orbix-4.1.0 → orbix-4.2.0}/tests/test_viz_anim.py +0 -0
  85. {orbix-4.1.0 → orbix-4.2.0}/tests/test_viz_orbit.py +0 -0
  86. {orbix-4.1.0 → orbix-4.2.0}/tests/test_viz_package.py +0 -0
  87. {orbix-4.1.0 → orbix-4.2.0}/tests/test_viz_prepared.py +0 -0
  88. {orbix-4.1.0 → orbix-4.2.0}/tests/test_vs_exosims.py +0 -0
  89. {orbix-4.1.0 → orbix-4.2.0}/tools/check_internal_refs.py +0 -0
@@ -43,6 +43,13 @@
43
43
  * The broken predict/pdet functions and the `discrete_e` factory were removed
44
44
  (they did not work correctly and had no working callers).
45
45
 
46
+ ## [4.2.0](https://github.com/CoreySpohn/orbix/compare/v4.1.0...v4.2.0) (2026-11-16)
47
+
48
+
49
+ ### Features
50
+
51
+ * **system:** leading batch dimensions on the system, with ordered sums that make trailing zero-mass bodies bitwise inert ([acae82f](https://github.com/CoreySpohn/orbix/commit/acae82fa3df92ebbc57aea41dcb8d81f56ee88fe))
52
+
46
53
  ## [4.1.0](https://github.com/CoreySpohn/orbix/compare/v4.0.0...v4.1.0) (2026-11-16)
47
54
 
48
55
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: orbix
3
- Version: 4.1.0
3
+ Version: 4.2.0
4
4
  Summary: A JAX library of functions useful for exoplanet simulations
5
5
  Project-URL: Homepage, https://github.com/CoreySpohn/orbix
6
6
  Project-URL: Issues, https://github.com/CoreySpohn/orbix/issues
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '4.1.0'
22
- __version_tuple__ = version_tuple = (4, 1, 0)
21
+ __version__ = version = '4.2.0'
22
+ __version_tuple__ = version_tuple = (4, 2, 0)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -87,7 +87,7 @@ class AbstractChart(eqx.Module):
87
87
  class FrameChart(AbstractChart):
88
88
  """Coordinates (ln a, ux, uy, vw, vx, vy, vz), with a quaternion gauge.
89
89
 
90
- The disk map is u/sqrt(1+|u|^2); the quaternion is v/|v|. The inverse
90
+ The disk map is u/sqrt(1+norm(u)^2); the quaternion is v/norm(v). The inverse
91
91
  chooses unit length and makes the largest-magnitude component positive
92
92
  (first component wins ties). Thus neither length nor sign is recovered.
93
93
 
@@ -97,8 +97,8 @@ class FrameChart(AbstractChart):
97
97
  Use nonzero v for differentiable inference; a Gaussian draw is nonzero
98
98
  almost surely.
99
99
 
100
- For positive gauge_sd, with r=|v|, log_volume is
101
- -2 log(1+|u|^2) - 0.5*((r-1)/gauge_sd)^2 - 3 log(r).
100
+ For positive gauge_sd, with r=norm(v), log_volume is
101
+ -2 log(1+norm(u)^2) - 0.5*((r-1)/gauge_sd)^2 - 3 log(r).
102
102
  The additive normalization constant is omitted, including the normal's
103
103
  truncation to r>0 (a negligible correction for small gauge_sd); r=0
104
104
  has zero density. Since d^4 v=r^3 dr dS3, the r^3 factor cancels:
@@ -106,7 +106,7 @@ class FrameChart(AbstractChart):
106
106
  r near one to limit changes in orientation scales during inference.
107
107
 
108
108
  With gauge_sd=None, log_volume is instead
109
- -2 log(1+|u|^2) - |v|^2/2 - 2 log(2*pi), unchanged and normalized.
109
+ -2 log(1+norm(u)^2) - norm(v)^2/2 - 2 log(2*pi), unchanged and normalized.
110
110
  Gaussian four-vector draws then give exact isotropic orientations.
111
111
  Both quaternion signs are integrated in either gauge.
112
112
  """
@@ -166,13 +166,13 @@ class FrameChart(AbstractChart):
166
166
  class EccentricityVectorChart(AbstractChart):
167
167
  """Coordinates (ln a, ux, uy, atanh(cos i), W, M0+w).
168
168
 
169
- u/sqrt(1+|u|^2) gives (e cos w, e sin w). Angles are plain real radians;
169
+ u/sqrt(1+norm(u)^2) gives (e cos w, e sin w). Angles are plain real radians;
170
170
  predictions are periodic in them. Conventions match from_classical on
171
171
  FrameOrbit. The inverse remains regular at e=0 but is undefined at
172
172
  either inclination pole, which finite coordinates do not reach in exact
173
173
  arithmetic.
174
174
 
175
- log_volume = -2 log(1+|u|^2) + log(sech(z)^2), z=atanh(cos i).
175
+ log_volume = -2 log(1+norm(u)^2) + log(sech(z)^2), z=atanh(cos i).
176
176
  The omitted additive constant is -log(8*pi^2) for normalized Haar
177
177
  measure and one 2*pi cell for each angle. Rotation of the eccentricity
178
178
  plane by -(M0+w) preserves area, including its coupled phase dependence.
@@ -237,9 +237,9 @@ class CartesianChart(AbstractChart):
237
237
  """Epoch position and escape-speed-scaled velocity coordinates (p, w).
238
238
 
239
239
  With positive scale_AU=s, r=s*p is in (east, north, away) AU and
240
- v=sqrt(2*mu/|r|)*w/sqrt(1+|w|^2) is in AU/day. The velocity map is
240
+ v=sqrt(2*mu/norm(r))*w/sqrt(1+norm(w)^2) is in AU/day. The velocity map is
241
241
  smooth and bijective onto the open escape-speed ball, including w=0,
242
- with no division by |w| and no clipping.
242
+ with no division by norm(w) and no clipping.
243
243
 
244
244
  Nonzero position and nonradial velocity are required by FrameOrbit:
245
245
  every finite input has negative energy at r!=0, but exactly radial
@@ -270,19 +270,19 @@ class CartesianChart(AbstractChart):
270
270
  return jnp.concatenate([r / self.scale_AU, _plane(v / escape[..., None])], -1)
271
271
 
272
272
  def log_volume(self, x) -> Array:
273
- """Return -3 log(|p|) - 4 log(1+|w|^2), independent of mu and scale.
273
+ """Return -3 log(norm(p)) - 4 log(1+norm(w)^2), independent of mu and scale.
274
274
 
275
- Let s=scale_AU, R=s*|p|, b=1+|w|^2, a=R*b/2, and dnu be the
275
+ Let s=scale_AU, R=s*norm(p), b=1+norm(w)^2, a=R*b/2, and dnu be the
276
276
  reference measure e de d(cos i) dW dw dM d(ln a) with unnormalized
277
277
  Haar orientation. Delaunay actions L=sqrt(mu*a), G=L*sqrt(1-e^2),
278
278
  H=G*cos(i), and J=s^3*(2*mu/R)^(3/2)*b^(-5/2) give:
279
279
  d^3r d^3v = dL dG dH dM dw dW = (mu*a)^(3/2)/2 * dnu.
280
- dnu/d^6x = 2*J/(mu*a)^(3/2) = 16*|p|^(-3)*b^(-4).
280
+ dnu/d^6x = 2*J/(mu*a)^(3/2) = 16*norm(p)^(-3)*b^(-4).
281
281
 
282
282
  The ball Jacobian b^(-5/2) has one radial and two tangential
283
283
  eigenvalues b^(-3/2), b^(-1/2), b^(-1/2). Position dependence of
284
284
  escape speed leaves the phase-space Jacobian block triangular.
285
- Thus escape-speed scaling cancels mu exactly, and R=s*|p| cancels
285
+ Thus escape-speed scaling cancels mu exactly, and R=s*norm(p) cancels
286
286
  s. The omitted additive constant may depend on scale_AU only;
287
287
  here it is independent of scale too: log(16) for unnormalized
288
288
  Haar, or log(2/pi^2) for normalized Haar.
@@ -5,6 +5,7 @@ The hierarchy is a set of independent Kepler orbits, not an N-body integrator.
5
5
  """
6
6
 
7
7
  import equinox as eqx
8
+ import jax
8
9
  import jax.numpy as jnp
9
10
  from hwoutils.constants import G, Msun2kg
10
11
  from hwoutils.epoch import Epoch
@@ -18,31 +19,49 @@ GM_SUN_AU3_PER_D2 = G * Msun2kg
18
19
  _DEFAULT_SOLVER = Markley()
19
20
 
20
21
 
21
- def enclosed_mu(star_mass_Msun, planet_mass_Msun):
22
- """Return Jacobi gravitational parameters, including each planet's mass.
22
+ def _ordered_sum(values):
23
+ """Return final sum and prefixes along axis zero, in fixed input order."""
23
24
 
24
- The star mass is scalar; planet masses have shape (K,), ordered inner
25
- to outer by the caller. This is the sole mass-to-orbit coupling.
26
- """
25
+ def add(total, value):
26
+ total = total + value
27
+ return total, total
28
+
29
+ return jax.lax.scan(add, jnp.zeros(values.shape[1:], values.dtype), values)
30
+
31
+
32
+ def enclosed_mu(star_mass_Msun, planet_mass_Msun):
33
+ """Return Jacobi mu for star shape B and inner-to-outer masses B + (K,)."""
34
+ masses = jnp.asarray(planet_mass_Msun)
35
+ _, cumulative = _ordered_sum(jnp.moveaxis(masses, -1, 0))
27
36
  return GM_SUN_AU3_PER_D2 * (
28
- jnp.asarray(star_mass_Msun) + jnp.cumsum(jnp.asarray(planet_mass_Msun), axis=0)
37
+ jnp.asarray(star_mass_Msun)[..., None] + jnp.moveaxis(cumulative, 0, -1)
29
38
  )
30
39
 
31
40
 
32
41
  def jacobi_to_barycentric(relative, star_mass_Msun, planet_mass_Msun):
33
- """Map (K,) + time_shape + (3,) relative vectors to K+1 body vectors.
42
+ """Map B + (K,) + time_shape + (3,) to B + (K+1,) + time_shape + (3,).
34
43
 
35
- The same linear mass-weighted map applies to positions and velocities.
36
- Body zero is the star; a cumulative sum avoids an unrolled planet loop.
44
+ Both sums run sequentially inner to outer. Appending zero-mass bodies
45
+ preserves the bits of every preceding body and the stellar reflex.
37
46
  """
38
47
  relative = jnp.asarray(relative)
39
48
  masses = jnp.asarray(planet_mass_Msun)
40
- weights = masses / (jnp.asarray(star_mass_Msun) + jnp.cumsum(masses))
41
- weighted = relative * weights.reshape(masses.shape + (1,) * (relative.ndim - 1))
42
- cumulative = jnp.cumsum(weighted, axis=0)
43
- star = -jnp.sum(weighted, axis=0, keepdims=True)
49
+ axis = masses.ndim - 1
50
+ _, cumulative_mass = _ordered_sum(jnp.moveaxis(masses, -1, 0))
51
+ enclosed = jnp.asarray(star_mass_Msun)[..., None] + jnp.moveaxis(
52
+ cumulative_mass, 0, -1
53
+ )
54
+ weights = masses / enclosed
55
+ weighted = relative * weights.reshape(
56
+ masses.shape + (1,) * (relative.ndim - masses.ndim)
57
+ )
58
+ total, cumulative = _ordered_sum(jnp.moveaxis(weighted, axis, 0))
59
+ star = -total[None]
44
60
  preceding = jnp.concatenate([jnp.zeros_like(star), cumulative], axis=0)[:-1]
45
- return jnp.concatenate([star, star + preceding + relative], axis=0)
61
+ relative = jnp.moveaxis(relative, axis, 0)
62
+ return jnp.moveaxis(
63
+ jnp.concatenate([star, star + preceding + relative], axis=0), 0, axis
64
+ )
46
65
 
47
66
 
48
67
  class Body(eqx.Module):
@@ -96,8 +115,24 @@ class Ephemeris(eqx.Module):
96
115
  if isinstance(reference, str):
97
116
  if reference != "barycenter":
98
117
  raise ValueError('reference must be a body index or "barycenter"')
99
- return values[target]
100
- return values[target] - values[reference]
118
+ return self._body(values, target)
119
+ target_values = self._body(values, target)
120
+ reference_values = self._body(values, reference)
121
+ axis = self.dist_pc.ndim
122
+ while reference_values.ndim < target_values.ndim:
123
+ reference_values = jnp.expand_dims(reference_values, axis)
124
+ while target_values.ndim < reference_values.ndim:
125
+ target_values = jnp.expand_dims(target_values, axis)
126
+ return target_values - reference_values
127
+
128
+ def _body(self, values, target):
129
+ axis = self.dist_pc.ndim
130
+ if jnp.ndim(target) > 1:
131
+ indices = jnp.asarray(target).reshape(
132
+ (*jnp.shape(target), *(1,) * (values.ndim - axis - 1))
133
+ )
134
+ return jnp.take_along_axis(values, indices, axis=axis)
135
+ return jnp.take(values, target, axis=axis)
101
136
 
102
137
  def offset_arcsec(self, target, reference=0):
103
138
  """Return east and north angular offsets from the reference."""
@@ -140,8 +175,8 @@ class System(eqx.Module):
140
175
  """A Jacobi chain ordered inner to outer by the caller.
141
176
 
142
177
  Orbit j describes planet j relative to the center of mass of the star
143
- and all preceding planets. The star is scalar; masses and orbit batch
144
- have shape (K,). Changing masses on a constructed System changes the
178
+ and all preceding planets. The star and distance have shape B; planet
179
+ masses and orbit batch have shape B + (K,). Editing masses changes the
145
180
  barycentric map only: rebuild to impose dynamically consistent rates.
146
181
  """
147
182
 
@@ -153,12 +188,14 @@ class System(eqx.Module):
153
188
  def __check_init__(self):
154
189
  """Validate the body and vector shape contract."""
155
190
  if (
156
- self.star.mass_Msun.shape != ()
157
- or self.planets.mass_Msun.ndim != 1
191
+ self.planets.mass_Msun.shape[:-1] != self.star.mass_Msun.shape
192
+ or self.planets.mass_Msun.ndim < 1
193
+ or self.frame.dist_pc.shape != self.star.mass_Msun.shape
158
194
  or self.orbits.a_AU.shape != self.planets.mass_Msun.shape
159
195
  ):
160
196
  raise ValueError(
161
- "System requires a scalar star and (K,) planets and orbits"
197
+ "System requires star/distance shape B "
198
+ "and planets/orbits shape B + (K,)"
162
199
  )
163
200
 
164
201
  @classmethod
@@ -180,6 +217,19 @@ class System(eqx.Module):
180
217
 
181
218
  def solve(self, time_d, *, solver=_DEFAULT_SOLVER):
182
219
  """Solve once at all times; return (K+1,) + time_shape + (3,) states."""
220
+ batch = self.star.mass_Msun.shape
221
+ if batch:
222
+ time = jnp.asarray(time_d)
223
+ paired = time.ndim != 1
224
+ if paired and time.shape[:-1] != batch:
225
+ raise ValueError("time_d must have shape (T,) or B + (T,)")
226
+
227
+ def solve(system, time):
228
+ return system.solve(time, solver=solver)
229
+
230
+ for _ in batch:
231
+ solve = jax.vmap(solve, in_axes=(0, 0 if paired else None))
232
+ return solve(self, time)
183
233
  r, v = self.orbits.at(time_d, solver=solver)
184
234
  return Ephemeris(
185
235
  jacobi_to_barycentric(r, self.star.mass_Msun, self.planets.mass_Msun),
@@ -1,6 +1,7 @@
1
1
  """Non-singular bound-orbit state; Broucke and Cefola (1972), Danby (1988)."""
2
2
 
3
3
  import equinox as eqx
4
+ import jax
4
5
  import jax.numpy as jnp
5
6
  from jaxtyping import Array
6
7
 
@@ -211,7 +212,13 @@ class FrameOrbit(eqx.Module):
211
212
  basis = self.plane_basis().reshape(
212
213
  (*self.a_AU.shape, *(1,) * jnp.ndim(time_d), 3, 2)
213
214
  )
214
- return (basis @ xy[..., None])[..., 0], (basis @ xy_rate[..., None])[..., 0]
215
+
216
+ def apply(coordinates):
217
+ first = jax.lax.optimization_barrier(basis[..., 0] * coordinates[..., :1])
218
+ second = jax.lax.optimization_barrier(basis[..., 1] * coordinates[..., 1:])
219
+ return first + second
220
+
221
+ return apply(xy), apply(xy_rate)
215
222
 
216
223
  def plane_basis(self) -> Array:
217
224
  """Return the constant B + (3, 2) plane-to-sky matrix in AU.
@@ -296,7 +303,13 @@ class FrameOrbit(eqx.Module):
296
303
  """
297
304
  xy, xy_rate = self._plane_coordinates_each(time_d, solver=solver)
298
305
  basis = self.plane_basis()
299
- return (basis @ xy[..., None])[..., 0], (basis @ xy_rate[..., None])[..., 0]
306
+
307
+ def apply(coordinates):
308
+ first = jax.lax.optimization_barrier(basis[..., 0] * coordinates[..., :1])
309
+ second = jax.lax.optimization_barrier(basis[..., 1] * coordinates[..., 1:])
310
+ return first + second
311
+
312
+ return apply(xy), apply(xy_rate)
300
313
 
301
314
  def _plane_coordinates_each(self, time_d, *, solver):
302
315
  """Evaluate dimensionless plane position and rate at paired times."""
@@ -11,7 +11,9 @@ from hwoutils.constants import AU2m, d2s, pc2AU, rad2arcsec
11
11
  def offset_arcsec(r_AU, dist_pc):
12
12
  """Return east (Delta alpha cos delta) and north offsets in arcseconds."""
13
13
  r = jnp.asarray(r_AU)
14
- factor = rad2arcsec / (pc2AU * jnp.asarray(dist_pc))
14
+ distance = jnp.asarray(dist_pc)
15
+ distance = distance.reshape(distance.shape + (1,) * (r.ndim - 1 - distance.ndim))
16
+ factor = rad2arcsec / (pc2AU * distance)
15
17
  return r[..., 0] * factor, r[..., 1] * factor
16
18
 
17
19
 
@@ -1,13 +1,27 @@
1
1
  """Scalar-first unit quaternions mapping plane vectors into the sky frame."""
2
2
 
3
+ import jax
3
4
  import jax.numpy as jnp
4
5
 
5
6
 
7
+ def _cross(left, right):
8
+ """Cross product with shape-independent rounding of each product."""
9
+ first = left[..., [1, 2, 0]] * right[..., [2, 0, 1]]
10
+ second = left[..., [2, 0, 1]] * right[..., [1, 2, 0]]
11
+ return jax.lax.optimization_barrier(first) - jax.lax.optimization_barrier(second)
12
+
13
+
6
14
  def rotate(quat, vector):
7
- """Rotate last-axis vectors by broadcast unit quaternions (w, x, y, z)."""
15
+ """Rotate last-axis vectors by broadcast unit quaternions (w, x, y, z).
16
+
17
+ Round products before adding so CPU fusion cannot depend on batch length.
18
+ """
19
+ vector = jnp.asarray(vector)
8
20
  imaginary = quat[..., 1:]
9
- twice_cross = 2 * jnp.cross(imaginary, vector)
10
- return vector + quat[..., :1] * twice_cross + jnp.cross(imaginary, twice_cross)
21
+ twice_cross = 2 * _cross(imaginary, vector)
22
+ first = jax.lax.optimization_barrier(quat[..., :1] * twice_cross)
23
+ second = _cross(imaginary, twice_cross)
24
+ return vector + first + second
11
25
 
12
26
 
13
27
  def from_basis(f, g, normal):
@@ -289,3 +289,53 @@ def test_host_time_observables_and_solver_trace():
289
289
  )
290
290
  with pytest.raises(ValueError, match="reference"):
291
291
  eph.distance_AU(1, "invalid")
292
+
293
+
294
+ @pytest.mark.parametrize("batch_shape", [(), (2, 3)])
295
+ def test_batch_and_massless_tail(batch_shape):
296
+ """Fails if leading axes couple systems or zeros alter the ordered sum.
297
+
298
+ Exact algebra: trailing zero weights must preserve all preceding bits.
299
+ Batch/vectorized and scalar solves use the same arithmetic (2 ULP floor).
300
+ """
301
+ base = _system()
302
+ batch = jax.tree.map(lambda x: jnp.broadcast_to(x, batch_shape + x.shape), base)
303
+ times = jnp.array([0.0, 31.0])
304
+ result = batch.solve(times)
305
+ truth = base.solve(times)
306
+ np.testing.assert_array_equal(
307
+ result.position_AU, np.broadcast_to(truth.position_AU, result.position_AU.shape)
308
+ )
309
+ np.testing.assert_array_equal(
310
+ result.separation_arcsec(1),
311
+ np.broadcast_to(truth.separation_arcsec(1), (*batch_shape, 2)),
312
+ )
313
+ padded = System.from_classical(
314
+ Body(jnp.ones(batch_shape)),
315
+ Body(
316
+ jnp.broadcast_to(
317
+ jnp.array([0.001, 0.005, 0.0, 0.0, 0.0]), (*batch_shape, 5)
318
+ )
319
+ ),
320
+ SkyFrame(jnp.full(batch_shape, 10.0)),
321
+ **{
322
+ name: jnp.broadcast_to(
323
+ jnp.array([*values, *([1.0 if name == "a_AU" else 0.0] * 3)]),
324
+ (*batch_shape, 5),
325
+ )
326
+ for name, values in ELEMENTS.items()
327
+ },
328
+ )
329
+ extra = padded.solve(times)
330
+ np.testing.assert_array_equal(extra.position_AU[..., :3, :, :], result.position_AU)
331
+ np.testing.assert_array_equal(
332
+ extra.velocity_AU_per_d[..., :3, :, :], result.velocity_AU_per_d
333
+ )
334
+ if batch_shape:
335
+ expected = np.stack([truth.separation_arcsec(i) for i in (1, 2)])
336
+ np.testing.assert_array_equal(
337
+ result.separation_arcsec(jnp.array([1, 2])),
338
+ np.broadcast_to(expected, (*batch_shape, *expected.shape)),
339
+ )
340
+ paired = batch.solve(jnp.broadcast_to(times, batch_shape + times.shape))
341
+ np.testing.assert_array_equal(paired.position_AU, result.position_AU)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes