Classical simulation fails for a QROAM with block size 1 on one axis: 0-bit `BQUInt` breaks `Partition`

Aperta
#2,008 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, testing

Direzione di ricerca

Start in qualtran/dtype/_uint.py and trace how _UInt.from_bits and _UInt.to_bits handle zero-width registers; the report gives reproducible failures through Partition and BQUInt(0, 1). Check both BQUInt(0, 1) and QUInt(0), then run the reported Partition examples and the QROAMClean decomposition example. Done when zero-bit registers round-trip as 0 without raising or adding an address bit.

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

Descrizione

A 2D QROAM read with block size 1 on one axis (log_block_sizes=(0, k)) partitions that axis's address into a high part and a 0-bit low part BQUInt(0, 1). Classical simulation of the decomposition then fails on that 0-bit part in both directions. The partition raises, because BQUInt(0, 1).from_bits([]) computes int('', 2). The unpartition silently returns a wrong address, because BQUInt(0, 1).to_bits_array gives one bit instead of zero, so the joined address gains a bit and doubles:

from qualtran import BQUInt, Register
from qualtran.bloqs.bookkeeping import Partition

p = Partition(3, regs=(Register('l', BQUInt(3, 8)), Register('k', BQUInt(0, 1))))
p.call_classically(x=1)                 # ValueError: invalid literal for int() with base 2: ''
p.adjoint().call_classically(l=1, k=0)  # (2,), expected (1,)

Expected: a 0-bit register has no bits and holds 0. The cause is _UInt in qualtran/dtype/_uint.py: from_bits raises on [] (also for QUInt(0)), and to_bits(0) returns [0], since f'{0:00b}' is '0'.

Qualtran's own QROAMClean and SelectSwapQROM fail before this, when decomposing, because SwapWithZero drops the 0-bit selection:

import numpy as np
from qualtran.bloqs.data_loading.qroam_clean import QROAMClean

QROAMClean.build_from_data(np.arange(12).reshape(3, 4), log_block_sizes=(0, 1)).decompose_bloq()
# BloqError: a call to SwapWithZero register dtypes are not consistent Partition<2>.k: BQUInt(0, 1) vs selection: BQUInt(1, 2).
Lingua principale
Python
Stelle
397
Fork
127
Merge medio
2g 19h
PR unite (30g)
4

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 quantumlib/Qualtran

Tutte le issue di quantumlib/Qualtran

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.