`let` aliases: no `++` concatenation, no classical aliases, no alias-of-alias

Abierto
#392 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.

  • #406 de @TheGupta2012 — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
compilers

Línea de trabajo

Start in _visit_alias_statement in src/pyqasm/visitor.py, where the errors at about lines 2806 and 2811 are raised, then read how existing qubit aliases are stored as name-to-qubit-list mappings. Add handling for Concatenation values and alias-of-alias lookup, and extend the register lookup to classical bits. Tests belong in tests/qasm3/test_alias.py; done when the spec example runs end to end, but it also depends on the separate negative-indexing issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement llm-assisted qasm3 qasm3-coverage

Limitation

Aliasing and
Register concatenation and slicing
define let over qubit and classical registers, allow the ++ concatenation operator in the
aliased expression, and allow an alias to be built from another alias.

pyqasm supports only the simple and sliced qubit-register cases. The spec's own worked
example fails on its second line.

Example QASM failure

The spec's example, verbatim:

OPENQASM 3.0;
qubit[2] one;
qubit[10] two;
let concatenated = one ++ two;      // <-- fails here
let first = concatenated[0];
let last = concatenated[-1];
let qubit_selection = two[{0, 3, 5}];
let sliced = concatenated[0:6];
let every_second = concatenated[0:2:12];
let last_three = two[-4:-1];
let both = sliced ++ last_three;
ValidationError: Unsupported aliasing AliasStatement(... value=Concatenation(...))

Alias of an alias:

OPENQASM 3.0;
qubit[4] q;
let a = q;
let b = a[0];
// ValidationError: Qubit register a not found for aliasing

Classical register alias — the spec permits let over classical bits, and
For loops explicitly names "the target of a let
statement that creates an alias to classical bits" as an iterable:

OPENQASM 3.0;
bit[4] b;
let c = b;
// ValidationError: Qubit register b not found for aliasing
OPENQASM 3.0;
bit[2] a;
bit[2] b;
let c = a ++ b;
// ValidationError: Unsupported aliasing ...

Simple and sliced qubit aliases work today, including gates and delays applied to them, so the
alias machinery exists — it is the expression forms and the classical case that are missing.

Change Requested

  1. Handle openqasm3.ast.Concatenation as an alias value, for both qubit and bit registers,
    producing an alias whose length is the sum of its parts.
  2. Resolve an alias target that is itself an alias, by looking through to the underlying
    register. Nesting must work to arbitrary depth (sliced ++ last_three in the spec example
    concatenates two aliases).
  3. Support let over classical bit[n] registers, not only qubit registers, and correct the
    error message, which currently says "Qubit register ... not found" even when the name refers
    to a declared classical register.
  4. Support the discrete-set alias form two[{0, 3, 5}].

Negative indices inside alias expressions (concatenated[-1], two[-4:-1]) are covered by the
separate negative-indexing issue; the two should land together for the spec example to pass in
full.

Implementation Details

  • Alias handling is Qasm3Visitor._visit_alias_statement in src/pyqasm/visitor.py; the two
    errors above are raised at visitor.py:2806 ("Unsupported aliasing") and
    visitor.py:2811 ("Qubit register ... not found for aliasing").
  • The lookup at 2811 consults only the qubit register table. It needs to consult the classical
    scope as well, and the resulting alias must record which kind it is so downstream index
    resolution picks the right table.
  • Aliases are currently stored as a name → concrete-qubit-list mapping. Concatenation fits that
    model directly: resolve each operand to its list and join them. Alias-of-alias then works
    for free, provided the lookup checks the alias table before the register table.
  • Concatenation nodes may nest (a ++ b ++ c), so resolution should recurse rather than
    assume two operands.
  • A classical alias must be usable everywhere a bit[n] is: as a for iterable, indexed,
    sliced, and assigned to. Coordinate with the bit[n] representation issue.
  • Tests: tests/qasm3/test_alias.py — the spec example above as a single end-to-end case,
    plus qubit ++, bit ++, alias-of-alias, discrete-set alias, a gate applied through a
    concatenated alias, and a length-mismatch error case.
Lenguaje dominante
Python
Estrellas
29
Forks
33
Merge medio
1 d 20 h
PR fusionados (30 d)
8

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.