Currently, if a user passes in a measurement basis containing an identity (I) -- which is admittedly a weird thing to do -- that basis may pass a compatibility check with a given observable term, but not really be valid for evaluating that observable term. For example, the basis IZ cannot be used to evaluate the observable term ZZ, but is qubit-wise commuting.
I think the check happens here (?):
|
commutes = ( |
|
np.dot(observable_element.z, basis.x) + np.dot(observable_element.x, basis.z) |
|
) % 2 == 0 |
I'm thinking we should modify how we check compatibility to something like this, instead of checking qubit-wise commutativity:
mask = term.z|term.x
compatible = np.all(term[mask] == basis[mask])
It would also be a little more accurate to change language in code/docstrings/errors about "commuting" to "compatible." (Observable XX is commuting with basis ZZ but is not compatible. Observable ZZ is qubit-wise commuting with basis IZ but is not compatible.)
(Alternatively, we could just raise an error when validating measurement bases if they are not all full-weight. But maybe there's some abstract case where it's convenient to work with measurement bases that have identity characters, indicating basically a dummy bit.)
Currently, if a user passes in a measurement basis containing an identity (
I) -- which is admittedly a weird thing to do -- that basis may pass a compatibility check with a given observable term, but not really be valid for evaluating that observable term. For example, the basisIZcannot be used to evaluate the observable termZZ, but is qubit-wise commuting.I think the check happens here (?):
qiskit-addon-utils/qiskit_addon_utils/exp_vals/expectation_values.py
Lines 357 to 359 in 6247521
I'm thinking we should modify how we check compatibility to something like this, instead of checking qubit-wise commutativity:
It would also be a little more accurate to change language in code/docstrings/errors about "commuting" to "compatible." (Observable
XXis commuting with basisZZbut is not compatible. ObservableZZis qubit-wise commuting with basisIZbut is not compatible.)(Alternatively, we could just raise an error when validating measurement bases if they are not all full-weight. But maybe there's some abstract case where it's convenient to work with measurement bases that have identity characters, indicating basically a dummy bit.)