Skip to content

Fix BufferizationStage IR blowup for runtime-parameterized Hamiltonians (Reroll)#3036

Open
jk20342 wants to merge 10 commits into
PennyLaneAI:mainfrom
jk20342:reroll-loops
Open

Fix BufferizationStage IR blowup for runtime-parameterized Hamiltonians (Reroll)#3036
jk20342 wants to merge 10 commits into
PennyLaneAI:mainfrom
jk20342:reroll-loops

Conversation

@jk20342

@jk20342 jk20342 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Context:
qml.TrotterProduct with runtime coefficients (via qml.dot) causes severe IR
amplification: tracing unrolls all Trotter steps, and every gate angle drags a chain of
single-element tensor ops through bufferization, each becoming an alloc plus copies.
For an H2 QPE workload this meant ~62x total IR growth and ~19 GB of compiler memory.

Description of the Change:

New scalarize-tensor-extracts pass: folds tensor.extract through
extract_slice/collapse_shape/small elementwise linalg.generic, turning gate-angle
dataflow into scalar arithmetic.
New reroll-loops pass: detects repeated op sequences via structural hashing and
rebuilds them as scf.for loops.
Default pipeline (HLO stage only): scalarize + linalg-fuse-elementwise-ops before
reroll-loops, and a second scalarize after detensorization (which materializes the
extract chains).
Benefits:
On the H2 QPE benchmark, before/after measured on the same machine, same build, same
input IR, differing only in the pipeline: compile time 1h41m -> ~25s (~240x), peak
memory 15.4 GB -> 1.2 GB (12.8x), final IR 18.4 MB -> 5.4 MB (3.4x), post-bufferization
IR 7.45 MB -> 2.64 MB (2.8x). Output probabilities are bit-identical to the old pipeline.

these baseline numbers differ from the issue report (306 s, 21.3 GB, 241 MB final
IR) because the issue predates current main, which already reduced the
baseline's bufferization blowup (60 MB -> 7.45 MB post-bufferization; input IR drifted
3.86 -> 4.69 MB), and these measurements use an assertions-enabled dev build, ~20x
slower in wall time than the release wheel the issue used. Ratios within this PR are
apples-to-apples; absolute times are not comparable to the issue's.

Possible Drawbacks:
Both passes are conservative (size caps, semantic verification, high min-savings
default) but rerolling may miss non-contiguous repeats; overhead on workloads without
the pattern is negligible.

Related GitHub Issues:
Fixes #2759. Related: #1464, #1507.

jk20342 and others added 6 commits July 12, 2026 02:13
…tonians

Add scalarize-tensor-extracts and reroll-loops passes and re-order the
default pipeline so runtime-coefficient Trotterization no longer amplifies
IR through bufferization (9.9x -> ~1.0x on the H2 QPE benchmark).

Fixes PennyLaneAI#2759
…tonians

Add scalarize-tensor-extracts and reroll-loops passes and re-order the
default pipeline so runtime-coefficient Trotterization no longer amplifies
IR through bufferization (9.9x -> ~1.0x on the H2 QPE benchmark).

Fixes PennyLaneAI#2759
…tonians

Add scalarize-tensor-extracts and reroll-loops passes and re-order the
default pipeline so runtime-coefficient Trotterization no longer amplifies
IR through bufferization (9.9x -> ~1.0x on the H2 QPE benchmark).

Fixes PennyLaneAI#2759
…-loops pass (split from PennyLaneAI#3013)

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added the external PRs where the author is not a part of PennyLane Org (or part of external contributors team) label Jul 16, 2026
Updated pull request reference in changelog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PRs where the author is not a part of PennyLane Org (or part of external contributors team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BufferizationStage IR amplification for runtime-coefficient Hamiltonians under @qjit

1 participant