atlytle / dense-ev

Expectation value measurements in Qiskit using optimal dense grouping. Dense-ev provides an improvement of ~2^m over naive grouping and (3/2)^m over qubit-wise commuting groups. https://arxiv.org/abs/2305.11847
Apache License 2.0
9 stars 1 forks source link

Error corrected that causes the expectation value to be calculated incorrectly #1

Closed LeDernier closed 1 year ago

LeDernier commented 1 year ago

The coefficient associated to the identity in 2^n dimensions, I^n, was zero if there were other Pauli strings with zero coefficient (because all the Pauli strings with zero coefficient are mapped to the identity, so when creating "id_dict", the id associated to I^n would be the last Pauli string transformed into the identity and not 0). I just proposed a quick solution. It can be improved later.

atlytle commented 1 year ago

Thank you. The issue arises when there are repeated strings in H.primitive. I wonder if a judicious call to H.reduce() could solve this for all cases. I've merged your code and expanded test coverage for this case.

LeDernier commented 1 year ago

Yes. "operator".reduce() should also solve the problem. It could be added in the method "convert" of the class "DensePauliExpectation". However, I don't know if that will have a negative effect in the rest of the code (I doubt it).