{"record":{"id":"fb3e15a0cc56d816","repo":"jax-ml/jax","slug":"value-of-type-type-self-is-not-convertible-to-h","errorCode":null,"errorMessage":"Value of type {type(self)} is not convertible to hex.","messagePattern":"Value of type (.+?) is not convertible to hex\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":1136,"sourceCode":"    return self.aval._int(self)\n\n  def __float__(self):\n    check_scalar_conversion(self)\n    if not hasattr(self.aval, \"_float\"):\n      raise TypeError(f\"Value of type {type(self)} is not convertible to float.\")\n    return self.aval._float(self)\n\n  def __complex__(self):\n    check_scalar_conversion(self)\n    if not hasattr(self.aval, \"_complex\"):\n      raise TypeError(f\"Value of type {type(self)} is not convertible to complex.\")\n    return self.aval._complex(self)\n\n  def __hex__(self):\n    if is_concrete(self): return hex(self.to_concrete_value())\n    check_integer_conversion(self)\n    if not hasattr(self.aval, \"_hex\"):\n      raise TypeError(f\"Value of type {type(self)} is not convertible to hex.\")\n    return self.aval._hex(self)\n\n  def __oct__(self):\n    if is_concrete(self): return oct(self.to_concrete_value())\n    check_integer_conversion(self)\n    if not hasattr(self.aval, \"_oct\"):\n      raise TypeError(f\"Value of type {type(self)} is not convertible to oct.\")\n    return self.aval._oct(self)\n\n  def __index__(self):\n    if is_concrete(self): return operator.index(self.to_concrete_value())\n    check_integer_conversion(self)\n    if not hasattr(self.aval, \"_index\"):\n      raise TypeError(f\"Value of type {type(self)} is not convertible to integer index.\")\n    return self.aval._index(self)\n\n  # raises a useful error on attempts to pickle a Tracer.\n  def __reduce__(self):","sourceCodeStart":1118,"sourceCodeEnd":1154,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L1118-L1154","documentation":"Raised by JAXTracer.__hex__ when hex() is called on a JAX Tracer whose aval does not implement _hex — i.e. on a symbolic value being traced by a JAX transformation. hex() requires a concrete integer on the host, which tracers do not have. JAX blocks it with a clear TypeError instead of failing obscurely later.","triggerScenarios":"Calling hex(tracer) inside code traced by jax.jit/grad/vmap/scan; formatting traced integer values with f'{x:#x}' or '%#x' % x (which routes through __format__/__hex__ paths); debugging prints of traced indices or counters.","commonSituations":"Debug-printing loop counters or indices from jax.lax.fori_loop/scan with hex formatting; porting bit-manipulation or hashing code that hex-dumps intermediate values; logging inside jitted functions.","solutions":["Remove hex() calls from traced code; use jax.debug.print with integer formatting to inspect values.","Return the traced integer from the function and hex() the concrete result on the host after the transformation completes.","If hex output of bits is required inside the trace, compute it symbolically with jax.numpy operations instead of the Python builtin."],"exampleFix":"# before\n@jax.jit\ndef f(i):\n    print(hex(i))   # TypeError\n    return i + 1\n\n# after\n@jax.jit\ndef f(i):\n    jax.debug.print('i={i}', i=i)\n    return i + 1","handlingStrategy":"validation","validationCode":"import jax\ndef describe_int(x) -> str:\n    if isinstance(x, jax.core.Tracer):\n        raise ValueError('cannot hex-format a tracer; inspect after transform returns')\n    return hex(int(x))","typeGuard":"import jax\ndef is_concrete_int(x) -> bool:\n    return not isinstance(x, jax.core.Tracer) and isinstance(int(x), int)","tryCatchPattern":"try:\n    s = hex(x)\nexcept TypeError as e:\n    if 'not convertible' in str(e):\n        jax.debug.print('x={x}', x=x); s = '<tracer>'\n    else:\n        raise","preventionTips":["Never format traced values with hex/oct/%-style format strings.","Route debug output through jax.debug.print.","Keep bit-dump/debug helpers operating on post-jit concrete outputs."],"tags":["jax","tracer","hex","formatting","debugging"],"backgroundTag":"jax-tracer-concretization","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}