{"record":{"id":"fb9a7f1764c35307","repo":"jax-ml/jax","slug":"args-argument-to-jax-scipy-optimize-minimize-must","errorCode":null,"errorMessage":"args argument to jax.scipy.optimize.minimize must be a tuple, got {}","messagePattern":"args argument to jax\\.scipy\\.optimize\\.minimize must be a tuple, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/optimize/minimize.py","lineNumber":103,"sourceCode":"    args: extra arguments passed to the objective function.\n    method: solver type. Currently only ``\"BFGS\"`` is supported.\n    tol: tolerance for termination. For detailed control, use solver-specific\n      options.\n    options: a dictionary of solver options. All methods accept the following\n      generic options:\n\n      - maxiter (int): Maximum number of iterations to perform. Depending on the\n        method each iteration may use several function evaluations.\n\n  Returns:\n    An :class:`OptimizeResults` object.\n  \"\"\"\n  if options is None:\n    options = {}\n\n  if not isinstance(args, tuple):\n    msg = \"args argument to jax.scipy.optimize.minimize must be a tuple, got {}\"\n    raise TypeError(msg.format(args))\n\n  fun_with_args = lambda x: fun(x, *args)\n\n  if method.lower() == 'bfgs':\n    results = minimize_bfgs(fun_with_args, x0, **options)\n    success = results.converged & jnp.logical_not(results.failed)\n    return OptimizeResults(x=results.x_k,\n                           success=success,\n                           status=results.status,\n                           fun=results.f_k,\n                           jac=results.g_k,\n                           hess_inv=results.H_k,\n                           nfev=results.nfev,\n                           njev=results.ngev,\n                           nit=results.k)\n\n  if method.lower() == 'l-bfgs-experimental-do-not-rely-on-this':\n    results = _minimize_lbfgs(fun_with_args, x0, **options)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/optimize/minimize.py#L85-L121","documentation":"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.","triggerScenarios":"Passing args=[X, y] (a list) or args=None-adjacent values; converting a config-loaded array to args.","commonSituations":"Copy-pasting scipy.optimize.minimize calls where lists are accepted; JSON/YAML configs producing lists.","solutions":["Wrap in a tuple: args=(X, y)","If args may be a single value, still use a 1-tuple: args=(value,)","Validate type before calling"],"exampleFix":"# before\nres = minimize(loss, x0, args=[X, y])\n# after\nres = minimize(loss, x0, args=(X, y))","handlingStrategy":"type-guard","validationCode":"args = tuple(args)","typeGuard":"def is_tuple_args(a) -> bool: return isinstance(a, tuple)","tryCatchPattern":null,"preventionTips":["Always write args=(...) literal; lint for list args"],"tags":["jax","scipy","optimize","type-error","argument-validation"],"backgroundTag":"wrong-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}