Subroutines that return `bit` / `bit[n]` fail, including `return measure q;`
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Start by running the def f() -> bit snippet to reproduce the AttributeError, then find the .value dereference on the return path in src/pyqasm/subroutines.py and the call/return visiting in src/pyqasm/visitor.py. The measurement-return case needs a design decision about the caller's classical bit, and the issue says it depends on the bit[n] representation change. Done means the bit, bit[n] and return measure q cases in tests/qasm3/test_function.py either work or raise a ValidationError naming both types.
索引モデルが issue の本文から書いたものです。
説明
Limitation
Subroutines allow any classical scalar return type,
including bit and bit[n], and the spec shows returning a measurement result directly.
pyqasm crashes with an AttributeError for a bit return, and rejects bit[n] returns and
measurement returns with a misleading "Invalid initialization value" error at the call site.
Example QASM failure
Internal error:
OPENQASM 3.0;
def f() -> bit {
bit b;
return b;
}
bit x = f();
AttributeError: 'NoneType' object has no attribute 'value'
Register return, rejected:
OPENQASM 3.0;
def f() -> bit[2] {
bit[2] b;
return b;
}
bit[2] x = f();
// ValidationError: Invalid initialization value for variable 'x'
Returning a measurement — the idiom the spec uses:
OPENQASM 3.0;
include "stdgates.inc";
def f(qubit q) -> bit {
return measure q;
}
qubit[1] r;
bit b = f(r[0]);
// ValidationError: Invalid initialization value for variable 'b'
Assigning first does not help:
def f(qubit q) -> bit {
bit c;
c = measure q;
return c;
}
// ValidationError: Invalid initialization value for variable 'b'
For contrast, -> int[8], -> float[64] and -> bool returns all work today, so the gap is
specific to bit-typed returns.
Change Requested
def ... -> bitanddef ... -> bit[n]must return a usable value that can initialise or
be assigned to a matchingbit/bit[n]variable.return measure q;inside a subroutine must be accepted, with the measurement recorded in
the unrolled program and its result becoming the return value.- A genuine type mismatch between the declared return type and the returned expression must
raise aValidationErrornaming both types — never anAttributeError.
Change note
This is distinct from #311, which concerns qubit index remapping for arguments passed into a
subroutine. This issue is about the return path and bit-typed values.
Implementation Details
- Subroutine handling is in
src/pyqasm/subroutines.pytogether with the call/return visiting
insrc/pyqasm/visitor.py. - The
AttributeError: 'NoneType' object has no attribute 'value'indicates the return-value
path assumes the returned object carries a.value— true for the literal-backed numeric
types, false for the bit representation. Locating that dereference identifies the fix site
directly. - The measurement case is the harder half: a measurement inside a subroutine body must both
(a) emit aQuantumMeasurementStatementinto the unrolled output against the caller's
qubit, and (b) bind its classical result to the return value. Decide whether to synthesise a
temporary classical bit in the caller's scope for this, which keeps the emitted program
valid OpenQASM. - This depends on the
bit[n]representation change tracked in the bit-register operators
issue; sequencing that one first will make this fix smaller. - Tests:
tests/qasm3/test_function.py—-> bit,-> bit[n],return measure q, assign-
then-return, a declared/returned type mismatch, and a nested subroutine that forwards a bit
return.
- 主要言語
- Python
- スター
- 29
- フォーク
- 33
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
qBraid/pyqasm#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM対応中かも @Jah-yee が 18 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
qBraid/pyqasm#438 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lost対応中かも @tonycoder-hub が 11 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 22/100
qBraid/pyqasm#436 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
push_gh-pages fails on master branch on forks対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンgood first issue infrastructure
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
documentation priority: high
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
a-lex-s/mealie-telegram-bot#54 ·
メンテナーはふだん 1 日以内に返信
-
type/test
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
SaltedTan/virgil-language-server#218 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
btclib-org/btclib-wallet#541 ·
メンテナーはふだん 1 日以内に返信