Add modular increment and decrement arithmetic primitives

Aperta
#108 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 8 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Start with python/cudaq_algorithms/primitives/_arithmetic.py and the existing exports from cudaq_algorithms.primitives; read the current constant arithmetic kernels and their tests to follow the project’s conventions. Implement and test increment and decrement against the stated wraparound, slice, inverse, and control contracts. Done includes API exports, documentation, exhaustive small-register and statevector tests, gate and resource counts, and comparisons with the CDKM and QFT adders at K=1.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Cyclic shifts, counters, and structured block encodings often need only j -> j +/- 1 mod 2**n. Add specialized public increment and decrement device kernels alongside the existing generic arithmetic.

The current arithmetic module offers:

  • CDKM add_constant / subtract_constant, which take an n-qubit work register and a carry qubit.
  • QFT constant addition/subtraction, which need no work register but use Fourier transforms and phase operations.

A dedicated binary increment/decrement would provide a simple interface and another resource tradeoff for this common special case.

Proposed API and contract
from cudaq_algorithms.primitives import increment, decrement

# Inside a CUDA-Q kernel; target[0] is the least-significant bit.
increment(target)       # target <- target + 1 mod 2**target.size()
decrement(target)       # exact inverse

# Incrementing the upper subregister adds a power-of-two offset.
increment(target[2:])   # full register <- full register + 4 mod 2**n
  • In-place, little-endian, modular arithmetic: overflow/underflow wraps; no carry output.
  • No scratch register, constant-bit array, or internal qubit allocation.
  • Empty views are no-ops; a one-qubit increment or decrement is X.
  • Preserve coherent amplitudes and relative phases.
  • Support external controls through cudaq.control, with disjoint control and target registers.
Candidate implementation

For increment, sweep target bits from most significant down to bit 1, flipping bit k controlled on every lower bit being 1; finish with X on bit 0. Decrement is the explicitly reversed gate sequence, consistent with the arithmetic module's hand-written inverse style.

At the expressed-circuit level, this is one X and n-1 controlled-X operations with control counts 1, ..., n-1. This is not a claim of linear elementary-gate or Toffoli cost. Larger controlled operations must be accounted for under the chosen decomposition/backend.

Acceptance criteria
  • Export the kernels from cudaq_algorithms.primitives and document their register, wraparound, and control contracts.
  • Exhaustively test small-register basis permutations, both wrap boundaries, width one, empty views, and inverse round trips.
  • Compare complete statevectors on complex superpositions and test superposed external controls, including identity on the inactive control branch.
  • Test register slices, including power-of-two shifts that leave the lower bits unchanged.
  • Pin logical gate/control counts and allocated-qubit counts. Report decomposed counts/depth and any decomposition workspace where available; distinguish Toffolis from higher-controlled X operations.
  • Compare the specialization with the existing CDKM and QFT constant adders at K=1, including GPU statevector execution where available. Document the measured tradeoffs rather than assuming the specialized implementation is always faster.

The initial change can add these entry points without changing existing adder behavior.

Related: #79 (general adder optimization) and #107 (periodic banded sparse-access oracles).

Lingua principale
Python
Stelle
19
Fork
18
Merge medio
5g 18h
PR unite (30g)
14

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/cudaq-algorithms

Tutte le issue di NVIDIA/cudaq-algorithms

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.