Add periodic boundary support to banded sparse-access oracles

Open
#107 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 8 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start with python/cudaq_algorithms/sparse/_banded.py and the existing banded oracle tests; trace how locations, values, inverses, and normalization are defined. Implement and test the periodic mode against independently assembled quantized circulant matrices, including alias and small-dimension cases. Done means the stated oracle, unitarity, QSVT solve, documentation, and runnable example criteria pass.

Written by the indexing model from the issue text.

Description

banded_oracles currently clips entries that cross the matrix boundary, although its location oracle already computes shifts modulo the register dimension. Add an opt-in periodic mode so constant-coefficient circulant stencils can use SparseOracleEncoding and QSVT through arithmetic oracles, without a per-entry QROM table.

A motivating example is the periodic diffusion-reaction operator
A = (2 + mass) I - S - S.T, where S is a cyclic shift, N = 2**n, and mass > 0 makes the system invertible.

Proposed API
from cudaq_algorithms.sparse import SparseOracleEncoding, banded_oracles

n = 3
mass = 4.0 / 9.0

oracles = banded_oracles(
    offsets=[-1, 0, 1],
    band_values=[-1.0, 2.0 + mass, -1.0],
    num_system=n,
    value_bits=8,
    boundary="periodic",
)
encoding = SparseOracleEncoding(oracles, num_system=n)

Preserve the current clipped behavior as the default, for example boundary="open". This names the existing band truncation; it does not introduce a general PDE boundary-condition solver.

Implementation considerations

The natural extension point is sparse/_banded.py. The generic SparseOracleEncoding assembler should not need a periodic-specific algorithm.

  • Locations: retain the existing modular shift and its explicit inverse.
  • Values: periodic bands retain their coefficients across wrap-around instead of being masked to zero.
  • Signed entries: compute the upper bit from the actual wrapped row/column ordering. The current offset-sign rule is valid for clipped bands, but reverses at a periodic boundary. Simply removing the value mask would give incorrect signs for negative wrap-around entries.
  • Equivalent offsets: define whether offsets congruent modulo N are combined or rejected with a clear error. Cover the self-inverse half-period shift and the N=2 case, where +1 and -1 address the same neighbor. Preserve a valid reverse-slot involution.
  • Contracts: retain clean scratch, zero-valued padded slots, explicit oracle inverses, the existing value-quantization model, and honest normalization/register accounting.

Initially scope this to one-dimensional periodic/circulant matrices. Coordinate-wise periodic boundaries on multidimensional meshes need a separate design; wrapping a flattened index is not equivalent.

Acceptance criteria
  • Existing clipped-mode tests and behavior remain unchanged.
  • Test periodic location/value oracles and their inverses, including coherent inputs, clean scratch, unused slots, and signed wrap-around entries.
  • Compare the good block against an independently assembled quantized circulant matrix divided by the reported normalization; check unitarity and Hermiticity on the supported clean-scratch domain.
  • Test the documented policy for offset aliases, half-period shifts, and very small dimensions.
  • Add a small QSVT solve of the shifted periodic Laplacian, checked against an independent FFT/classical solution, with matrix-quantization and inverse-polynomial errors accounted for separately.
  • Document the option and provide a runnable sparse-access example. Report its register and normalization costs explicitly; it need not match the qubit count of a specialized compact LCU encoding.
Dominant language
Python
Stars
19
Forks
18
Avg merge
5d 18h
Merged PRs (30d)
14

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/cudaq-algorithms

All issues in NVIDIA/cudaq-algorithms

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.