-
Notifications
You must be signed in to change notification settings - Fork 127
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
Fix barrier instructions in tomography experiments #1059
Conversation
`QuantumCircuit.barrier()` accepts many forms of input, but `tuple` is not one of them. The prep and measurement indices passed as tuples to the barrier method were causing qpy serialization/deserialization to fail. It is possible that there were other unnoticed consequences to the type of the barrier argument being incorrect. Closes https://github.com/Qiskit/qiskit-ibm-provider/issues/523
I will add a release note. #1060 should probably be moved to this repo, though maybe it's not worth the trouble. |
I added a release note. mtreinish moved the issue into the repo. |
Also, I fixed the |
Thanks for the fix! Perhaps we should add a test that tomography circuits can be serialized and deserialized? |
I added some simple tests. In principle a test like these could be added for every experiment.
I stepped through in the debugger and followed what happened for reset. Although the type hint suggests that
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barrier thing seems like a straightforward fix, but can you change the reset one back to keep code cleaner unless there is a specific issue with it since this is expected behaviour of that instruction.
@@ -219,9 +219,10 @@ def circuits(self): | |||
if prep_element: | |||
# Add tomography preparation | |||
prep_circ = self._prep_circ_basis.circuit(prep_element, self._prep_physical_qubits) | |||
circ.reset(self._prep_indices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this one actually causing an issue? All 1-qubit instructions in terra are setup to broadcast over the arguments so shouldn't have any issues with qpy, and unless that changes I dont think we need to change this (And if there is specifically an issue with tuple, then it can be converted to a list)
eg reset doc string indicates it works with more than 1-qubit:
reset(qubit: 'QubitSpecifier') -> 'InstructionSet' method of qiskit.circuit.quantumcircuit.QuantumCircuit instance
Reset the quantum bit(s) to their default state.
Args:
qubit: qubit(s) to reset.
Returns:
qiskit.circuit.InstructionSet: handle to the added instruction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change it back. You and I put more weight on different parts of the quoted text 🙂 The qubit: 'QubitSpecifier'
type annotation says to me that it accepts only a single qubit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just went with qubit(s)
:D
qpy_file = io.BytesIO() | ||
qpy.dump(circs, qpy_file) | ||
qpy_file.seek(0) | ||
new_circs = qpy.load(qpy_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beyond scope of this PR, but we should probably add similar tests for serialization of generated circuits for all experiments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #1063 to keep track of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can probably use the round trip json serialization test function (like we use for experiment data), since json serializer should serialize a list of circuits via qpy.
Since I addressed @chriseclectic's feedback and the PR was pretty straightforward, I added it to auto-merge since we just enabled it and #1062 was already in the queue and we wanted to see how it auto-merging handles multiple queued PR's. |
I'd expect this to be prevent from enqueued because of @chriseclectic's changes requested review is sticky. But it'll be interesting to watch this all play out. It's a new feature in github and I've not used it yet. |
Ah, that makes sense. It shows me now "Auto-merge enabled" but I don't see it in the merge queue so far. It is still running checks. The documentation made it sound like I wouldn't be able to enable auto-merge until all the checks had passed. I am glad that is not the case because part of the motivation is not having to wait for all the tests to pass and the branch be up to date before queuing something for merging. Do you happen to know how the commit message works? It didn't prompt me for one and we are using squash merging, so it seems like we might get stuck with the automated message that combines all the messages. |
I found this post about the commit message. It looks like you can choose from a few options (the concatenated commit messages, the PR title and description, or just the PR title). |
Ah cool, that's good to know that's there now, it's a relatively recent (well 6 months ago) addition from that post. Personally I prefer the default combination of the branch's commit messages. But I also tend to write more detailed commit messages for each intermediate commit on a PR branch, and I know others typically don't bother. |
Hmm, actually, that post is about the default commit message, which is what I thought auto-merging might have to use, but I see here that the documentation for auto-merging says that it should prompt for a commit message if you are using the merge or squash methods, but I didn't get that prompt.
I like that style as well, but it doesn't work very well with GitHub PR reviews. With that style, when the reviewer requests changes, ideally you could go back and rebase/squash fixes into the individual commits and force push, but then GitHub gives up and shows you the full diff again. If you just do little clean up commits, GitHub will give you the option to see just the diff of those cleanups which makes it easy for a reviewer to do a follow up review. Ideally, there would be a workflow that makes it easy for the reviewer to review the responses to their feedback with the multiple commit style. |
It seems like that documentation I screenshotted is not correct (yet?). The workaround is to choose the default commit message to be the PR title and description as suggested here like I had mentioned in my post before last. |
Merge queue setting changed
Summary
Fix barrier instructions in tomography experiments
Details and comments
QuantumCircuit.barrier()
accepts many forms of input, buttuple
is not one of them. The prep and measurement indices passed as tuples to the barrier method were causing qpy serialization/deserialization to fail. It is possible that there were other unnoticed consequences to the type of the barrier argument being incorrect.Closes #1060.
See also this Slack thread.