{"record":{"id":"321cc1d5ff4bd304","repo":"jax-ml/jax","slug":"tracerintegerconversionerror","errorCode":null,"errorMessage":"TracerIntegerConversionError","messagePattern":"TracerIntegerConversionError","errorType":"exception","errorClass":"TracerIntegerConversionError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":2041,"sourceCode":"def to_concrete_value(x):\n  if isinstance(x, Tracer):\n    return x.to_concrete_value()\n  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","sourceCodeStart":2023,"sourceCodeEnd":2059,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L2023-L2059","documentation":"TracerIntegerConversionError is raised when hex(), oct(), or operator.index() (implicit integer conversion, e.g., list indexing) is applied to a Tracer. Python needs a concrete int, but the Tracer's value is unknown during tracing.","triggerScenarios":"Using a traced scalar as a list index (data[idx]), in range(), in hex()/oct(), or anywhere Python calls __index__ on a value inside a jitted function.","commonSituations":"Indexing Python lists/tuples with traced loop counters inside jit; passing traced ints to bin(i) for debugging; using traced values in slicing of Python objects.","solutions":["Index JAX arrays instead of Python lists (convert list to jnp.array first)","Use jax.lax.fori_loop / lax.dynamic_slice / lax.dynamic_update_slice for dynamic indexing","Hoist the index computation outside the traced function and pass a concrete int","Use jax.debug.print instead of hex()/bin() for debugging"],"exampleFix":"# before\n@jax.jit\ndef get(i):\n    return my_python_list[i]  # TracerIntegerConversionError\n\n# after\narr = jnp.array(my_python_list)\n@jax.jit\ndef get(i):\n    return arr[i]  # or lax.dynamic_index / dynamic_slice","handlingStrategy":"validation","validationCode":"import jax\ndef ensure_concrete_index(i):\n    if isinstance(i, jax.core.Tracer):\n        raise TypeError('index must be concrete; use lax.dynamic_slice')\n    return int(i)","typeGuard":"def is_concrete_int(i) -> bool:\n    import jax; return not isinstance(i, jax.core.Tracer) and isinstance(i, (int, np.integer))","tryCatchPattern":null,"preventionTips":["Convert Python lists to jnp.array before jit so indexing works on tracers","Use lax.dynamic_slice/dynamic_update_slice for dynamic indices","Never use hex/oct/range on traced values inside transformations"],"tags":["jax","tracer","integer-conversion","indexing","jit"],"backgroundTag":"jax-tracer-concretization","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}