jax-ml/jax · error · ValueError
series_order must be <= 30.
Error message
series_order must be <= 30.
What it means
log_ndtr's series_order is capped at 30 because the precomputed coefficient tables and the asymptotic expansion only cover 30 terms; more terms bring no accuracy benefit and would need larger tables. Values above 30 raise ValueError.
Source
Thrown at jax/_src/scipy/special.py:1670
Args:
x: an array of type `float32`, `float64`.
series_order: Positive Python integer. Maximum depth to
evaluate the asymptotic expansion. This is the `N` above.
Returns:
an array with `dtype=x.dtype`.
Raises:
TypeError: if `x.dtype` is not handled.
TypeError: if `series_order` is a not Python `integer.`
ValueError: if `series_order` is not in `[0, 30]`.
"""
if not isinstance(series_order, int):
raise TypeError("series_order must be a Python integer.")
if series_order < 0:
raise ValueError("series_order must be non-negative.")
if series_order > 30:
raise ValueError("series_order must be <= 30.")
x_arr = jnp.asarray(x)
dtype = lax.dtype(x_arr)
if dtype == np.float64:
lower_segment: np.ndarray = _LOGNDTR_FLOAT64_LOWER
upper_segment: np.ndarray = _LOGNDTR_FLOAT64_UPPER
elif dtype == np.float32:
lower_segment = _LOGNDTR_FLOAT32_LOWER
upper_segment = _LOGNDTR_FLOAT32_UPPER
else:
raise TypeError(f"x.dtype={np.dtype(dtype)} is not supported.")
# The basic idea here was ported from:
# https://root.cern.ch/doc/v608/SpecFuncCephesInv_8cxx_source.html
# We copy the main idea, with a few changes
# * For x >> 1, and X ~ Normal(0, 1),
# Log[P[X < x]] = Log[1 - P[X < -x]] approx -P[X < -x],View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Clamp to 30: series_order = min(30, int(order)) — the default of 3 is usually already sufficient for float32/64 accuracy
- Read the docstring's documented [0, 30] range and pick a modest value (3–18)
- If more tail accuracy is truly needed, use log_ndtr(x.astype(jnp.float64), order) instead of raising order
Example fix
// before jax.scipy.special.log_ndtr(x, series_order=50) // after jax.scipy.special.log_ndtr(x, series_order=min(30, 50))
Defensive patterns
Strategy: validation
Validate before calling
series_order = min(30, max(0, int(series_order)))
Type guard
def order_in_range(o):
return isinstance(o, int) and 0 <= o <= 30 Prevention
- Prefer float64 inputs over huge orders for tail accuracy
- Document the [0,30] contract wherever log_ndtr is exposed
When it happens
Trigger: Calling log_ndtr(x, series_order=31) or higher, often from a sweep or an accuracy-tuning loop that assumes more is better.
Common situations: Accuracy tuning where users crank the order; copying order values from other libraries' settings; automated hyperparameter search exceeding the bound.
Related errors
- series_order must be non-negative.
- series_order must be a Python integer.
- x.dtype={np.dtype(dtype)} is not supported.
- z must be a 1D array.
- `compute_on`'s compute_type argument must be a string.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/f61d6f392ab18eef.
Report an issue: GitHub.