jax-ml/jax · error · TypeError

args argument to jax.scipy.optimize.minimize must be a tuple

Error message

args argument to jax.scipy.optimize.minimize must be a tuple, got {}

What it means

jax.scipy.optimize.minimize requires args to be a Python tuple because it is splatted as fun(x, *args) inside a closure that JAX traces. Lists or other sequences are rejected with TypeError.

Source

Thrown at jax/_src/scipy/optimize/minimize.py:103

    args: extra arguments passed to the objective function.
    method: solver type. Currently only ``"BFGS"`` is supported.
    tol: tolerance for termination. For detailed control, use solver-specific
      options.
    options: a dictionary of solver options. All methods accept the following
      generic options:

      - maxiter (int): Maximum number of iterations to perform. Depending on the
        method each iteration may use several function evaluations.

  Returns:
    An :class:`OptimizeResults` object.
  """
  if options is None:
    options = {}

  if not isinstance(args, tuple):
    msg = "args argument to jax.scipy.optimize.minimize must be a tuple, got {}"
    raise TypeError(msg.format(args))

  fun_with_args = lambda x: fun(x, *args)

  if method.lower() == 'bfgs':
    results = minimize_bfgs(fun_with_args, x0, **options)
    success = results.converged & jnp.logical_not(results.failed)
    return OptimizeResults(x=results.x_k,
                           success=success,
                           status=results.status,
                           fun=results.f_k,
                           jac=results.g_k,
                           hess_inv=results.H_k,
                           nfev=results.nfev,
                           njev=results.ngev,
                           nit=results.k)

  if method.lower() == 'l-bfgs-experimental-do-not-rely-on-this':
    results = _minimize_lbfgs(fun_with_args, x0, **options)

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Wrap in a tuple: args=(X, y)
  2. If args may be a single value, still use a 1-tuple: args=(value,)
  3. Validate type before calling

Example fix

# before
res = minimize(loss, x0, args=[X, y])
# after
res = minimize(loss, x0, args=(X, y))
Defensive patterns

Strategy: type-guard

Validate before calling

args = tuple(args)

Type guard

def is_tuple_args(a) -> bool: return isinstance(a, tuple)

Prevention

When it happens

Trigger: Passing args=[X, y] (a list) or args=None-adjacent values; converting a config-loaded array to args.

Common situations: Copy-pasting scipy.optimize.minimize calls where lists are accepted; JSON/YAML configs producing lists.

Related errors


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