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

Give repr to contrib.routing.SwapNetwork, add error message test for unmapped qubits #2251

Closed
wants to merge 12 commits into from

Conversation

Strilanc
Copy link
Contributor

@Strilanc Strilanc commented Oct 1, 2019

No description provided.

# Conflicts:
#	cirq/contrib/acquaintance/permutation.py
#	cirq/contrib/routing/swap_network_test.py
@Strilanc Strilanc requested a review from bryano October 1, 2019 03:04
@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Oct 1, 2019
b: b
})
with pytest.raises(ValueError, match='acts on unmapped qubit'):
_ = list(swap_network.get_logical_operations())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the mock assignment for pylint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sometimes pylint complains that the result of an expression is unused. So I got into the habit of assigning to _ as a way of saying "I know I'm throwing this away".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe

for op in swap_network.get_logical_operations():
    pass # coverage: ignore

It's fine as-is if you have a preference.

if (isinstance(op, ops.GateOperation) and
isinstance(op.gate, PermutationGate)):
op.gate.update_mapping(mapping, op.qubits)
# Ignoring type warning about passing an abstract type into Type[...].
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe link to the issue here?

isinstance(op.gate, PermutationGate)):
op.gate.update_mapping(mapping, op.qubits)
# Ignoring type warning about passing an abstract type into Type[...].
gate = ops.op_gate_of_type(op, PermutationGate) # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this just a style preference?

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 can revert it if you prefer. It's just much shorter, and it's why we defined these methods.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have a preference. IIRC, this is what I originally wrote, and changed it to avoid the type issues.

gate = ops.op_gate_of_type(op, PermutationGate) # type: ignore
if gate is not None:
# Ignoring type warning about op.qubits not being a tuple.
gate.update_mapping(mapping, op.qubits) # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does mypy think op.qubits has type Union[Tuple[Qid, ...], FrozenSet[Qid]]? Shouldn't it be a tuple?

Copy link
Contributor Author

@Strilanc Strilanc Oct 2, 2019

Choose a reason for hiding this comment

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

I honestly don't know. My guess is that somewhere in the code base a qubits method returns a FrozenSet[Qid] and mypy is inferring the return type from that, but I wasn't able to find where.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like a silly thing to spend too much time on, but this seems like a case where mypy might actually be catching an bug, so maybe we shouldn't override it so quickly.

@bryano
Copy link
Collaborator

bryano commented Oct 12, 2019

I don't want to hold this up on the mypy thing; if you think it's not worth the trouble, that's fine.

LGTM after adding the link to the issue.

@bryano
Copy link
Collaborator

bryano commented Dec 12, 2019

@Strilanc ping

@Strilanc Strilanc added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Apr 28, 2020
@CirqBot
Copy link
Collaborator

CirqBot commented Apr 28, 2020

Automerge cancelled: No approved review.

@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Apr 28, 2020
Copy link
Collaborator

@dabacon dabacon left a comment

Choose a reason for hiding this comment

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

Is there a reason this shouldn't be submitted?

@bryano
Copy link
Collaborator

bryano commented May 11, 2020

I thought it was good modulo getting the tests passed.

@balopat
Copy link
Contributor

balopat commented Jul 10, 2020

@Strilanc - can you have a look at this why it's failing and merge it?

@Strilanc
Copy link
Contributor Author

Closed as obsolete

@Strilanc Strilanc closed this Jul 16, 2020
@Strilanc Strilanc deleted the flakes1 branch July 16, 2020 20:30
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.

7 participants