-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add transpile_operator function to primitives.utils #9988
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 4743816955
💛 - Coveralls |
I have seen users try to do this when using the applications and passing in what they consider an already optimized ansatz they have transpiled themselves and failing as the resultant circuit, with swaps, is wider (more qubits) than the original operator. I had wondered about whether an Estimator could take some mapping the user passed in that mapped the original qubits to the ones in the circuit and did whatever it needed to do internally. From an application standpoint the stacks today just pass down operators into algorithms pre-built out by the user configured with primitives. Currently these have no visibility to the notion of whether a circuit might have been transpiled and the user has setup the Estimator to skip transpilation and passed some pre-transpiled circuit as an ansatz. If a user uses an Estimator directly then what is proposed here works; given how the application stacks are today and the user preparing an algorithm with a primitive something needs to be done to cater to that too. Arguably the notion of transpilation or not could be propagated higher up the stack and have each algo deal with it that uses an Estimator. From my perspective it would be nicer if it whatever was need to be done was more self-contained with the primitive, such that it would deal with the matching of the operator to the transpiled circuit based on the user configuring the primitive according - ie skip_translation and whatever was needed to understand the circuit mapping/layout. |
TBH, we did not expect that transpiled circuits would be passed on, and the introduction of I would like to make a fundamental fix, but the main bottleneck is that the layout of a transpiled circuit does not remember the original qubits. Therefore, I am passing |
The original qubits should be in the |
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.
Overall LGTM, I just have some minor comments below 🙂
--- | ||
features: | ||
- | | ||
Add :func:`~primitives.utils.transpile_operator` 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.
I'm not sure this will be found as it is, I think it would be safer to either add the full path, or use .transpile_operator
only 🙂
Add :func:`~primitives.utils.transpile_operator` function. | |
Add :func:`~qiskit.primitives.utils.transpile_operator` function. |
result = BackendEstimator(backend=backend).run(trans_qc, trans_op).result() | ||
if optionals.HAS_AER: | ||
self.assertAlmostEqual(result.values[0], -0.045, places=2) | ||
else: | ||
self.assertAlmostEqual(result.values[0], 0, places=2) |
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.
Could you add an additional test that checks that trans_op
equals the expected operator? Testing that the values are correct is also good, but there are other steps included which could affect the test, so I think it would be good to have a very specific one too 🙂
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.
sure.
@@ -15,16 +15,18 @@ | |||
from __future__ import annotations | |||
|
|||
from collections.abc import Iterable | |||
from typing import Sequence |
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.
Should we use collections.abc
instead of typing
here?
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.
Oh... What’s wrong with me
@mtreinish Thank you. I checked |
I'm wondering if |
I just opened a PR #10835 which I think will make this a lot easier to adjust based on the layout from a transpiled circuit inside the estimator. |
I think it is best if this is not inside the |
#10947 is better than this PR. |
Summary
Details and comments