Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when commuting moments #6659

Open
cdbf1 opened this issue Jul 8, 2024 · 1 comment
Open

Issue when commuting moments #6659

cdbf1 opened this issue Jul 8, 2024 · 1 comment
Labels
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. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@cdbf1
Copy link

cdbf1 commented Jul 8, 2024

Description of the issue
Cirq gives the wrong result when determining whether moments commute if the individual operators within the moments do not commute, but the moment as a whole still commutes. For example, take a pair of single qubit Z gates and a two qubit RXX gate. While [Z, RXX] !=0 (for either single qubit Z), we do in fact have [Z * Z, RXX] = 0. However, when using cirq we have

import cirq
qubits = cirq.LineQubits.range(2)
moment_1 = cirq.Moment([cirq.Z(qubits[0], cirq.Z(qubits[1])])
moment_2 = cirq.XXPowGate(exponent=1 / 2)(*qubits)

print(cirq.commutes(moment_1, moment_2))

Gives False.

Looking through the source code this seems to be because the the commutes() function compares pairs of operators form each moment but doesn't consider the case when the moment as a whole commutes even when the individual operators do not.

How to reproduce the issue
See above

Cirq version
You can get the cirq version by printing cirq.__version__. From the command line:
1.5.0

@cdbf1 cdbf1 added the kind/bug-report Something doesn't seem to work. label Jul 8, 2024
@NoureldinYosri NoureldinYosri added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Jul 8, 2024
@dstrain115 dstrain115 added triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Jul 17, 2024
@dstrain115
Copy link
Collaborator

dstrain115 commented Jul 17, 2024

cirq cync: This functionality works for pauli strings, but not for moments.

A naive solution would be to decompose the moments (if commutes is initially determined to be false via gate by gate comparison).

From the documentation:
Either value has a commutes method that returns 'True', 'False', or 'None' (meaning indeterminate).

So, this should either return None (not sure) or should perform an alternative strategy like decomposing the moment into a unitary.

@dstrain115 dstrain115 added the good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants