Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`for` loops only accept sets and ranges — not `bit[n]`, arrays, aliases or index expressions

オープン
#393 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@TheGupta2012 がすでに取り組んでいます。

2026年8月24日 から。

  • #406 @TheGupta2012 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
compilers

調査の方向性

Start in Qasm3Visitor._visit_forin_loop at src/pyqasm/visitor.py (around line 2462), where the type check on statement.set_declaration rejects everything except DiscreteSet and RangeDefinition. Move that branch into a helper that returns a list of values, then add the array case first, since it doesn't depend on other work. Done when tests/qasm3/test_loop.py covers each iterable form and an index expression, a write to the loop variable leaves the source array unchanged, and a multi-dimensional array raises ValidationError.

索引モデルが issue の本文から書いたものです。

説明

enhancement llm-assisted qasm3 qasm3-coverage

Limitation

For loops states that the iterated <values> may
be any of:

  • a discrete set, e.g. {1, 2, 3}
  • a range expression, e.g. [0:2:10]
  • a value of type bit[n], or the target of a let statement aliasing classical bits
  • a value of type array[<scalar>, n] (one-dimensional)

and adds: "It is valid to use an indexing expression (e.g. my_array[1:3]) to arrive at one of
the types given above."

pyqasm implements only the first two. Any identifier or index expression as the iterable is
rejected.

Example QASM failure

Iterating a bit register:

OPENQASM 3.0;
bit[4] b = "1010";
for bit x in b { }
// ValidationError: Unexpected type <class 'openqasm3.ast.Identifier'> of set_declaration in loop.

Iterating an array:

OPENQASM 3.0;
array[int[8], 3] a = {1, 2, 3};
for int[8] i in a { }
// ValidationError: Unexpected type <class 'openqasm3.ast.Identifier'> of set_declaration in loop.

Iterating an index expression:

OPENQASM 3.0;
array[int[8], 4] a = {1, 2, 3, 4};
for int[8] i in a[1:2] { }
// ValidationError: Unexpected type <class 'openqasm3.ast.IndexExpression'> of set_declaration in loop.

Iterating a classical alias:

OPENQASM 3.0;
bit[4] b;
let c = b;
for bit x in c { }
// ValidationError: Qubit register b not found for aliasing

Change Requested

Extend the loop's iterable resolution to accept, in addition to the existing set and range
forms:

  1. An Identifier naming a bit[n] — loop variable type bit, iterating index 0..n-1.
  2. An Identifier naming a one-dimensional array[<scalar>, n] — loop variable type
    <scalar>, promoted to the declared loop variable type.
  3. An Identifier naming a classical alias.
  4. An IndexExpression that evaluates to any of the above.

Two spec rules to enforce while doing so:

  • Iteration order is guaranteed sequential by index: iden[0], then iden[1], and so on.
  • Assigning to the loop variable inside the body must not modify the underlying array element.

A multi-dimensional array as the iterable must raise a ValidationError — the spec restricts
this to one-dimensional arrays.

Implementation Details

  • The rejection is in Qasm3Visitor._visit_forin_loop at src/pyqasm/visitor.py:2462. It
    branches on the concrete type of statement.set_declaration and falls through for anything
    that is not a DiscreteSet or RangeDefinition.
  • Factor the branch into a helper that returns a plain Python list of values to iterate. That
    isolates the new cases and keeps the unrolling loop below unchanged.
  • Since the loop body is unrolled per value, the "assignment to the loop variable does not
    write back" rule falls out naturally from binding a copy into the loop scope each
    iteration — but add an explicit test, since it is easy to regress with a by-reference bind.
  • Depends on the bit[n] representation work for case 1 and on the classical-alias work for
    case 3; case 2 (arrays) is independent and could land first.
  • Tests: tests/qasm3/test_loop.py — one case per iterable form, an index-expression iterable,
    a write to the loop variable asserting the source array is unchanged, and a
    multi-dimensional array asserting a clean ValidationError.
主要言語
Python
スター
29
フォーク
33
平均マージ
2日 4時間
マージ済み PR(30日)
15

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

qBraid/pyqasm のほかの issue

qBraid/pyqasm の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。