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

Proposed fix for #3529 (Functionality decoupling for _strat_commutes_… #3548

Merged
merged 28 commits into from Jan 26, 2021

Conversation

akushnarov
Copy link
Contributor

  1. Moved "commute" check from protocols/commutes_protocol.py to ops/raw_types.py:Operator
  2. Adjusted the "ops/gate_operation.py" (extended _commute_ functionality to check if the parent class commutes)

@akushnarov akushnarov requested review from cduck, vtomole and a team as code owners November 30, 2020 13:52
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 30, 2020
cirq/protocols/commutes_protocol_test.py Outdated Show resolved Hide resolved
cirq/protocols/commutes_protocol.py Outdated Show resolved Hide resolved
cirq/ops/pauli_string.py Outdated Show resolved Hide resolved
cirq/ops/raw_types.py Outdated Show resolved Hide resolved
@@ -698,7 +698,10 @@ def zip_paulis(
) -> Iterator[Tuple[pauli_gates.Pauli, pauli_gates.Pauli]]:
return (paulis for qubit, paulis in self.zip_items(other))

def _commutes_(self, other: Any, atol: float) -> Union[bool, NotImplementedType, None]:
def _commutes_(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unrelated - can you revert this formatting change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see an error when I'm doing this

Run check/mypy
cirq/ops/pauli_string.py:701: error: Signature of "_commutes_" incompatible with supertype "Operation"
Found 1 error in 1 file (checked 745 source files)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I adjusted the

  1. arguments as in Operation super
  2. function definition length, since it was too long (I had an error from the git checks)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what the problem is. You moved the * argument with the _strat_commutes_from_operationmethod. I think we don't need that for _commutes_. Can you remove it from all the touched _commutes_ methods?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact there seems to be some inconsistency around this in the codebase:

image

Alright, let's keep the * in front of atol, I'll open an issue to cleanup this inconsistency.

cirq/ops/gate_operation.py Outdated Show resolved Hide resolved
@akushnarov
Copy link
Contributor Author

@balopat please see my answers above, also I adjusted the code

@akushnarov
Copy link
Contributor Author

Hi @balopat, I'm back to Cirq. Could you please check the changes?

@@ -167,8 +167,14 @@ def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
return getter()
return NotImplemented

def _commutes_(self, other: Any, atol: float) -> Union[bool, NotImplementedType, None]:
return self.gate._commutes_on_qids_(self.qubits, other, atol=atol)
def _commutes_(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent within the PR at least and add the * parameter before atol.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll merge this, and then we can fix the inconsistency in #3695

@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jan 26, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jan 26, 2021
@CirqBot
Copy link
Collaborator

CirqBot commented Jan 26, 2021

Automerge cancelled: A required status check is not present.

Missing statuses: ['cla/google']

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jan 26, 2021
@balopat balopat added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jan 26, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jan 26, 2021
@CirqBot CirqBot merged commit c5c2d95 into quantumlib:master Jan 26, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants