Classical value bit-slicing on `int` / `uint` is unsupported
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by reproducing the failures with the single-bit read int[32] myInt = 15; bit[1] lastBit = myInt[0]; and the chained intArr[0][0] case, then trace them through Qasm3Analyzer.analyze_classical_indices in src/pyqasm/analyzer.py. The issue depends on the separate bit[n] operators work and the negative-indexing issue, and it leaves the reversed slice myInt[-1:-16] semantics unresolved, so confirm those first. Done means the read, slice, assignment, array-element and out-of-range cases pass in tests/qasm3/test_expressions.py.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Limitation
Classical value bit slicing allows
indexing and slicing the bit representation of an integer, both as a read and as an assignment
target.
pyqasm supports neither.
Example QASM failure
The spec's example, verbatim:
OPENQASM 3.0;
int[32] myInt = 15; // 0xF or 0b1111
bit[1] lastBit = myInt[0]; // 1
bit[1] signBit = myInt[31]; // 0
bit[1] alsoSignBit = myInt[-1]; // 0
bit[16] evenBits = myInt[0:2:31]; // 3
bit[16] upperBits = myInt[-16:-1];
bit[16] upperReversed = myInt[-1:-16];
myInt[4:7] = "1010"; // myInt == 0xAF
Each read fails:
ValidationError: Invalid initialization value for variable 'lastBit'
The slice assignment fails with a misleading cast message:
ValidationError: Cannot cast 'str' to 'IntType'.
Invalid assignment of type 'str' to variable 'myInt' of type 'IntType'
uint behaves identically:
OPENQASM 3.0;
uint[32] i = 15;
bit b = i[0];
// ValidationError: Invalid initialization value for variable 'b'
Bit-slicing an array element, also from the spec:
OPENQASM 3.0;
array[int[32], 5] intArr = {0, 1, 2, 3, 4};
intArr[0][0] = 1;
// ValidationError: Invalid index for variable 'intArr'
bit[5] b = intArr[4][0:4];
// ValidationError: Invalid initialization value for variable 'b'
Change Requested
i[k]on anint[n]/uint[n]yieldsbit, with index 0 the least-significant bit.i[a:b]andi[a:step:b]yieldbit[k], following the spec's inclusive-range convention.i[a:b] = <bit[k]>writes back into the integer's bit representation.- The same forms work on an array element:
arr[i][k]andarr[i][a:b]. - An index outside
[0, n)after negative-index normalisation raises aValidationError
naming the width.
Negative indices in these expressions are covered by the separate negative-indexing issue;
both are needed for the spec example to pass in full.
Implementation Details
- Index resolution is
Qasm3Analyzer.analyze_classical_indicesinsrc/pyqasm/analyzer.py.
It currently assumes the indexed variable is a container; an integer scalar reaches it and
produces the generic initialisation failure. - Add an integer-bit-view path: convert the value to a fixed-width bit vector of the declared
width, index or slice it, and convert back on assignment. The declared width — not the
magnitude of the value — determines valid indices, soint[32] myInt = 15; myInt[31]must
be valid and yield0. - The assignment path needs the same treatment; the
"Cannot cast 'str' to 'IntType'"error
shows the RHSbit[k]reaching the scalar-assignment check unmodified. - Chained indexing
intArr[0][0]requires the index resolver to handle a secondIndexExpression
applied to the result of the first, rather than flattening both into one index list — which
is what produces"Invalid index for variable 'intArr'"today. - Shares the width-carrying bit representation from the
bit[n]operators issue; sequence that
one first. - Confirm the intended semantics of the spec's reversed slice
myInt[-1:-16]and cover it
explicitly. - Tests:
tests/qasm3/test_expressions.py— single-bit read, stepped slice read, slice
assignment, array-element bit access,uintvariants, and an out-of-range index error.
- Lingua principale
- Python
- Stelle
- 29
- Fork
- 33
- Merge medio
- 1g 20h
- PR unite (30g)
- 8
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di qBraid/pyqasm
-
dumps() prints the original program when unroll() leaves at most one statementForse già presa @ShiveshDragon l’ha presa 9 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
qBraid/pyqasm#493 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement error-handling program-validation
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 43/100
I maintainer di solito rispondono entro 1 giorno
-
dependencies enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di qBraid/pyqasm
Issue simili
-
docs(contributing): the two things that silently block a PRForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaavailable documentation good first issue
Difficoltà 1/5 1-3 ore Idoneità per principianti 95/100
Nixitov/Riptide-Native#944 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
JTHCode/secretguard#24 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
omarelshamy25x/shamy-hijri#63 ·
I maintainer di solito rispondono entro 1 giorno