Missing casts: `angle()` narrowing, `angle(float)`, and `int[n](bit[n])`
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- python
調査の方向性
Cast handling lives in Qasm3ExprEvaluator in src/pyqasm/expressions.py, with type maps in src/pyqasm/maps/expressions.py, and tests belong in tests/qasm3/test_casting.py. Start by reproducing the three rejected casts from the issue: angle[10](a + b), angle[20](f) from a float, and int[8](b) from a bit[8]. Note that the bit -> int case depends on the separate bit[n] operators issue, so it may need to wait. Done means each allowed cast returns the spec's value, angle narrowing matches the worked bit patterns, and forbidden casts raise a ValidationError naming both types.
索引モデルが issue の本文から書いたものです。
説明
Limitation
The allowed casts table permits float -> angle
and bit -> int, and the
floating-point numbers section shows
an angle narrowed to a smaller width with angle(...).
pyqasm rejects all three.
Example QASM failure
Narrowing an angle — the spec's own example:
OPENQASM 3.0;
angle[20] a = pi / 2;
angle[20] b = pi;
angle[10] c;
c = angle(a + b); // cast to angle[10]
ValidationError: Invalid initialization value for variable 'c'
float -> angle, marked Yes in the cast table:
OPENQASM 3.0;
float[64] f = 1.0;
angle[20] a = angle(f);
// ValidationError: Invalid initialization value for variable 'a'
bit -> int, also marked Yes:
OPENQASM 3.0;
bit[8] b = "00000101";
int[8] i = int[8](b);
// ValidationError: Invalid initialization value for variable 'i'
Casts that already work: int[n](float), uint(float), bool(int), bit[n](int).
Change Requested
angle(x)andangle[n](x)wherexis afloator anangle, applying the spec's
fixed-point semantics: anangle[n]represents a value in[0, 2π)withnbits of
precision, so narrowing truncates the low-order bits.int[n](b)anduint[n](b)wherebis abit[n], interpreting the bit register as the
integer's binary representation.- A cast the spec's table forbids must raise a
ValidationErrornaming both types, rather
than the current generic"Invalid initialization value"message.
Not in scope
float(duration)— the cast table marks this No;pyqasm's current rejection is correct.float(angle)— the table also marks this No, though the spec's own comparison example uses
it.pyqasmcurrently accepts it. Worth raising upstream onopenqasm/openqasmto settle
the inconsistency before changing behaviour either way.
Implementation Details
- Cast handling is in
Qasm3ExprEvaluator(src/pyqasm/expressions.py) together with the type
maps insrc/pyqasm/maps/expressions.py. - Angle semantics are the substantive part. An
angle[n]is a fixed-point value: the stored
integer isround(value / (2π) * 2**n), and narrowing fromangle[m]toangle[n]with
n < mtruncates. Implementing that as an explicit representation makes the spec's worked
results —7 * (pi / 8)asangle[4]being"0111"— directly assertable in tests. bit -> intdepends on the width-carrying bit representation from thebit[n]operators
issue; sequence that one first.- Encoding the spec's cast table as an explicit
(from_type, to_type) -> allowedmap gives
correct rejection messages for free and documents the supported surface in one readable
place. - Tests:
tests/qasm3/test_casting.py— each newly supported cast with its expected value,
angle narrowing against the spec's worked bit patterns, and a forbidden cast asserting a
ValidationErrorthat names both types.
- 主要言語
- 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 が 8 日前に担当しました。 オープン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 が 16 日前に担当しました。 オープン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 が 9 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 22/100
qBraid/pyqasm#436 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
[Bug]: Queen's own Ollama model loses num_ctx when a running session switches to it対応中かも @anasamin26 が今日担当しました。 オープンbug enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
aden-hive/hive#7508 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
llm translation
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
BerriAI/litellm#47884 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug 🐛
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
netalertx/NetAlertX#1856 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信