Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions .agent/audits/controlled-rotation-quality.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
axis,controls,angle,backend,synthesis_ms,raw_cx,raw_one_qubit,raw_depth,raw_cx_depth,optimized_cx,optimized_one_qubit,optimized_depth,optimized_cx_depth,max_operator_error
rx,2,numeric,core,0.272258,4,6,10,4,4,5,9,4,2.1153413308660057e-16
rx,2,numeric,qiskit,0.033504,8,15,18,8,8,7,13,8,3.298440587052649e-16
rx,2,symbolic,core,0.365394,4,6,10,4,4,6,10,4,3.1401849173675503e-16
rx,2,symbolic,qiskit,0.043104,8,15,18,8,8,9,15,8,3.3306690738754696e-16
rx,3,numeric,core,0.382035,14,24,28,12,14,16,20,12,1.5331320705493272e-15
rx,3,numeric,qiskit,0.069664,20,35,42,20,20,15,29,20,7.610516769633753e-16
rx,3,symbolic,core,0.384211,14,24,28,12,14,20,24,12,1.2780539954372932e-15
rx,3,symbolic,qiskit,0.086401,20,35,42,20,20,21,35,20,4.440892098500626e-16
rx,4,numeric,core,0.433683,24,42,46,18,24,28,34,18,2.3361959382837703e-15
rx,4,numeric,qiskit,0.189521,24,42,46,18,24,28,34,18,2.3361959382837703e-15
rx,4,symbolic,core,0.448979,24,42,46,18,24,36,40,18,2.558937633260452e-15
rx,4,symbolic,qiskit,0.087009,24,42,46,18,24,36,40,18,2.558937633260452e-15
rx,5,numeric,core,0.26325,40,58,70,34,40,48,64,34,2.6801557172297703e-15
rx,5,numeric,qiskit,0.074576,40,58,70,34,40,48,64,34,2.6801557172297703e-15
rx,5,symbolic,core,0.265666,40,58,70,34,40,56,68,34,3.9563492527737815e-15
rx,5,symbolic,qiskit,0.095857,40,58,70,34,40,56,68,34,3.9563492527737815e-15
rx,6,numeric,core,0.350434,56,74,86,38,56,69,76,38,
rx,6,numeric,qiskit,0.089969,56,74,86,38,56,69,76,38,
rx,6,symbolic,core,0.342834,56,74,86,38,56,75,84,38,
rx,6,symbolic,qiskit,0.101105,56,74,86,38,56,75,84,38,
rx,7,numeric,core,0.426562,80,124,176,80,80,88,152,80,
rx,7,numeric,qiskit,0.250914,80,124,176,80,80,88,152,80,
rx,7,symbolic,core,0.934085,80,124,176,80,80,96,156,80,
rx,7,symbolic,qiskit,0.306498,80,124,176,80,80,96,156,80,
rx,8,numeric,core,1.081863,104,174,213,98,104,120,185,98,
rx,8,numeric,qiskit,0.24325,104,174,200,89,104,120,170,89,
rx,8,symbolic,core,1.085719,104,174,213,98,104,128,185,98,
rx,8,symbolic,qiskit,0.315538,104,174,200,89,104,128,170,89,
rx,9,numeric,core,1.210728,120,198,248,112,120,136,213,112,
rx,9,numeric,qiskit,0.253954,120,198,248,108,120,136,209,108,
rx,9,symbolic,core,1.215672,120,198,248,112,120,144,213,112,
rx,9,symbolic,qiskit,0.306066,120,198,248,108,120,144,209,108,
rx,10,numeric,core,1.361704,136,222,293,130,136,152,249,130,
rx,10,numeric,qiskit,0.277426,136,222,280,121,136,152,234,121,
rx,10,symbolic,core,1.386809,136,222,293,130,136,160,249,130,
rx,10,symbolic,qiskit,0.329666,136,222,280,121,136,160,234,121,
rx,16,numeric,core,2.290686,232,366,533,226,232,248,441,226,
rx,16,numeric,qiskit,0.335074,232,366,520,217,232,248,426,217,
rx,16,symbolic,core,2.301854,232,366,533,226,232,256,441,226,
rx,16,symbolic,qiskit,0.378083,232,366,520,217,232,256,426,217,
rx,32,numeric,core,4.60406,488,750,1173,482,488,504,953,482,
rx,32,numeric,qiskit,0.472531,488,750,1160,473,488,504,938,473,
rx,32,symbolic,core,4.589452,488,750,1173,482,488,512,953,482,
rx,32,symbolic,qiskit,0.519923,488,750,1160,473,488,512,938,473,
rx,64,numeric,core,9.109,1000,1518,2453,994,1000,1016,1977,994,
rx,64,numeric,qiskit,0.707028,1000,1518,2440,985,1000,1016,1962,985,
rx,64,symbolic,core,9.080984,1000,1518,2453,994,1000,1024,1977,994,
rx,64,symbolic,qiskit,0.842309,1000,1518,2440,985,1000,1024,1962,985,
ry,2,numeric,core,0.258562,4,4,8,4,4,4,8,4,2.220446049250313e-16
ry,2,numeric,qiskit,0.036944,8,15,18,8,8,6,12,8,2.220446049250313e-16
ry,2,symbolic,core,0.270545,4,4,8,4,4,4,8,4,2.220446049250313e-16
ry,2,symbolic,qiskit,0.042288,8,15,18,8,8,6,12,8,3.3306690738754696e-16
ry,3,numeric,core,0.350882,14,22,26,12,14,17,21,12,1.024360521199179e-15
ry,3,numeric,qiskit,0.075584,20,35,42,20,20,14,28,20,2.220446049250313e-16
ry,3,symbolic,core,0.355074,14,22,26,12,14,20,24,12,8.892273665708786e-16
ry,3,symbolic,qiskit,0.095025,20,35,42,20,20,14,28,20,4.440892098500626e-16
ry,4,numeric,core,0.406435,24,40,44,18,24,29,35,18,1.520397016336855e-15
ry,4,numeric,qiskit,0.177777,24,40,44,18,24,29,35,18,1.520397016336855e-15
ry,4,symbolic,core,0.408035,24,40,44,18,24,36,41,18,1.686470170725321e-15
ry,4,symbolic,qiskit,0.207521,24,40,44,18,24,36,41,18,1.686470170725321e-15
ry,5,numeric,core,0.562084,40,56,69,34,40,50,64,34,5.0035533349649525e-15
ry,5,numeric,qiskit,0.197794,40,56,69,34,40,50,64,34,5.0035533349649525e-15
ry,5,symbolic,core,0.558788,40,56,69,34,40,55,68,34,4.0974976367522364e-15
ry,5,symbolic,qiskit,0.25357,40,56,69,34,40,55,68,34,4.0974976367522364e-15
ry,6,numeric,core,0.719669,56,72,85,38,56,67,76,38,
ry,6,numeric,qiskit,0.200482,56,72,85,38,56,67,76,38,
ry,6,symbolic,core,0.345506,56,72,85,38,56,74,83,38,
ry,6,symbolic,qiskit,0.095505,56,72,85,38,56,74,83,38,
ry,7,numeric,core,0.440963,80,122,174,80,80,89,153,80,
ry,7,numeric,qiskit,0.095392,80,122,174,80,80,89,153,80,
ry,7,symbolic,core,0.42237,80,122,174,80,80,96,156,80,
ry,7,symbolic,qiskit,0.108529,80,122,174,80,80,96,156,80,
ry,8,numeric,core,0.506563,104,172,212,98,104,121,186,98,
ry,8,numeric,qiskit,0.237873,104,172,199,89,104,121,171,89,
ry,8,symbolic,core,1.086358,104,172,212,98,104,128,186,98,
ry,8,symbolic,qiskit,0.274962,104,172,199,89,104,128,171,89,
ry,9,numeric,core,1.203495,120,196,247,112,120,137,214,112,
ry,9,numeric,qiskit,0.243874,120,196,247,108,120,137,210,108,
ry,9,symbolic,core,1.210119,120,196,247,112,120,144,214,112,
ry,9,symbolic,qiskit,0.301426,120,196,247,108,120,144,210,108,
ry,10,numeric,core,1.335944,136,220,292,130,136,153,250,130,
ry,10,numeric,qiskit,0.25957,136,220,279,121,136,153,235,121,
ry,10,symbolic,core,1.356264,136,220,292,130,136,160,250,130,
ry,10,symbolic,qiskit,0.319554,136,220,279,121,136,160,235,121,
ry,16,numeric,core,2.213934,232,364,532,226,232,249,442,226,
ry,16,numeric,qiskit,0.346178,232,364,519,217,232,249,427,217,
ry,16,symbolic,core,2.235966,232,364,532,226,232,256,442,226,
ry,16,symbolic,qiskit,0.369299,232,364,519,217,232,256,427,217,
ry,32,numeric,core,2.109981,488,748,1172,482,488,505,954,482,
ry,32,numeric,qiskit,0.205905,488,748,1159,473,488,505,939,473,
ry,32,symbolic,core,2.101613,488,748,1172,482,488,512,954,482,
ry,32,symbolic,qiskit,0.233938,488,748,1159,473,488,512,939,473,
ry,64,numeric,core,4.250746,1000,1516,2452,994,1000,1017,1978,994,
ry,64,numeric,qiskit,0.349938,1000,1516,2439,985,1000,1017,1963,985,
ry,64,symbolic,core,4.418747,1000,1516,2452,994,1000,1024,1978,994,
ry,64,symbolic,qiskit,0.359011,1000,1516,2439,985,1000,1024,1963,985,
rz,2,numeric,core,0.094,4,4,8,4,4,4,8,4,0.0
rz,2,numeric,qiskit,0.065872,4,4,8,4,4,4,8,4,0.0
rz,2,symbolic,core,0.107504,4,4,8,4,4,4,8,4,0.0
rz,2,symbolic,qiskit,0.074577,4,4,8,4,4,4,8,4,0.0
rz,3,numeric,core,0.146417,14,22,26,12,14,17,21,12,9.71445146547012e-16
rz,3,numeric,qiskit,0.070896,14,22,26,12,14,17,21,12,9.71445146547012e-16
rz,3,symbolic,core,0.146593,14,22,26,12,14,20,24,12,8.473409486550037e-16
rz,3,symbolic,qiskit,0.081153,14,22,26,12,14,20,24,12,8.473409486550037e-16
rz,4,numeric,core,0.183121,24,40,44,18,24,29,35,18,1.3092278833360677e-15
rz,4,numeric,qiskit,0.075681,24,40,44,18,24,29,35,18,1.3092278833360677e-15
rz,4,symbolic,core,0.438195,24,40,44,18,24,36,41,18,1.6136471996107273e-15
rz,4,symbolic,qiskit,0.213825,24,40,44,18,24,36,41,18,1.6136471996107273e-15
rz,5,numeric,core,0.553923,40,56,69,34,40,48,64,34,2.538614803067886e-15
rz,5,numeric,qiskit,0.199377,40,56,69,34,40,48,64,34,2.538614803067886e-15
rz,5,symbolic,core,0.270114,40,56,69,34,40,55,68,34,2.871672278914067e-15
rz,5,symbolic,qiskit,0.099201,40,56,69,34,40,55,68,34,2.871672278914067e-15
rz,6,numeric,core,0.355427,56,72,85,38,56,69,76,38,
rz,6,numeric,qiskit,0.095633,56,72,85,38,56,69,76,38,
rz,6,symbolic,core,0.36133,56,72,85,38,56,74,83,38,
rz,6,symbolic,qiskit,0.102721,56,72,85,38,56,74,83,38,
rz,7,numeric,core,0.447603,80,122,174,80,80,89,153,80,
rz,7,numeric,qiskit,0.101792,80,122,174,80,80,89,153,80,
rz,7,symbolic,core,0.453491,80,122,174,80,80,96,156,80,
rz,7,symbolic,qiskit,0.112609,80,122,174,80,80,96,156,80,
rz,8,numeric,core,0.528067,104,172,212,98,104,121,186,98,
rz,8,numeric,qiskit,0.108993,104,172,199,89,104,121,171,89,
rz,8,symbolic,core,0.53146,104,172,212,98,104,128,186,98,
rz,8,symbolic,qiskit,0.119873,104,172,199,89,104,128,171,89,
rz,9,numeric,core,0.60346,120,196,247,112,120,137,214,112,
rz,9,numeric,qiskit,0.275169,120,196,247,108,120,137,210,108,
rz,9,symbolic,core,1.363753,120,196,247,112,120,144,214,112,
rz,9,symbolic,qiskit,0.341538,120,196,247,108,120,144,210,108,
rz,10,numeric,core,1.525946,136,220,292,130,136,153,250,130,
rz,10,numeric,qiskit,0.288994,136,220,279,121,136,153,235,121,
rz,10,symbolic,core,1.479721,136,220,292,130,136,160,250,130,
rz,10,symbolic,qiskit,0.145633,136,220,279,121,136,160,235,121,
rz,16,numeric,core,1.075383,232,364,532,226,232,249,442,226,
rz,16,numeric,qiskit,0.145457,232,364,519,217,232,249,427,217,
rz,16,symbolic,core,1.07559,232,364,532,226,232,256,442,226,
rz,16,symbolic,qiskit,0.163921,232,364,519,217,232,256,427,217,
rz,32,numeric,core,2.147598,488,748,1172,482,488,505,954,482,
rz,32,numeric,qiskit,0.482483,488,748,1159,473,488,505,939,473,
rz,32,symbolic,core,4.725454,488,748,1172,482,488,512,954,482,
rz,32,symbolic,qiskit,0.505475,488,748,1159,473,488,512,939,473,
rz,64,numeric,core,9.260025,1000,1516,2452,994,1000,1017,1978,994,
rz,64,numeric,qiskit,0.746389,1000,1516,2439,985,1000,1017,1963,985,
rz,64,symbolic,core,9.402778,1000,1516,2452,994,1000,1024,1978,994,
rz,64,symbolic,qiskit,0.842181,1000,1516,2439,985,1000,1024,1963,985,
49 changes: 49 additions & 0 deletions .agent/audits/controlled-synthesis-test-runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Controlled synthesis test runtime

