Multi-level Bloq decomposition for symbolic Bloqs

Đang mở
#1,644 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend-api-design

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
397
Fork
127
Merge trung bình
2 ngày 19 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quantumlib/Qualtran

Tất cả issue của quantumlib/Qualtran

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.