Skip to content

exp-val: fix handling of identity in meas basis #192

Description

@aeddins-ibm

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions