Skip to content

Conversation

@maffoo
Copy link
Contributor

@maffoo maffoo commented Jun 25, 2020

Also change the return type of transform_qubits in the same way. AFAICT this should always be correct, but it's sometimes tricky to convince mypy of this (have to cast in GateOperation.with_qubits, for example).

@maffoo maffoo requested a review from Strilanc June 25, 2020 17:26
@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Jun 25, 2020
def with_qubits(self, *new_qubits: 'cirq.Qid') -> 'cirq.Operation':
return self.gate.on(*new_qubits)
def with_qubits(self: TSelf, *new_qubits: 'cirq.Qid') -> TSelf:
return cast(TSelf, self.gate.on(*new_qubits))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: Have you tried making GateOperation parametrized with the type of gate it wraps? I think this should let us remove the cast.

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 didn't try that, but my experience with "genericizing" classes in python is that it is not trivial, especially for something this widely used. The relationship between gates and operations is also complicated by various specialized operation subclasses that we have.

@maffoo maffoo merged commit bbd8a2d into master Jun 25, 2020
tai271828 pushed a commit to tai271828/Cirq that referenced this pull request Jun 26, 2020
tai271828 pushed a commit to tai271828/Cirq that referenced this pull request Jun 27, 2020
tonybruguier pushed a commit to tonybruguier/Cirq that referenced this pull request Aug 23, 2020
@mpharrigan mpharrigan deleted the u/maffoo/op-self-type branch January 16, 2021 02:41
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.

3 participants