Status: implemented and validated. Baseline:
`1f25f40667079f909685992653549b12ce0e0be6` with the pending MCY support, shared
Pauli tests, and rotation CX budgets. The open PR is
[#2467](https://github.com/munich-quantum-toolkit/core/pull/2467).

## Scope and contract

Speed up `test_multi_controlled_decomposition.cpp` without removing control
widths, numeric or runtime angles, gate-count bounds, exact-phase comparisons,
borrowed-control restoration, or input/output IR and linearity verification.
Production synthesis and the Python test matrix are unchanged.

## Findings

The single-pass helper verified its output twice: once in `PassManager::run` and
again in an explicit `verify` call. Sampling the rotation resource test
attributed 658 samples to the first check and 677 to the second, compared with
712 in greedy rewriting. The helper now explicitly enables the pass manager's
verifier and retains the separate output linearity check. Input verification is
unchanged. Both output checks covered the same module after the same pass.

The large Pauli full-operator tests spend most of their time in DD matrix
multiplication. Reusing packages solely to avoid allocations is not justified by
this profile. Switching the three matrix-only helpers to the existing
unitary-simulation DD configuration showed no benefit: the three-run median for
the 25 Pauli-at-eight-controls and numeric/runtime rotation tests changed from
5.276 to 5.294 seconds. This experiment was reverted.

## Validation

The baseline Debug binary passed all 297 decomposition tests in 42.4 seconds on
macOS ARM64 with AppleClang 21 and LLVM/MLIR 23.1. The run included a short
sampling interval, so it is diagnostic rather than a controlled speed ratio.

A subsequent unprofiled three-run comparison of
`MultiControlledDecompositionTest.RotationsUseLinearResourcesWithoutExtraQubits`
used the original binary and the rebuilt single-verifier binary serially, with
no concurrent build. The median fell from 2.035 to 1.477 seconds (27%). All six
runs passed with all 96 axis, width, and angle-kind combinations retained. The
34-test MCY and rotation-resource filter also passed three times per binary. Its
median fell from 10.528 to 8.910 seconds (15%). Compilation and profiling time
are excluded from test durations.

The final rebuilt binary passes all 297 tests. The full changed-file
`uvx nox -s cpp-lint -- ec799daa09f855bd0edcbc5592a5fedd90836516` check reports
zero findings, and `uvx nox -s lint` passes. The final full-suite run overlapped
with C++ lint and is not used for a whole-suite speedup claim.
150 changes: 150 additions & 0 deletions .agent/audits/pr2467-controlled-synthesis-review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Controlled-synthesis audit and quality comparison

Status: applied. Date: 2026-09-08. Original baseline:
`00a214ec3f49aab0eeee0352a05ef817100e8c55`. Changes rebased onto main
`4c5e45855e5bb50c42b68ddbf4f9a4dababb8737`.

## Findings and disposition

- **Identity modifier evaluation:** wide X/Y/Z synthesis can leave empty
`qco.ctrl` bodies after angle folding. The original head's DD consumer
rejected these valid identity regions. Main's shared `composeBodyMatrix` fix
in #2464 resolves this on rebase. No duplicate or Y-specific workaround is
needed. The 63-control coherent-state regression now passes without
canonicalization.
- **Unreachable HP24 machinery:** `mczCoreForWidth` uses specialized synthesis
below five controls and SP22 through 32. HP24 now asserts its actual minimum
of 33 controls and directly selects one dirty helper for odd widths, two for
even widths. Removed the inactive small-width table, ripple incrementer,
recursive relative-phase planner, thread-local cache, and estimate branches.
Active half-MCX widths exceed 11 and incrementer widths exceed 10, so those
removed alternatives had no production caller. Changing the crossover must
revisit this limit. This is a maintenance improvement, not a speed claim.
- **Wide-state oracle and coverage:** retained existing SP22 samples and added
32/33/34, 47/48, and 63/64 controls for X/Y/Z. Compare the phase-sensitive
norm of `actual - expected` at `1e-11`, rather than DD node identity. The
coherent helper scopes DD arithmetic tolerance to `1e-15` and restores it
afterward; the default merging tolerance accumulated about `1e-9` error at 32
controls. These selected states are not a full-operator bound. Independent
numeric and runtime rotation matrices now cover 2 through 10 controls.
- **Duplicate remapping:** remap each generated rotation half-plan in place;
remove unused `GateEmitter` remapping. This removes a second plan allocation
and move loop. Plans remain the sole owner of wire remapping.
- **Stale CLI descriptions:** both compiler options now name Y and rotations;
the generated pass description names the active HP24 dirty-helper choice.

Source:
`mlir/lib/Dialect/QCO/Transforms/Decomposition/DecomposeMultiControlled.cpp`.
Regression tests: the corresponding
`mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_multi_controlled_decomposition.cpp`.

## Contracts retained

The modifier verifier owns restrictions on classical support operations. No
second dependency walker is needed. Balanced halves borrow opposite controls and
restore them coherently. Arbitrary relative-phase MCX replacements have not been
proved safe in the four-MCX rotation shell. RX uses Hadamard conjugation of RZ;
Y uses target S conjugation of X. Controlled `2*pi` rotations retain their
conditional minus sign. Native-target and minimum-width policies still apply. No
new cache, public API, or dependency is justified.

## Reproducible Qiskit comparison

Run `uv run --no-sync python test/bench/compare_controlled_rotations.py` with
the locally built package and Qiskit 2.5.2. The script records numeric and
symbolic RX/RY/RZ at 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 32, and 64 controls. Raw
rows from this run are in
[controlled-rotation-quality.csv](controlled-rotation-quality.csv). Core was
built with Clang/LLVM 23.1, Release, ThinLTO, and mold on ARM64.

Both methods use exactly the input qubits. Nine-sample median synthesis times
exclude one warmup, input creation, import/export, basis conversion, and
routing. Both circuits receive the same `u,cx` normalization, then level-3
optimization with seed zero and `qubits_initially_zero=False`. The CSV includes
CX count, one-qubit count, total depth, CX depth, and synthesis time. Numeric
and symbolic operators through five controls pass phase-sensitive checks,
including symbolic binding at `2*pi`. Timings are local sequential measurements,
not an end-to-end compilation comparison or stable performance guarantee.

Numeric post-optimization examples (Core / Qiskit):

| Gate | Controls | CX | Depth | Synthesis ms |
| ---- | -------: | ----------: | ----------: | ------------: |
| RX | 2 | 4 / 8 | 9 / 13 | 0.272 / 0.034 |
| RY | 3 | 14 / 20 | 21 / 28 | 0.351 / 0.076 |
| RY | 8 | 104 / 104 | 186 / 171 | 0.507 / 0.238 |
| RY | 16 | 232 / 232 | 442 / 427 | 2.214 / 0.346 |
| RY | 64 | 1000 / 1000 | 1978 / 1963 | 4.251 / 0.350 |

Core saves CX gates for RX/RY at two and three controls. Other sampled CX counts
match, including all RZ cases and symbolic angles. Core's larger circuits are up
to 15 layers deeper. Core synthesis is slower in this measurement. Earlier
claims of uniformly faster Core synthesis included basis lowering in Qiskit's
timed work and are superseded by this comparison.

## Improvement beyond Qiskit: measured candidate, deferred implementation

Helper order affects scheduling even when CX count stays fixed. In an isolated
prototype, reverse the selected dirty-helper wires in both balanced half-MCXs,
keeping controls in order. Use Qiskit's exact `synth_mcx_n_dirty_i15` to
construct those halves, and the same four quarter-angle rotations and
normalization as above. This produces these numeric RY depths:

| Controls | Core | Qiskit | Reversed-helper prototype | CX (all three) |
| -------- | ---: | -----: | ------------------------: | -------------: |
| 9 | 214 | 210 | 204 | 120 |
| 10 | 250 | 235 | 232 | 136 |
| 16 | 442 | 427 | 388 | 232 |
| 32 | 954 | 939 | 804 | 488 |
| 64 | 1978 | 1963 | 1636 | 1000 |

At eight controls, balanced reversed helpers give depth 180, worse than Qiskit's
171. A 5+3 split instead reduces CX from 104 to 96 but has depth 185. Neither
candidate dominates at every width. The reversed balanced prototype at nine
controls and both eight-control splits pass full phase-sensitive operator
comparisons with maximum element error below `1.2e-14`.

Minimal reproduction, after importing `QuantumCircuit`, `transpile`, and
`qiskit.synthesis.synth_mcx_n_dirty_i15`:

```python
k = 64
first = (k + 1) // 2
halves = []
for start, count in ((0, first), (first, k - first)):
plan = synth_mcx_n_dirty_i15(count)
spare = [i for i in range(k) if i < start or i >= start + count]
spare = spare[: plan.num_qubits - count - 1]
halves.append((plan, list(range(start, start + count)) + [k] + spare[::-1]))
circuit = QuantumCircuit(k + 1)
for _ in range(2):
circuit.compose(*halves[0], inplace=True)
circuit.ry(-0.73 / 4, k)
circuit.compose(*halves[1], inplace=True)
circuit.ry(0.73 / 4, k)
output = transpile(
circuit,
basis_gates=["u", "cx"],
optimization_level=3,
seed_transpiler=0,
qubits_initially_zero=False,
)
assert output.count_ops()["cx"] == 1000
assert output.depth() == 1636
```

This establishes room beyond Qiskit's current public synthesis output, not
optimality or a ready Core patch. Before implementation, measure Core's own
helper ordering across all axes, symbolic expressions, and routing targets;
retain the exact-restoration tests. A width-specific split policy needs an
explicit objective because CX count and depth disagree at eight controls. The
existing construction has linear CX count; results requiring additional
clean/dirty qubits do not establish an improvement under this no-extra-qubit
contract.

## Validation

The native decomposition binary passes all 303 tests, including both active HP24
dirty-helper modes and numeric/runtime full operators through ten controls. The
benchmark completes all 144 backend rows. Final lint and Python validation are
recorded in the implementation plan.
Loading
Loading