Skip to content

examples: add QROM-programmed spatial frames to DF encoding - #91

Draft
wsttiger wants to merge 2 commits into
mainfrom
codex/v02-10-df-qrom-programmable-givens
Draft

wsttiger wants to merge 2 commits into
mainfrom
codex/v02-10-df-qrom-programmable-givens

Conversation

@wsttiger

@wsttiger wsttiger commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

The double-factorized example currently sweeps through classical orbital frames. Add an optional QROM backend that coherently loads one real spatial frame from the term index, applies programmable inverse/forward Givens networks around the signed Z word, and uncomputes angle/ladder workspace. The fixed backend remains the class default; the molecular driver defaults to comparing both.

Preserves the exact flat coefficient PREPARE, retained terms, scalar offsets, compressed dense-core support, and all BlockEncoding consumers. Documents index-bit reversal, two-spin rotation conventions, complete-ancilla reflections, resource widths, and independent ideal/represented error budgets. This implements the requested angle-loading mechanism; it does not reproduce the papers' nested DF algorithms or optimized fault-tolerant costs.

This PR targets main independently of plan 09 / PR #90 and PR #78. No library or dependency changes.

Validation on Python 3.12.3 / CUDA-Q 0.16.0.post1, fp64 qpp-cpu:

  • test_df_encoding.py: 37 passed (89.56 s), including all 26 existing fixed tests. Complete 16x16 good block, every term/padding address, coherent SELECT/control, clean workspace, state-prep injection, Walk/QSVT, and identity/diagonal/single-orbital/dense-core cases.
  • test_examples.py -k 'df_block_encoding or 04_double_factorization_and_the_protocol or 06_bring_your_own_encoding': 3 passed (52.33 s).
  • Standalone H2, both backends, four bits: 46.66 s. Fixed: 9 qubits; QROM: 18 qubits (4 system + 5 index + 4 angle + 5 ladder). H2 maximum action/Walk/QSVT error 4.11e-15 against independent NumPy references, tolerance 1e-10.
  • Off-grid synthetic DF: angle operator error 0.0491630, separately bounded by 0.2328365; circuit action error 1.57e-15. Three-slot, three-spatial-mode programmable check: full-state error 1.94e-15 on 15 qubits.
  • Final host-guard compatibility checks: 4 passed. Sphinx -W and YAPF 0.43.0: pass.

The driver retains fixed-backend moments, adds a host-only b=4/6/8 precision sweep, and labels larger QROM cases as resource-only. H2 happens to be on-grid; the synthetic regression deliberately exercises nonzero rounding error. Full wheel/GPU CI is separate from these focused checks.

Signed-off-by: Scott Thornton <wsttiger@gmail.com>
…ELECT

The QROM SELECT undid the programmable spatial network with
cudaq.adjoint, which the CUDA-Q runtime refuses for a kernel that calls
cudaq.control inside a loop ("could not autogenerate the adjoint of a
kernel"), so the H2 driver and every QROM-backend kernel failed to
execute on CUDA-Q 0.15.1. programmable_spatial_givens_adjoint is the
hand-written inverse (slots in reverse order, negated weights), the
same convention as the arithmetic primitives, and the angle words are
erased by a second lookup, which the QROM contract documents as exactly
self-inverse. User-facing text states what the backends are rather
than how they relate to earlier versions.

The 11 QROM tests pass on CUDA-Q 0.15.1 and 0.16.0; the H2 driver runs
both backends with all checks passing.

Signed-off-by: Scott Thornton <wsttiger@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant