Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support encoding Pauli as dictionary key #1472

Open
jyu00 opened this issue Aug 26, 2024 · 1 comment
Open

Support encoding Pauli as dictionary key #1472

jyu00 opened this issue Aug 26, 2024 · 1 comment

Comments

@jyu00
Copy link

jyu00 commented Aug 26, 2024

What is the expected enhancement?

If I want to build my own Estimator-like function, for example, which accepts a mapping with Pauli as the key, as described in the spec, this does not currently work. The job would fail with

TypeError: keys must be str, int, float, bool or None, not Pauli

since the default JSON encoder doesn't accept Pauli as a dictionary key type.

@akihikokuroda
Copy link
Collaborator

I'm not familiar with how the estimator works. How is the dictionary used as the observable?

ObservableLike = Union[
    str,
    Pauli,
    SparsePauliOp,
    Mapping[Union[str, Pauli], float],
]

The dictionary key must be immutable objects in Python. Can it be the hash value or a label of Pauli?

Thanks and sorry for novice questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@akihikokuroda @jyu00 and others