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

Fixes for device wire handling #42

Merged
merged 4 commits into from
Aug 19, 2020
Merged

Fixes for device wire handling #42

merged 4 commits into from
Aug 19, 2020

Conversation

josh146
Copy link
Member

@josh146 josh146 commented Aug 18, 2020

This PR contains the pasqal-independent bug fixes from #40 by @co9olguy

Copy link
Contributor

@mariaschuld mariaschuld left a comment

Choose a reason for hiding this comment

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

I am approving in the interest of time, and since the changes seem to work, but please double check the comment on calling the super function earlier. Might just be blind!

self._unsorted_qubits = qubits
self.qubits = sorted(qubits)

super().__init__(wires, shots, analytic)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why super is not called earlier? That would remove a lot of code above, because num_wires can be extracted from len(self.wires) or self.num_wires. One could still raise an error if qubits has a different length.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mariaschuld, here is @co9olguy's original comment: #40 (comment)

I had to move down the superclass initialization here, since it is the thing that creates the wire_map, but the wire_map can't be determined until the cirq qubits have been assigned

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah maybe that is due to other changes made in the original PR? In that case we can merge as is, to not to create conflicts!

Copy link
Member

Choose a reason for hiding this comment

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

define_wire_map is called in the parent class's __init__ method.

We don't need to know the number of qubits (as you say, that can be inferred), but we do need to do all this qubit pre-processing before define_wire_map makes sense to be called

consecutive_wires = Wires(cirq_order)

wire_map = zip(wires, consecutive_wires)
return OrderedDict(wire_map)
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool!

Copy link
Member

Choose a reason for hiding this comment

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

Worked really nicely once I figured out that Cirq always uses an ordering internally (the edge case of unordered qubits was never caught before in this plugin)

# wires that are not acted upon
self.circuit.append(cirq.IdentityGate(len(self.qubits))(*self.qubits))
for q in self.qubits:
self.circuit.append(cirq.IdentityGate(1)(q))
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand why len(self.qubits) can be replaced by 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, it looks like you are applying len(self.qubit) single-qubit identity gates, instead of one large identity gate.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but this is just putting a band-aid over an existing hack. Would be better for us to keep better track of the unused wires in the plugin (which we can now do easily!)

Copy link
Member

Choose a reason for hiding this comment

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

Have added a TODO in the codebase

@josh146
Copy link
Member Author

josh146 commented Aug 18, 2020

Thanks @mariaschuld! I'll get @co9olguy to give it a once over before we merge it in.

@josh146 josh146 requested a review from co9olguy August 18, 2020 07:57
@josh146 josh146 merged commit 7cfb6fc into master Aug 19, 2020
@josh146 josh146 deleted the wire-fixes branch August 19, 2020 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants