Multi-level Bloq decomposition for symbolic Bloqs

Abierto
#1,644 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Start with the symbolic-width guards in Bloqs such as LessThanEqual, QROM, and CSwap, and trace how decompose_bloq() and _decompose_from_build_composite_bloq() handle decomposition. The issue gives a minimal reproduction using StatePreparationAliasSampling.from_n_coeff; run it to confirm the failure and inspect the resulting call graph. Done means symbolic subtrees expand into QREF routines with port definitions and connection wiring so GraphViz preserves their topology.

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

Descripción

qref_interop

Description:

When you instantiate certain Bloq subclasses with Sympy symbols for register widths (e.g.)

StatePreparationAliasSampling.from_n_coeff(L, lam, precision=eps)

the call to decompose_bloq() immediately raises

DecomposeTypeError("bitsize must be a concrete value")

because each of these Bloq classes contains a guard like:

if not isinstance(self.bitsize, int):
    raise DecomposeTypeError("bitsize must be a concrete value")

This affects many Bloqs (e.g. LessThanEqual, QROM, CSwap, etc.) and prevents any symbolic-parameter subtree from ever being expanded when you convert to QREF + GraphViz. All you ever see is a monolithic leaf.

There is a private _decompose_from_build_composite_bloq() that builds a CompositeBloq via the call-graph, but it still runs the same per-class guards, so it also refuses on symbolic bitsizes.

Why the “obvious” fixes don’t work
  • Centralizing dual-fallback in the QREF importer
    We could catch DecomposeTypeError and call _decompose_from_build_composite_bloq() instead—but that builder itself enforces the same isinstance(bitsize, int) checks, so symbolic widths are still rejected.

  • Using from_callgraph=True
    There is already a bloq_to_qref(..., from_callgraph=True) path, but it only reconstructs a flat call-graph of Bloqs. It does not produce real port definitions or connection wiring in the resulting RoutineV1, so to_graphviz on that schema loses all topology.

Minimal repro

import sympy
from qualtran.bloqs.state_preparation import StatePreparationAliasSampling

L, lam, eps = sympy.symbols("L lam eps")
alias = StatePreparationAliasSampling.from_n_coeff(L, lam, precision=eps)

cb = alias.decompose_bloq()       # CompositeBloq with 5 leaves
for inst in cb.bloq_instances:
    inst.bloq.decompose_bloq()    # always raises DecomposeTypeError

Related

MR #1643 adds a dual-fallback for numeric Bloqs, but it still fails for symbolic cases because of the per-class guards.

Tagging @mstechly

Lenguaje dominante
Python
Estrellas
397
Forks
127
Merge medio
2 d 19 h
PR fusionados (30 d)
4

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 quantumlib/Qualtran

Todos los issues de quantumlib/Qualtran

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.