{"record":{"id":"af4b0c0c6f6d513c","repo":"jax-ml/jax","slug":"compound-factors-should-be-one-level-nested-brack","errorCode":null,"errorMessage":"Compound factors should be one level, nested brackets are not allowed","messagePattern":"Compound factors should be one level, nested brackets are not allowed","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":282,"sourceCode":"            \"Ellipsis can only be used at the beginning of a dimension\")\n      if rule_index < rule_len and rule[rule_index].isdigit():\n        batching_group_str = \"\"\n        while rule_index < rule_len and rule[rule_index].isdigit():\n          batching_group_str += rule[rule_index]\n          rule_index += 1\n        batching_group = str(int(batching_group_str))\n      else:\n        batching_group = \"0\"\n\n      add_factor(f\"{BATCHING}{batching_group}\")\n      continue\n    if char in \"(), \":\n      if current_factor is not None:\n        add_factor(current_factor)\n        current_factor = None\n      if char == \"(\":\n        if current_compound_dim is not None:\n          raise ValueError(\n              \"Compound factors should be one level, nested brackets are not\"\n              \" allowed\")\n        current_compound_dim = []\n      elif char == \")\":\n        if current_compound_dim is None:\n          raise ValueError(\"Brackets are not balanced\")\n        if len(current_compound_dim) <= 1:\n          raise ValueError(\"Brackets should contain at least two factors\")\n        value.append(CompoundFactor(*current_compound_dim))\n        current_compound_dim = None\n      elif char == \",\":\n        all_values.append(ArrayMapping(*value))\n        value = []\n    elif char == \"_\" or char.isdigit() or char.isalpha():\n      if current_factor is None:\n        if str.isdigit(char):\n          raise ValueError(f\"Factor names have to start with a letter, but got '{char}'\")\n        current_factor = char","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L264-L300","documentation":"Compound factors support only one level of parentheses, e.g. '(a,b)'. _parse_values tracks current_compound_dim and rejects a second '(' while already inside a compound factor.","triggerScenarios":"Rule containing '((a,b),c)' or '(a,(b,c))'.","commonSituations":"Trying to express hierarchical factor trees like mesh axis trees in the rule string.","solutions":["Flatten to a single level: '(a,b,c)'","Express deeper structure via factor_sizes and separate factors instead of nesting"],"exampleFix":"# before\nrule = '((a,b),c)->(a,b,c)'\n# after\nrule = '(a,b,c)->(a,b,c)'","handlingStrategy":"validation","validationCode":"import re\nassert not re.search(r'\\([^)]*\\(', rule), 'nested compound factors not allowed'","typeGuard":"import re\ndef is_flat_compounds(rule: str) -> bool:\n    return re.search(r'\\([^)]*\\(', rule) is None","tryCatchPattern":null,"preventionTips":["Keep compound factors one level deep: '(a,b,c)'"],"tags":["jax","sharding","compound-factor","rule-syntax"],"backgroundTag":"unsupported-syntax-nesting","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}