Qiskit / qiskit-serverless

A programming model for leveraging quantum and classical resources
https://qiskit.github.io/qiskit-serverless/
Apache License 2.0
68 stars 30 forks source link

Support encoding Pauli as dictionary key #1472

Open jyu00 opened 3 months ago

jyu00 commented 3 months ago

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 commented 3 months ago

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.