Missing casts: `angle()` narrowing, `angle(float)`, and `int[n](bit[n])`
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- python
- Área
- compilers, quantum-computing
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 29
- Forks
- 33
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 15
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de qBraid/pyqasm
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
Los mantenedores suelen responder en 1 día
-
enhancement error-handling program-validation
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.pyPosiblemente ocupada @danielgaskins la tomó hace 11 días. Abiertoenhancement qasm2
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
qBraid/pyqasm#447 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASMPosiblemente ocupada @Jah-yee la tomó hace 19 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
qBraid/pyqasm#438 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lostPosiblemente ocupada @tonycoder-hub la tomó hace 12 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 22/100
qBraid/pyqasm#436 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de qBraid/pyqasm
Issues similares
-
Project submission:Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
slavakurilyak/awesome-ai-agents#845 ·
Los mantenedores suelen responder en 1 día
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directoryPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodifficulty:2 enhancement good first issue
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
MakazhanAlpamys/Soup#2178 ·
Los mantenedores suelen responder en 1 día
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
scverse/rapids-singlecell#854 ·
Los mantenedores suelen responder en 1 día
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGLPosiblemente ocupada @ninglinLiu la tomó hoy. Abiertoarea:frontend backend:slang bug direction:input
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
random_elements(unique=True) on an OrderedDict: ZeroDivisionError once only zero weights remain, AssertionError with use_weighting=FalsePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 13 días