-
Notifications
You must be signed in to change notification settings - Fork 131
Define BaseExperiment._transpiled_circuits and deprecate BaseExperiment._postprocess_transpiled_circuits #677
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
Conversation
bda4650
to
07e0246
Compare
BaseExperiment._postprocess_transpiled_circuits
CI failure appears to be unrelated:
|
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.
Code looks good to me but this is indeed conflicting with #667 @yaelbh could you please decide if merge this first or close this and make @kevinsung co-author of your PR.
"""Additional post-processing of transpiled circuits before running on backend""" | ||
pass | ||
def _transpile( | ||
self, circuits: List[QuantumCircuit], backend: Backend, **transpile_options |
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.
Probably backend is not necessary since you can access to it via self.backend
(also this will bypass _set_backend
hook). Transpile options and circuit too. Likely you want to make it static method -- is there any plan to hack this method? Something like injecting circuit which is not generated by this experiment instance?
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.
It is necessary because self.backend
could be None, in which case the backend is passed to BaseExperiment.run
and forwarded to this function.
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.
It should not be a static method because transpilation can depend on the experiment instance.
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.
This is not correct because existence of backend is guaranteed by these lines. Seems like this allows a hack that injecting backend which is not associated with the instance. Currently you are using self
to only access deprecated method.
https://github.com/Qiskit/qiskit-experiments/blob/317b964b8cbde0febcda8696fd4bd5cce3490e0a/qiskit_experiments/framework/base_experiment.py#L251-L259
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.
Nothing needs to be passed as kwargs to this function except the circuits (and that one is debatable too, the only reason to pass them is to allow overloading with some pre-transpilation logic). Options and backend should all be taken from the self
instance. As Naoki points out backend can never be None when this function is called inside run
.
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.
Perhaps you are assuming the situation the user directly call this method of the instance initialized without backend to check the physical circuit? Then I agree it's worth having backend here. But I think circuit and transpile options can come from self.
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.
Still, the backend needs to be forwarded because it uses experiment.backend
which could be different from self.backend
.
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.
Perhaps you are assuming the situation the user directly call this method of the instance initialized without backend to check the physical circuit? Then I agree it's worth having backend here. But I think circuit and transpile options can come from self.
Yes, exactly. If the user calls run
with a backend specified, then using self.backend
would be incorrect. I actually this this a bit confusing, and that only one way of passing the backend should be supported. That would also eliminate the need for the complicated backend selection code. But that is a separate issue.
I suggest that the PR that's ready first will be merged first, and the other one will resolve the conflicts |
"""Additional post-processing of transpiled circuits before running on backend""" | ||
pass | ||
def _transpile( | ||
self, circuits: List[QuantumCircuit], backend: Backend, **transpile_options |
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.
Nothing needs to be passed as kwargs to this function except the circuits (and that one is debatable too, the only reason to pass them is to allow overloading with some pre-transpilation logic). Options and backend should all be taken from the self
instance. As Naoki points out backend can never be None when this function is called inside run
.
@chriseclectic I have eliminated the transpilation options keyword arguments. As I explained above, |
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.
Thanks @kevinsung 😃.
I intentionally mark "Comment" and not "Request changes", to make the approvals of Chris and Naoki sufficient for merging the PR.
Please don't proceed with approving and merging this PR before we resolve #667 (comment). |
I've updated the code to align with #667 by changing |
CI failure appears unrelated again, see #682 |
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.
This looks very close. I would suggest merging #667 first, then rebasing this again after.
@chriseclectic I've addressed your comments. It might make sense to merge this before #667 because #667 actually includes this change and does more on top. |
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.
Minor formatting
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.
@kevinsung sounds good, we can merge this one first
Add BaseExperiment._transpile_circuits method and deprecate BaseExperiment._postprocess_transpiled_circuits Co-authored-by: Christopher J. Wood <cjwood@us.ibm.com>
Fixes #669.
Summary
Adds
BaseExperiment._transpiled_circuits
to enable customization of transpilation. This makesBaseExperiment._postprocess_transpiled_circuits
obsolete so that is deprecated with a version 0.4.0 deadline.Details and comments
@chriseclectic I didn't find any issues with composite experiments, but let me know if there are any specific tests I should add.