`stretch` operands in duration arithmetic raise `TypeError: ... 'float' and 'NoneType'`
维护者通常 1 天内回复
评估
调研方向
The float + None error comes from Qasm3ExprEvaluator in src/pyqasm/expressions.py, and stretch declarations are handled in src/pyqasm/visitor.py; unit handling is in DURATION_UNITS in src/pyqasm/maps/expressions.py. Check open pull request #417 first, since it may already cover this. Done means a + s no longer raises a Python TypeError: it either survives symbolically or raises a ValidationError naming the stretch variable and its span, with tests in tests/qasm3/test_timing.py.
由索引模型根据 Issue 内容生成。
描述
Limitation
Duration and stretch types defines
stretch as a duration that resolves at compile time, and
Operations on durations allows a
stretch to be combined with a duration in arithmetic. This is how the spec expresses
padding that absorbs whatever slack a schedule leaves.
pyqasm declares a stretch with a None value and then applies Python arithmetic to it,
producing an uncaught TypeError.
Example QASM failure
import pyqasm
m = pyqasm.loads('''
OPENQASM 3.0;
stretch s;
duration a = 300ns;
duration b = a + s;
''')
m.validate()
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'
A bare stretch s; declaration and delay[s] q[0]; both work today, so the gap is confined
to arithmetic involving a stretch operand.
Change Requested
- Duration expressions containing a
stretchoperand must not raise a PythonTypeError. - Preferred: represent a duration as an affine value
(constant_ns, {stretch: coefficient})
so thata + s,2 * s, anda + 2 * sare all representable symbolically and can be
emitted unchanged bydumps(). - Minimum acceptable: raise a
ValidationErrorstating that stretch arithmetic is not yet
supported, naming the stretch variable and its span. The current internal error is the only
unacceptable outcome.
Implementation Details
- Duration/stretch declarations are handled in
src/pyqasm/visitor.pyalongside the other
classical declarations; the numeric evaluation happens inQasm3ExprEvaluator
(src/pyqasm/expressions.py), which is where thefloat + Noneoccurs. - Unit conversion lives in
DURATION_UNITSinsrc/pyqasm/maps/expressions.py; the affine
representation should normalise the constant part to nanoseconds there, consistent with how
plain durations are already handled. - The affine form composes with the existing
box[...]duration validation anddelay[...]
handling, both of which currently expect a plain number — they will need to accept the new
type or explicitly reject a non-constant duration where a concrete one is required. - Full stretch resolution (solving for stretch values against a schedule) is a much larger
piece of work and is explicitly out of scope here. This issue only asks that stretch
operands survive expression evaluation. - Tests:
tests/qasm3/test_timing.py(or the existing delay/box tests) —a + s,2 * s,
a + 2 * s, a stretch insidebox[...], and adumps()round-trip.
- 主要语言
- Python
- 星标
- 29
- 派生
- 33
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 15
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
qBraid/pyqasm 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复
-
enhancement error-handling program-validation
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.py可能已有人在做 @danielgaskins 于 10 天前认领。 未关闭enhancement qasm2
难度 4/5 3-5 天 新手友好度 22/100
维护者通常 1 天内回复
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM可能已有人在做 @Jah-yee 于 18 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 25/100
维护者通常 1 天内回复
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lost可能已有人在做 @tonycoder-hub 于 12 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 22/100
维护者通常 1 天内回复
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
fossasia/visdom-dev#77 ·
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
aws-cloudformation/cfn-lint#4890 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
volcengine/OpenViking#6521 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
-
bug
难度 2/5 1-3 小时 新手友好度 77/100
AstrBotDevs/AstrBot#10720 ·
维护者通常 1 天内回复