Multi-level Bloq decomposition for symbolic Bloqs

オープン
#1,644 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
397
フォーク
127
平均マージ
2日 19時間
マージ済み PR(30日)
4

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

quantumlib/Qualtran のほかの issue

quantumlib/Qualtran の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。