Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`stretch` operands in duration arithmetic raise `TypeError: ... 'float' and 'NoneType'`

未关闭
#389 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@SAY-5 已经在做这个了。

开始于 2026年8月26日。

  • #417 来自 @SAY-5 —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
18/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
compilers

调研方向

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 内容生成。

描述

bug error-handling llm-assisted qasm3

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

  1. Duration expressions containing a stretch operand must not raise a Python TypeError.
  2. Preferred: represent a duration as an affine value (constant_ns, {stretch: coefficient})
    so that a + s, 2 * s, and a + 2 * s are all representable symbolically and can be
    emitted unchanged by dumps().
  3. Minimum acceptable: raise a ValidationError stating 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.py alongside the other
    classical declarations; the numeric evaluation happens in Qasm3ExprEvaluator
    (src/pyqasm/expressions.py), which is where the float + None occurs.
  • Unit conversion lives in DURATION_UNITS in src/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 and delay[...]
    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 inside box[...], and a dumps() round-trip.
主要语言
Python
星标
29
派生
33
平均合并
2 天 4 小时
30 天内合并 PR
15

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

qBraid/pyqasm 的其他 Issue

查看 qBraid/pyqasm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。