evolved_operator_terms quantizes every coefficient to 1e-12, destroying precision at the API's own default atol

Aperta Adatta ai principianti
#189 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Leggi cpp/monoprop/detail/monomial_propagator/MonomialPropagatorImpl.h intorno alle righe 1069–1073 e segui la decodifica dei coefficienti nei file citati sull’algebra di Majorana e di Pauli. Poi esegui i test elencati e aggiungi un caso di regressione per un coefficiente di circa 1e-10 con atol=1e-12; il lavoro è completato quando il coefficiente restituito mantiene la precisione double completa e i test esistenti passano.

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

Descrizione

bug

🤖 AI text below 🤖

What

MonomialPropagator<NumModes>::evolved_operator_terms quantizes every decoded coefficient to 12
decimal places before returning it.

cpp/monoprop/detail/monomial_propagator/MonomialPropagatorImpl.h:1069-1073

// Round to drop anti-hermitian numerical noise (Majorana un-applies the Hermitian phase).
const auto decoded = algebra_decode_coeff<NumModes>(basis_, coeff, mono);
const std::complex<double> rounded(std::round(decoded.real() * 1e12) / 1e12,
                                   std::round(decoded.imag() * 1e12) / 1e12);
terms.emplace_back(bitset_to_indices<NumModes>(mono), rounded);

Why this is a problem

The "anti-hermitian numerical noise" the comment describes cannot arise:

  • Majorana: decode_coeff multiplies by hermitian_coefficient<NumModes>(maj)
    (cpp/monoprop/algebra/MajoranaAlgebra.h), which returns an element of POWERS_OF_I — components
    are exactly 0.0 and ±1.0.
  • Pauli: decode_pauli_coeff returns {coeff, 0.0} outright.

coeff is a real double, so in both cases the complex multiply is exact in IEEE-754 and the
component that should be zero already is an exact zero. There is nothing to scrub.

What the rounding does do is quantize to 1e-12 absolute. evolved_operator is exposed to Python
with a default atol=1e-12
(MajoranaPropagator.evolved_operator / PauliPropagator.evolved_operator), so it deliberately
admits terms whose magnitude the rounding then reduces to one or two significant digits:

true coefficient returned
1.23456789012345e-3 1.23456789e-3 (9 s.f.)
4.7213456789e-10 4.72e-10 (3 s.f.)
8.31e-12 8e-12 (1 s.f.)

So the API's own default tolerance selects exactly the range where the rounding is most destructive.

Suggested fix

Return decoded unchanged and drop the rounded temporary.

If a noise scrub is still wanted for defensiveness, snap only the component that is required to be
zero, relative to the magnitude of the other one — do not quantize both components absolutely.

Verification

  • Existing coverage: tests/test_nonfermi.py, tests/test_majorana.py, tests/test_pauli.py,
    tests/test_monoprop_smoke.py (line 149 calls evolved_operator(parameters, 1e-12)). These compare
    with isclose(atol=1e-12), so removing the rounding should leave them green.
  • Add a regression test: build a case with an evolved coefficient around 1e-10 and assert
    evolved_operator(..., atol=1e-12) returns it to full double precision. This fails today.

Found by a code-reading review of the repository at 29a8050. No build tree was available, so the
analysis is from source inspection and should be confirmed against a build.

Lingua principale
C++
Stelle
52
Fork
2
Merge medio
2g 2h
PR unite (30g)
39

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 Algorithmiq/monoprop

Tutte le issue di Algorithmiq/monoprop

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.