jax-ml/jax · error · ValueError

Unknown boundary option

Error message

Unknown boundary option '{boundary}', must be one of: {list(boundary_funcs.keys())}

What it means

The boundary argument of the spectral functions selects how each segment is extended before windowing; JAX implements only 'even', 'odd', 'zeros', and None (None skips extension). Any other string is rejected with the list of valid keys.

Solutions

  1. Use one of 'even', 'odd', 'zeros', or None
  2. Pass boundary=None and pre-pad manually if you need other extension semantics

Example fix

// before
jax.scipy.signal.stft(x, boundary='symmetric')
// after
jax.scipy.signal.stft(x, boundary='even')
# or pre-pad: jax.scipy.signal.stft(jnp.pad(x,(k,k)), boundary=None)
Defensive patterns

Strategy: validation

Validate before calling

BOUNDARIES = ('even', 'odd', 'zeros', None)
assert boundary in BOUNDARIES, f'boundary must be one of {BOUNDARIES}'

Type guard

def is_valid_boundary(b) -> bool:
    return b in ('even', 'odd', 'zeros', None)

Prevention

When it happens

Trigger: jax.scipy.signal.stft(x, boundary='reflect') or 'constant' (scipy pad-style names); boundary='' from an unset config.

Common situations: Confusing jnp.pad mode names ('wrap', 'symmetric') with the boundary vocabulary; porting code from other STFT implementations.

Understand the failure class

Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/daa0e3bc33225325. Report an issue: GitHub.

Appendix: source

Thrown at jax/_src/scipy/signal.py:650

  def make_pad(mode, **kwargs):
    def pad(x, n, axis=-1):
      pad_width = [(0, 0) for unused_n in range(x.ndim)]
      pad_width[axis] = (n, n)
      return jnp.pad(x, pad_width, mode, **kwargs)
    return pad

  boundary_funcs = {
      'even': make_pad('reflect'),
      'odd': odd_ext,
      'constant': make_pad('edge'),
      'zeros': make_pad('constant', constant_values=0.0),
      None: lambda x, *args, **kwargs: x
  }

  # Check/ normalize inputs
  if boundary not in boundary_funcs:
    raise ValueError(
        f"Unknown boundary option '{boundary}', "
        f"must be one of: {list(boundary_funcs.keys())}")

  axis = core.concrete_or_error(operator.index, axis, "axis of windowed-FFT")
  axis = canonicalize_axis(axis, x.ndim)

  if y is None:
    check_arraylike('spectral_helper', x)
    x, = promote_dtypes_inexact(x)
    y_arr = x  # place-holder for type checking
    outershape = tuple_delete(x.shape, axis)
  else:
    if mode != 'psd':
      raise ValueError("two-argument mode is available only when mode=='psd'")
    check_arraylike('spectral_helper', x, y)
    x, y_arr = promote_dtypes_inexact(x, y)
    if x.ndim != y_arr.ndim:
      raise ValueError("two-arguments must have the same rank ({x.ndim} vs {y.ndim}).")

View on GitHub (pinned to 1e1c6a8fc0)