-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Some operations involving the identity gate cause an error #7120
Copy link
Copy link
Closed
Labels
area/linear-operatorsarea/pauliscomplexity/lowintroduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributorintroduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributorgood first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.This issue can be resolved by someone who is not familiar with the codebase. A good starting issue.kind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.no QC knowledge neededWant to contribute to Cirq, but don't know quantum computing? This issue is for you.Want to contribute to Cirq, but don't know quantum computing? This issue is for you.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked onA consensus emerged that this bug report, feature request, or other action should be worked on
Metadata
Metadata
Assignees
Labels
area/linear-operatorsarea/pauliscomplexity/lowintroduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributorintroduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributorgood first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.This issue can be resolved by someone who is not familiar with the codebase. A good starting issue.kind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.no QC knowledge neededWant to contribute to Cirq, but don't know quantum computing? This issue is for you.Want to contribute to Cirq, but don't know quantum computing? This issue is for you.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked onA 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) ** 2is 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.