Skip to content

[python] cudaq.pauli_word is opaque (str() returns the repr), inconsistent with SpinOperatorTerm.get_pauli_word returning str #4850

Description

@wsttiger

Required prerequisites

  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions