Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Missing casts: `angle()` narrowing, `angle(float)`, and `int[n](bit[n])`

Abierto
#399 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@TheGupta2012 ya está trabajando en esto.

Desde el 24/8/2026.

  • #409 de @TheGupta2012 — abierto

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

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

enhancement llm-assisted qasm3 qasm3-coverage

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

  1. angle(x) and angle[n](x) where x is a float or an angle, applying the spec's
    fixed-point semantics: an angle[n] represents a value in [0, 2π) with n bits of
    precision, so narrowing truncates the low-order bits.
  2. int[n](b) and uint[n](b) where b is a bit[n], interpreting the bit register as the
    integer's binary representation.
  3. A cast the spec's table forbids must raise a ValidationError naming 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. pyqasm currently accepts it. Worth raising upstream on openqasm/openqasm to settle
    the inconsistency before changing behaviour either way.

Implementation Details

  • Cast handling is in Qasm3ExprEvaluator (src/pyqasm/expressions.py) together with the type
    maps in src/pyqasm/maps/expressions.py.
  • Angle semantics are the substantive part. An angle[n] is a fixed-point value: the stored
    integer is round(value / (2π) * 2**n), and narrowing from angle[m] to angle[n] with
    n < m truncates. Implementing that as an explicit representation makes the spec's worked
    results — 7 * (pi / 8) as angle[4] being "0111" — directly assertable in tests.
  • bit -> int depends on the width-carrying bit representation from the bit[n] operators
    issue; sequence that one first.
  • Encoding the spec's cast table as an explicit (from_type, to_type) -> allowed map 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
    ValidationError that names both types.
Lenguaje dominante
Python
Estrellas
29
Forks
33
Merge medio
2 d 4 h
PR fusionados (30 d)
15

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de qBraid/pyqasm

Todos los issues de qBraid/pyqasm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.