Required prerequisites
Describe the feature
A cudaq.pauli_word constructed in Python is opaque: it has no public
attributes or methods (dir() shows none) and str(word) returns the
object repr, so host code cannot inspect, compare, or serialize the word
it wraps. Meanwhile SpinOperatorTerm.get_pauli_word(n) returns a plain
Python str, and plain strings are accepted as list[cudaq.pauli_word]
kernel arguments — so the type only becomes load-bearing (and opaque)
exactly where users must construct it manually (captured values).
import cudaq
w = cudaq.pauli_word("XIZ")
print([m for m in dir(w) if not m.startswith("_")]) # []
print(str(w))
# <cudaq.mlir._mlir_libs._quakeDialects.cudaq_runtime.pauli_word object at 0x...>
Suggestion: give cudaq.pauli_word a __str__ (and ideally
__eq__/__repr__) returning the word string.
Environment
- CUDA-Q built from source at commit
0be565550f4c23affdcbed9e4eaec38d2d0915e6
- Python 3.11.x, target
qpp-cpu (library mode)
- AlmaLinux 8.10, x86_64
All reproducers below were executed and verified against this build.
Required prerequisites
Describe the feature
A
cudaq.pauli_wordconstructed in Python is opaque: it has no publicattributes or methods (
dir()shows none) andstr(word)returns theobject repr, so host code cannot inspect, compare, or serialize the word
it wraps. Meanwhile
SpinOperatorTerm.get_pauli_word(n)returns a plainPython
str, and plain strings are accepted aslist[cudaq.pauli_word]kernel arguments — so the type only becomes load-bearing (and opaque)
exactly where users must construct it manually (captured values).
Suggestion: give
cudaq.pauli_worda__str__(and ideally__eq__/__repr__) returning the word string.Environment
0be565550f4c23affdcbed9e4eaec38d2d0915e6qpp-cpu(library mode)All reproducers below were executed and verified against this build.