You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the use of JAX, there are now many possible types for numeric data. These include
68
+
69
+
- **Python scalars**: Objects with types that are ``float``, ``int``, or ``complex``.
70
+
- **NumPy scalars**: Objects with types that are subclasses of ``np.floating``, ``np.integer``, etc.
71
+
- **NumPy array scalars**: Objects with a type that is ``np.ndarray`` and have ``np.ndim(...) == 0``.
72
+
- **NumPy arrays**: Objects with a type that is ``np.ndarray`` and have ``np.ndim(...) > 0``.
73
+
- **JAX array scalars**: Objects with a type that is ``jax.numpy.ndarray`` and have ``jax.numpy.ndim(...) == 0``.
74
+
- **JAX arrays**: Objects with a type that is ``jax.numpy.ndarray`` and have ``jax.numpy.ndim(...) > 0``.
75
+
76
+
**JAX does not have pure scalar types like NumPy. JAX uses array scalars for those instead.**
77
+
78
+
JAX-GalSim uses the following rules when handling data types and casting.
79
+
80
+
- If the item is a Python numeric type (i.e., ``int`` or ``float``) or a
81
+
NumPy scalar type (i.e., ``isinstance(x, np.number)``, ``isinstance(x, np.integer)``, etc.),
82
+
convert it to a Python type of the appropriate kind.
83
+
- For all other array-like types, cast to the correct type via ``jax.numpy.astype(x, ...)``.
84
+
- For putting data into FITS headers only, JAX-GalSim converts of NumPy/JAX arrays to Python
85
+
numeric types as long as there is one element in the array (i.e., it is a NumPy scalar type,
86
+
an array scalar, or a 1D array with one element).
87
+
88
+
These rules allow JAX-GalSim to transparently handle JAX's tracing operations, but can result in
89
+
the code raising generic ``Exception`` instances instead of more specific ``GalSim`` exceptions in
90
+
some cases.
91
+
64
92
Random Number Generation
65
93
------------------------
66
94
@@ -163,9 +191,6 @@ profile parameters passed into a ``jit``-compiled function):
163
191
defgood(sigma):
164
192
return jax.lax.cond(sigma >1.0, lambdas: s *2, lambdas: s, sigma)
165
193
166
-
JAX-GalSim uses an internal ``has_tracers()`` utility to detect tracing and
167
-
avoid problematic control flow in its own implementations.
168
-
169
194
Fixed output shapes
170
195
^^^^^^^^^^^^^^^^^^^
171
196
@@ -197,20 +222,9 @@ The ``__init__`` gotcha
197
222
198
223
During ``jit`` tracing, JAX calls constructors with **tracer objects** rather
199
224
than concrete Python numbers. Type checks like ``isinstance(sigma, float)`` will
200
-
fail on tracers. JAX-GalSim handles this internally, but if you subclass any
201
-
JAX-GalSim object, be aware that ``__init__`` may receive tracers:
202
-
203
-
.. code-block:: python
204
-
205
-
from jax_galsim.core.utils import has_tracers
206
-
207
-
classMyProfile(jax_galsim.GSObject):
208
-
def__init__(self, sigma, gsparams=None):
209
-
ifnot has_tracers(sigma):
210
-
# Only validate with concrete values
211
-
if sigma <=0:
212
-
raiseValueError("sigma must be positive")
213
-
...
225
+
return ``False`` on tracers, and you cannot check correctness of values (e.g.,
226
+
``if sigma > 0: ...```). JAX-GalSim handles this internally, but if you subclass any
227
+
JAX-GalSim object, be aware that ``__init__`` may receive tracers.
214
228
215
229
Profile Restrictions
216
230
--------------------
@@ -221,12 +235,9 @@ Some GalSim features are not yet implemented in JAX-GalSim:
221
235
- **ChromaticObject**: All chromatic functionality (wavelength-dependent
222
236
profiles) is not available.
223
237
- **InterpolatedKImage**: Not implemented.
224
-
- **Airy, Kolmogorov, OpticalPSF, RealGalaxy**: See :doc:`api-coverage` for
238
+
- **Airy, Kolmogorov, OpticalPSF, RealGalaxy, etc.**: See :doc:`api-coverage` for
225
239
the full list.
226
240
227
-
The project currently implements **22.5 %** of the GalSim public API, focused
228
-
on the most commonly used profiles and operations.
229
-
230
241
Numerical Precision
231
242
-------------------
232
243
@@ -249,11 +260,11 @@ These differences are typically at the level of floating-point round-off
249
260
should not affect scientific conclusions.
250
261
251
262
⚠️ Additional Sharp Bits
252
-
--------------------------
263
+
------------------------
253
264
254
265
In the :doc:`api/index` you will find **🔪 JAX-GalSim - The Sharp Bits 🔪** blocks highlighting additional important caveats for specific classes and or methods. These could include things like:
255
266
256
-
- Many classes do not perform some of Galsim's test for correctness during initialization (e.g., :meth:`~jax_galsim.GSObject.drawImage`).
267
+
- Some classes do not perform some of Galsim's test for correctness during initialization (e.g., :meth:`~jax_galsim.InterpolatedImage`).
257
268
- Certain profiles might not be auto-differentiable with respect to some of their parameters (e.g., :class:`~jax_galsim.Spergel`, :class:`~jax_galsim.Moffat`)
258
269
- Limitations regarding what types of inputes are handled (e.g., :meth:`~jax_galsim.Image.calculate_fft` does not accept complex dtypes.)
0 commit comments