`for` loops only accept sets and ranges — not `bit[n]`, arrays, aliases or index expressions
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 aletstatement 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:
- An
Identifiernaming abit[n]— loop variable typebit, iterating index0..n-1. - An
Identifiernaming a one-dimensionalarray[<scalar>, n]— loop variable type
<scalar>, promoted to the declared loop variable type. - An
Identifiernaming a classical alias. - An
IndexExpressionthat evaluates to any of the above.
Two spec rules to enforce while doing so:
- Iteration order is guaranteed sequential by index:
iden[0], theniden[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_loopatsrc/pyqasm/visitor.py:2462. It
branches on the concrete type ofstatement.set_declarationand falls through for anything
that is not aDiscreteSetorRangeDefinition. - 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 cleanValidationError.
- Ngôn ngữ chính
- Python
- Star
- 29
- Fork
- 33
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 15
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của qBraid/pyqasm
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement error-handling program-validation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.pyCó thể đã có người làm @danielgaskins đã nhận 8 ngày trước. Đang mởenhancement qasm2
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
qBraid/pyqasm#447 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASMCó thể đã có người làm @Jah-yee đã nhận 16 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
qBraid/pyqasm#438 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lostCó thể đã có người làm @tonycoder-hub đã nhận 10 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 22/100
qBraid/pyqasm#436 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của qBraid/pyqasm
Issue tương tự
-
follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Download helper still uses huggingface_hub arguments removed in 1.0: USE_SYMLINKS is silently ignored and every download ends with a WinError 3 lineCó thể đã có người làm @li-lizhe đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
IPv6 node addresses produce an invalid request URLCó thể đã có người làm @RaphaelFakhri đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
typesense/typesense-python#154 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
elastic/elasticsearch-py#3592 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
developmentseed/titiler-cmr#250 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày