{"record":{"id":"4bc3b661af887de0","repo":"jax-ml/jax","slug":"method-argument-to-poisson-must-be-one-of-exac","errorCode":null,"errorMessage":"method argument to `poisson` must be one of {'exact', 'approximate'}, got {method!r}","messagePattern":"method argument to `poisson` must be one of (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/core.py","lineNumber":2201,"sourceCode":"      sampling and supports only the threefry2x32 RNG. The ``'approximate'``\n      method is loop-free and faster but approximate: the total variation\n      distance from the exact distribution is below 1e-4.\n    out_sharding: Optional. Specifies how the output array should be sharded\n      across devices in multi-device computation. Can be a\n      :class:`~jax.sharding.NamedSharding`, a :class:`~jax.sharding.PartitionSpec`\n      (``P``), or ``None`` (default). When specified, the output will be sharded\n      according to the given sharding specification. Primarily used in explicit\n      sharding mode.\n      See the `explicit sharding tutorial <https://docs.jax.dev/en/latest/parallel.html>`_\n      for more details.\n\n  Returns:\n    A random array with the specified dtype and with shape given by ``shape`` if\n    ``shape is not None, or else by ``lam.shape``.\n  \"\"\"\n  key, _ = _check_prng_key(\"poisson\", key)\n  if method not in {'exact', 'approximate'}:\n    raise ValueError(\"method argument to `poisson` must be one of \"\n                     f\"{{'exact', 'approximate'}}, got {method!r}\")\n  dtype = dtypes.check_and_canonicalize_user_dtype(\n      int if dtype is None else dtype)\n  if shape is not None:\n    shape = core.canonicalize_shape(shape)\n  else:\n    shape = np.shape(lam)\n  out_sharding = canonicalize_sharding_for_samplers(out_sharding, \"poisson\", shape)\n  if method == 'approximate':\n    # don't preemptively broadcast lam, if lower rank it may save some computation\n    if lax.broadcast_shapes(np.shape(lam), shape) != shape:\n      raise ValueError(\"lam shape must be broadcastable to shape argument; \"\n                       f\"got lam.shape {np.shape(lam)}, shape {shape}\")\n    return maybe_auto_axes(_poisson_approx, out_sharding,\n                           shape=shape, dtype=dtype)(key, lam)\n  lam = jnp.broadcast_to(lam, shape)\n  # TODO(frostig): generalize underlying poisson implementation and\n  # remove this check","sourceCodeStart":2183,"sourceCodeEnd":2219,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/core.py#L2183-L2219","documentation":"jax.random.poisson accepts only method='exact' (algorithm restricted to the threefry2x32 PRNG, see the separate NotImplementedError) or method='approximate' (a normal/knuth-style approximation that works on any backend). Any other method string raises ValueError.","triggerScenarios":"Calling jax.random.poisson(key, lam, method='Normal') or any string not in {'exact','approximate'}; explicitly passing method=None.","commonSituations":"Config-driven method names shared across gamma/poisson; typos; users switching to method='approximate' when they hit the threefry2x32 restriction but misspelling it and getting this error instead.","solutions":["Use exactly 'exact' or 'approximate'.","If you hit this while migrating off the default, note method='approximate' avoids the threefry2x32-only limitation of 'exact'.","Validate method strings from config at load time."],"exampleFix":"// before\np = jax.random.poisson(key, 3.0, method='normal')\n\n// after\np = jax.random.poisson(key, 3.0, method='approximate')","handlingStrategy":"validation","validationCode":"method = method or 'exact'\nassert method in {'exact', 'approximate'}, 'poisson method must be exact or approximate'","typeGuard":"def is_valid_poisson_method(method: str) -> bool:\n    return method in {'exact', 'approximate'}","tryCatchPattern":null,"preventionTips":["On non-threefry PRNGs, plan for method='approximate'.","Validate method from config against the allowed set."],"tags":["jax","random","poisson","method","input-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}