`NativeQuilMetadata` exposes no attribute getters in Python

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python, rust
Ambito
api

Direzione di ricerca

Inizia in crates/lib/src/compiler/quilc.rs, alla dichiarazione della pyclass NativeQuilMetadata, e confrontala con le classi affini che usano get_all. Verifica che il qcs_sdk/compiler/quilc.pyi generato esponga getter per tutti e otto i campi e che il codice Python possa leggere final_rewiring e gli altri valori dei metadati.

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

Descrizione

CompilationResult.native_quil_metadata is readable, but nothing on the object it returns is:

>>> from qcs_sdk.compiler.quilc import NativeQuilMetadata
>>> m = NativeQuilMetadata([9, 0, 1, 2], 3, 4, 1, 0.5, 0.99, 2, 1.5)
>>> [a for a in dir(m) if not a.startswith("_")]
[]
>>> m.final_rewiring
AttributeError: 'qcs_sdk.compiler.quilc.NativeQuilMetadata' object has no attribute 'final_rewiring'

Verified on qcs-sdk-python 0.26.3 (latest) and 0.26.1, and still the case on main: quilc.pyi declares only __eq__, __getnewargs__, __new__ and __repr__ for the class.

It looks like an omission

In crates/lib/src/compiler/quilc.rs#L302, NativeQuilMetadata is the only pyclass in the module that has pub fields and does not pass get_all:

pyclass get_all field visibility
CompilationResult, PauliTerm, and 5 others yes pub
CompilerOpts no pub(crate)
TargetDevice no private
NativeQuilMetadata no pub

So the two classes that legitimately hide their fields do so by keeping them non-public, while this one declares all eight fields pub and then exposes none of them.

Why it's worth fixing

final_rewiring is the only record of how quilc relabelled logical qubits onto physical ones. Anything expressed in physical qubits has to be interpreted against it — Quil-T especially, since DELAY 0 0.0005 and frame references address physical qubits, and reasoning about a compiled program without the mapping silently targets the wrong qubit rather than failing.

The only route today is __getnewargs__()[0]. It does return a typed list[int], so this isn't blocking, but it's the pickle protocol rather than an accessor: positional, undocumented, free to change, and it yields None instead of [] for an empty rewiring. __repr__ is the alternative, which means parsing Rust Debug output.

Suggested fix
 #[cfg_attr(
     feature = "python",
-    pyo3::pyclass(module = "qcs_sdk.compiler.quilc", eq)
+    pyo3::pyclass(module = "qcs_sdk.compiler.quilc", eq, get_all)
 )]
 pub struct NativeQuilMetadata {

Sibling classes also pass frozen; I've left it out here since it's a semantic change beyond adding getters, but it would match the module if you want it.

Happy to open a PR.

Lingua principale
Rust
Stelle
15
Fork
4
Merge medio
10h 36m
PR unite (30g)
2

Preparare l'ambiente

Apri in Codespaces

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

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

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 rigetti/qcs-sdk-rust

Tutte le issue di rigetti/qcs-sdk-rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.