{"record":{"id":"53379e029fb051e6","repo":"jax-ml/jax","slug":"invalid-mixing-of-symbolic-scopes-when-nexpecte","errorCode":null,"errorMessage":"Invalid mixing of symbolic scopes {when}.\\nExpected {self_descr}scope {self}\\nand found for '{other}' ({other_descr}) scope {other.scope}\\nSee https://docs.jax.dev/en/latest/export/shape_poly.html#user-specified-symbolic-constraints.","messagePattern":"Invalid mixing of symbolic scopes (.+?)\\.\\\\nExpected (.+?)scope (.+?)\\\\nand found for '(.+?)' \\((.+?)\\) scope (.+?)\\\\nSee https://docs\\.jax\\.dev/en/latest/export/shape_poly\\.html#user-specified-symbolic-constraints\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/export/shape_poly.py","lineNumber":1114,"sourceCode":"            _DimTerm.from_operation(\n                _DimFactor.FLOORDIV, *before_f.operands, scope=constr.e1.scope),\n            before_k2, scope=constr.e1.scope)\n        before_e1 = before_f.operands[0]\n        self._process_explicit_constraint(\n            _SymbolicConstraint(cmp=Comparator.EQ,\n                                e1=k_times_floordiv, e2=before_e1,\n                                diff=k_times_floordiv - before_e1,\n                                debug_str=f\"{k_times_floordiv} == {before_e1}\")\n        )\n\n    self._explicit_constraints.append(constr)\n\n  def _check_same_scope(self, other: _DimExpr,\n                        when: str = \"\",\n                        self_descr: str = \" \",\n                        other_descr: str = \"unknown\"):\n    if self is not other.scope:\n      raise ValueError(\n          f\"Invalid mixing of symbolic scopes {when}.\\n\"\n          f\"Expected {self_descr}scope {self}\\n\"\n          f\"and found for '{other}' ({other_descr}) scope {other.scope}\\n\"\n          f\"See https://docs.jax.dev/en/latest/export/shape_poly.html#user-specified-symbolic-constraints.\")\n\n  def _clear_caches(self):\n    self._bounds_cache.clear()\n\n\nclass BoundsPrecision(enum.Enum):\n  \"\"\"Specifies desired precision for the bounds calculation.\n\n  Since the bounds calculations are expensive, we allow the caller to specify\n  a sufficient condition for a result. As the bounds calculations progresses\n  the lower bounds is progressively increased and the upper bounds is\n  progressively decreased. Depending on the precision, we may stop the\n  computation early, if the results are sufficient for the use case.\n","sourceCodeStart":1096,"sourceCodeEnd":1132,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/export/shape_poly.py#L1096-L1132","documentation":"All symbolic dimension expressions in one computation must belong to the same SymbolicScope (the constraint context created per export). Mixing dims from different scopes — e.g. reusing a variable from an earlier export or a manually built scope — makes constraint reasoning ill-defined and raises ValueError.","triggerScenarios":"Calling a previously exported polymorphic function with arguments whose shapes contain dim vars from another SymbolicScope; combining dims from two different exported functions; capturing a global scope variable across exports.","commonSituations":"Caching an exported function and composing it with another export; reusing shape objects or scope globals between two jax.export calls; pickling an export and mixing with fresh scopes.","solutions":["Re-export the functions together so they share one scope, or pass shapes as strings so each export creates its own consistent scope","Avoid reusing dim expressions or scope objects across different exports","Ensure the same polymorphic_shapes strings (and constraints) are used consistently when composing exported functions"],"exampleFix":"# before\nexp1 = jax.export.export(shapes('n,'))(f)\nexp2 = jax.export.export(shapes('m,'))(g)  # different scope vars mixed later\n# after\n# use the same variable name and a single export or shared scope\nexp2 = jax.export.export(shapes('n,'), constraints=('n >= 1',))(g)","handlingStrategy":"validation","validationCode":"# verify all dim exprs share one scope before combining\nassert len({d.scope for d in dims}) == 1, 'mixed symbolic scopes'","typeGuard":"def same_scope(*dims) -> bool:\n    scopes = {getattr(d, 'scope', None) for d in dims}\n    return len(scopes) == 1","tryCatchPattern":"try:\n    out = compose(exp1, exp2)\nexcept ValueError as e:\n    if 'mixing of symbolic scopes' in str(e): reexport_together()","preventionTips":["Never reuse dim expressions or scopes across separate exports","Use identical shape variable names and constraints when composing exports"],"tags":["jax","shape-polymorphism","scope","export"],"backgroundTag":"symbolic-scope-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}