{"record":{"id":"d1058338c070e8d3","repo":"jax-ml/jax","slug":"the-problem-arose-with-the-fname-function","errorCode":null,"errorMessage":"The problem arose with the `{fname}` function. ","messagePattern":"The problem arose with the `(.+?)` function\\. ","errorType":"exception","errorClass":"ConcretizationTypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":2044,"sourceCode":"  else:\n    return x\n\ndef concretization_function_error(fun, suggest_astype=False):\n  fname = getattr(fun, \"__name__\", fun)\n  fname_context = f\"The problem arose with the `{fname}` function. \"\n  if suggest_astype:\n    fname_context += (\"If trying to convert the data type of a value, \"\n                      f\"try using `x.astype({fun.__name__})` \"\n                      f\"or `jnp.array(x, {fun.__name__})` instead.\")\n  if fun is bool:\n    def error(self, arg):\n      raise TracerBoolConversionError(arg)\n  elif fun in (hex, oct, operator.index):\n    def error(self, arg):\n      raise TracerIntegerConversionError(arg)\n  else:\n    def error(self, arg):\n      raise ConcretizationTypeError(arg, fname_context)\n  return error\n\ndef concrete_or_error(force: Any, val: Any, context=\"\"):\n  \"\"\"Like force(val), but gives the context in the error message.\"\"\"\n  if force is None:\n    force = lambda x: x\n  if isinstance(val, Tracer):\n    maybe_concrete = val.to_concrete_value()\n    if maybe_concrete is None:\n      raise ConcretizationTypeError(val, context)\n    else:\n      return force(maybe_concrete)\n  else:\n    return force(val)\n\ndef concrete_dim_or_error(val: Any, context=\"\"):\n  \"\"\"Like concrete_or_error(operator.index), allowing symbolic dimensions.\"\"\"\n  if is_symbolic_dim(val):","sourceCodeStart":2026,"sourceCodeEnd":2062,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L2026-L2062","documentation":"This is the ConcretizationTypeError raised by concrete_or_error when a non-bool/non-int builtin (e.g., float(), len(), str()) is applied to a Tracer; the message includes 'The problem arose with the `{fname}` function.' explaining which conversion forced concreteness.","triggerScenarios":"concrete_or_error(force, tracer) being invoked because user code called float(x), len(x), format(x), or similar on a Tracer inside a jax.jit/grad/vmap transformation.","commonSituations":"Calling float() on traced scalars for logging; len() on traced shapes assumed static; str() interpolation of tracers in f-strings inside traced code.","solutions":["Move the concrete conversion (float/len/str) outside the traced function","Use jax.debug.print or .item() after the jit call returns for logging","Use static arguments or x.shape known at trace time instead of len(tracer)","Replace Python print of tracers with jax.debug.print inside traces"],"exampleFix":"# before\n@jax.jit\ndef f(x):\n    print(f\"value: {float(x)}\")\n    return x * 2\n\n# after\n@jax.jit\ndef f(x):\n    jax.debug.print(\"value: {x}\", x=x)\n    return x * 2","handlingStrategy":"try-catch","validationCode":"import jax\ndef concrete(x):\n    return None if isinstance(x, jax.core.Tracer) else float(x)","typeGuard":"def is_tracer(x) -> bool:\n    import jax; return isinstance(x, jax.core.Tracer)","tryCatchPattern":"try:\n    val = float(x)\nexcept jax.errors.ConcretizationTypeError as e:\n    logging.warning('tracer concretized: %s', e)\n    val = None","preventionTips":["Keep float()/len()/str()/print calls outside traced functions","Use jax.debug.print for in-trace logging","Cache concrete scalars before entering jit and pass them as static arguments"],"tags":["jax","tracer","concretization","jit","float-conversion"],"backgroundTag":"jax-tracer-concretization","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}