Some operations involving the identity gate cause an error #7120
Labels
area/linear-operators
area/paulis
complexity/low
introduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributor
good first issue
This issue can be resolved by someone who is not familiar with the codebase. A good starting issue.
kind/bug-report
Something doesn't seem to work.
no QC knowledge needed
Want to contribute to Cirq, but don't know quantum computing? This issue is for you.
triage/accepted
A consensus emerged that this bug report, feature request, or other action should be worked on
Describe the issue
If one tries to add or subtract the identity gate to another gate (or vice-versa) on a qubit
q
, for example,I(q) - Z(q)
, then the following error occurs:One could perhaps add the Pauli beforehand and then apply them on qubits (this doesn't cause the error), but it isn't clear to me how one turns a LinearCombinationsOfGates to a PauliSum. Alternatively, replacing the
-
with+(-1.0)*
solves the issue in some cases. Otherwise, one may replace the offendingI(q)
byX(q)*X(q)
orPauliString()
. Is this very last option the preferred way of denoting the identity?The following assertions are satisfied (and the individual expressions do not throw an error)
They are all "paraphrases" of the original
I(q) - Z(q)
. As an aside,also fails, because
X(q) ** 2
is converted to an incompatible class.Explain how to reproduce the bug or problem
The code below goes through all possible combinations of gates and operations, and prints those not implemented. In fact, moving the
op(p1,p2)
out of the try block will reproduce the error above.This snippet outputs
This happens on cirq 1.4.1. I updated right before running the code.
I assume the error can be fixed by adding the missing
__add__
and__sub__
in some class, but I am confused by the class structure and have not managed to locate the correct one.The text was updated successfully, but these errors were encountered: