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

`input` and `output` declarations are unusable

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start with Qasm3Visitor._visit_classical_declaration in src/pyqasm/visitor.py, and check how the IODeclaration node from openqasm3 falls through without a scope entry. Reproduce the four failing snippets in the issue, then read tests/qasm3/test_declarations.py. Done means those snippets validate, output can be a measurement target, and dumps() keeps both qualifiers. The binding-versus-symbolic question must be settled by a maintainer before implementation.

由索引模型根据 Issue 内容生成。

描述

enhancement llm-assisted qasm3 qasm3-coverage

Limitation

Input/output defines input and output
modifiers on classical declarations. input marks a value supplied at run time — the spec's
motivating case is a parameterised circuit compiled once and executed many times with
different angles. output marks a value returned to the host.

pyqasm parses both declarations but never registers them in scope. Any later use fails.

Example QASM failure

The spec's own parameterised-circuit pattern:

OPENQASM 3.0;
include "stdgates.inc";
input float[64] a;
qubit[1] q;
rx(a) q[0];
// ValidationError: Invalid parameter 'a' for gate 'rx'

An input used in ordinary classical code fails the same way:

OPENQASM 3.0;
input int[8] a;
int[8] b = a;
// ValidationError: Invalid initialization value for variable 'b'

output is not registered either:

OPENQASM 3.0;
output bit[2] c;
qubit[2] q;
c = measure q;
// ValidationError: Missing register declaration for 'c' in measurement operation
OPENQASM 3.0;
output int[8] c;
c = 1;
// ValidationError: Undefined variable c in assignment

A bare input bit[2] a; with no subsequent use validates cleanly, which confirms the
declaration is parsed and then discarded.

Change Requested

  1. Register input and output declarations in the global scope with their declared types,
    so that every later reference resolves.
  2. An output-qualified variable must be assignable, including as a measurement target.
  3. Preserve both qualifiers through dumps() — a round-trip must not silently turn an input
    into an ordinary declaration.
  4. Enforce the spec's scope rule: input and output are permitted only in global scope.

Open design question

pyqasm's unroller evaluates classical expressions to concrete values, but an input has no
value at analysis time. Two viable directions, and this issue should settle which:

  • Binding API — accept values at load or unroll time, e.g.
    pyqasm.loads(qasm, inputs={"a": 0.5}), and substitute them during unrolling. Concrete
    output, no representation change, but requires the caller to supply every input.
  • Symbolic passthrough — treat an unbound input as an opaque symbol, validate its type
    and usage, and emit the expression unevaluated. Keeps the program parameterised at the cost
    of expression handling that tolerates non-numeric operands.

Supporting both — bind when a value is given, pass through when it is not — is likely the
right end state, but the first increment should pick one. Maintainer input needed.

Implementation Details

  • openqasm3 exposes the qualifier as IOKeyword.input / IOKeyword.output on
    ClassicalDeclaration / IODeclaration. Confirm which node type the parser produces for
    each so the visitor branches correctly.
  • The declaration path is Qasm3Visitor._visit_classical_declaration in
    src/pyqasm/visitor.py; the IODeclaration node appears to fall through without a scope
    entry. Registering the variable is the minimal fix that clears all four failures above.
  • The error "Invalid parameter 'a' for gate 'rx'" comes from the gate-argument evaluation
    path — it fires because the identifier does not resolve, so scope registration fixes it
    directly under the binding approach, and requires expression-level tolerance under the
    symbolic approach.
  • output needs the variable marked assignable and visible to the measurement path that
    raises "Missing register declaration for 'c' in measurement operation".
  • Tests: tests/qasm3/test_declarations.py — input in a gate argument, input in classical
    arithmetic, output as a measurement target, output in a plain assignment, a dumps()
    round-trip preserving both keywords, and input declared inside a def body raising a
    ValidationError.
主要语言
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 摘要。