Skip to content

[Bug]: Auto-allocated measurement names make conditionals unparseable under the canonical grammar #12

Description

@fedonman

Bug Description

A measurement on a schema-backed bus with no explicit name= gets an auto-name that embeds the bus path, q0/readout/m0, because _measurement_name_prefix joins with a slash. The writer's _MEASUREMENT_REF_UNSAFE pattern does not list / as unsafe, so a conditional on that handle goes out unquoted as if q0/readout/m0.state == 1:. The production parser reads it back fine, but qp.lark's DOTTED_NAME terminal only admits identifier characters, so the reference parser lexes the slash as BIN_OP and fails. The default path therefore produces a file the normative grammar rejects; either give the auto-name a token-safe separator or widen the grammar's handle terminal.

Minimal Reproducible Example

import qprogram as qp
from qprogram.buses import BusSchema
from qprogram.grammar import parse_text

s = BusSchema.transmon()
p = qp.QProgram(schema=s)
m = p.measure(s.q[0].readout, "readout", "weights")
with p.if_(m.state == 1):
    p.wait(s.q[0].drive, 100)
parse_text(qp.dumps(p))

Expected Behavior

Writer output parses under the canonical grammar, which is what tests/test_grammar.py exists to keep true.

Actual Behavior

lark.exceptions.UnexpectedToken: Unexpected token Token('BIN_OP', '/') at line 10, column 8.
Expected one of: 
	* CMP_OP

.qp Text

body:
  measure q[0].readout "readout" "weights" name="q0/readout/m0"
  if q0/readout/m0.state == 1:
    wait q[0].drive 100

System Information

qprogram 0.1.0
python   3.14.3 | Linux-7.0.0-30-generic-x86_64-with-glibc2.43
vendors  none

Metadata

Metadata

Assignees

No one assigned

    Labels

    serializationTouches the .qp writer, parser, registry and grammar

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions