-
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 Migration Guide for QuantumInstance
#9554
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 4691111819
💛 - Coveralls |
|
||
The functionality of :class:`~qiskit.utils.QuantumInstance.execute` has | ||
now been delegated to the different implementations of the :mod:`~qiskit.primitives` base classes, | ||
while the explicit transpilation has been left to the :mod:`~qiskit.transpiler` module (see table below). |
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 more a comment, but since its talking about transpilation its done by default now by the primitives, so algorithms no longer need to manage that aspect along with binding parameters. Transpilation can be turned off - but since operator and circuit size need to match for Estimator, doing your own transpilation needs to meet that constraint - if say it adds swaps, which increase overall circuit width, then it will fail as there is no mechanism to say identify the active qubits it should consider.
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 have added that algorithms no longer need to take care of transpilation, as it has been moved to the primitive level. I will see where I can mention the transpilation + Estimator challenges.
* - QuantumInstance method | ||
- Alternative | ||
* - ``QuantumInstance.execute`` | ||
- ``Sampler.run`` or ``Estimator.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.
This might also be an alternative https://qiskit.org/documentation/apidoc/execute.html - though the QI one had the mitigation, job splitting/combining and reliability which you may now want/need to do yourself if using 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.
We're probably going to deprecate execute
, so that would not need to be listed as alternative 🙂 See also #7892
circuit.x(1) | ||
circuit.measure_all() | ||
|
||
sampler = Sampler(run_options = {"method":"statevector", "shots":200}) |
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.
Similar comment. I will note while this is ok for Sampler presently, as far as I am aware, the Aer Estimator will override any method you pass it as it sets it internally based on approximation and if noise model is used.
|
||
estimator = Estimator( | ||
backend_options={ | ||
"method": "density_matrix", |
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.
As mentioned above this will be overidden in any case - yes, you have what it chooses internally but there is no choice at this level.
On the other hand, when using the primitives: | ||
|
||
* You cannot explicitly access their transpilation routine. | ||
* The mechanism to apply custom transpilation passes to the Aer, Runtime and Backend primitives is to pre-transpile |
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.
Care is needed here - as I mentioned in one of the earlier comments at the head of the file. In opflow the ansatz would always have the basis change and measurement gates added before transpilation so if the circuit ended up on more qubits it did not matter. Transpiling it first before giving it to the Estimator is a different flow.
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.
added a warning
Aer simulation following the statevector method. This would be the direct 1-1 replacement of the ``QuantumInstance`` | ||
example, as they are both accessing the same simulator. For this reason, the output metadata is | ||
closer to the Quantum Instance's output. Please note that | ||
the resulting quasi-probability distribution does not use bitstrings but **integers** to identify the states. |
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.
You could note the QuasiProb does have methods binary_probabilities
and hex_probabilities
if the integer keys are not to your liking.
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.
Added note and example
Co-authored-by: Steve Wood <[email protected]>
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.
LGTM! Again, just minor grammar tweaks.
Co-authored-by: Declan Millar <[email protected]>
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.
Hi Elena. The content looks great!
However I have some comments about the Sphinx links.
The only alternative for local simulations using the quantum instance was using an Aer Simulator backend. | ||
Please note that ``QuantumInstance.execute()`` returned the counts bitstrings in hexadecimal format. | ||
|
||
.. testcode:: |
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.
If you don't plan to run the tests (I see that you used the SKIP
flag) you can use .. code-block:: python
and .. code-block:: text
for input and output respectively so you don't depend on the Sphinx doctest
extension.
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 didn't know about .. code-block:: text
, thanks!
Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]>
…terra into qi-migration-guide
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.
Some minor points and one comment on the unbound PMs, otherwise LGTM 👍🏻
Quasi dists: [{2: 0.0008492371522941081, 3: 0.9968874384378738, 0: -0.0003921227905920063, | ||
1: 0.002655447200424097}] | ||
|
||
.. dropdown:: Example 4: Circuit Sampling with Custom Bound and Unbound Pass Managers |
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.
The power of unbound and bound pass managers in the quantum instance is actually coming from the combination with the CircuitSampler
🙂 If you have an unbound
and bound
pass manager (for example, the unbound pass manager does the routing and high level optimization and the bound
does pulse optimization), then you could do
qi = QuantumInstance(pass_manager=unbound, bound_pass_manager=bound, ....)
sampler = CircuitSampler(qi)
circuits = .... # circuit with *free* parameters
sampler.convert(circuits, param_values=....) # sampler will first do the unbound, then bind, then the bound for you
This workflow is (afaik) not possible anymore with the primitives. Should we update this example?
Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: Julien Gacon <[email protected]>
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.
LGTM thanks for all the detailed work on the migration guides!
* Add draft * Remove qiskit * Add qi migration file * Add content * Finish content * Update provider syntax * Finish content * Apply auto-suggestions * Add doctests * Change to dropdowns * Add EM results * Apply suggestions from code review Co-authored-by: Steve Wood <[email protected]> * Apply review comments * Apply suggestions from Declan's code review Co-authored-by: Declan Millar <[email protected]> * Apply suggestions from Guillermo's code review Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> * Change from doctest to codeblocks * Review follow-up edits * Replace statevector with quantum info * Reorder index * Add assemble alternative * Apply suggestions from Julien's code review Co-authored-by: Julien Gacon <[email protected]> * Change transpilation example * Apply suggestions from Juliencode review Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Steve Wood <[email protected]> Co-authored-by: Declan Millar <[email protected]> Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> Co-authored-by: Julien Gacon <[email protected]>
* Add draft * Remove qiskit * Add qi migration file * Add content * Finish content * Update provider syntax * Finish content * Apply auto-suggestions * Add doctests * Change to dropdowns * Add EM results * Apply suggestions from code review Co-authored-by: Steve Wood <[email protected]> * Apply review comments * Apply suggestions from Declan's code review Co-authored-by: Declan Millar <[email protected]> * Apply suggestions from Guillermo's code review Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> * Change from doctest to codeblocks * Review follow-up edits * Replace statevector with quantum info * Reorder index * Add assemble alternative * Apply suggestions from Julien's code review Co-authored-by: Julien Gacon <[email protected]> * Change transpilation example * Apply suggestions from Juliencode review Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Steve Wood <[email protected]> Co-authored-by: Declan Millar <[email protected]> Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> Co-authored-by: Julien Gacon <[email protected]>
* Add draft * Remove qiskit * Add qi migration file * Add content * Finish content * Update provider syntax * Finish content * Apply auto-suggestions * Add doctests * Change to dropdowns * Add EM results * Apply suggestions from code review Co-authored-by: Steve Wood <[email protected]> * Apply review comments * Apply suggestions from Declan's code review Co-authored-by: Declan Millar <[email protected]> * Apply suggestions from Guillermo's code review Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> * Change from doctest to codeblocks * Review follow-up edits * Replace statevector with quantum info * Reorder index * Add assemble alternative * Apply suggestions from Julien's code review Co-authored-by: Julien Gacon <[email protected]> * Change transpilation example * Apply suggestions from Juliencode review Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Steve Wood <[email protected]> Co-authored-by: Declan Millar <[email protected]> Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> Co-authored-by: Julien Gacon <[email protected]>
* Add draft * Remove qiskit * Add qi migration file * Add content * Finish content * Update provider syntax * Finish content * Apply auto-suggestions * Add doctests * Change to dropdowns * Add EM results * Apply suggestions from code review Co-authored-by: Steve Wood <[email protected]> * Apply review comments * Apply suggestions from Declan's code review Co-authored-by: Declan Millar <[email protected]> * Apply suggestions from Guillermo's code review Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> * Change from doctest to codeblocks * Review follow-up edits * Replace statevector with quantum info * Reorder index * Add assemble alternative * Apply suggestions from Julien's code review Co-authored-by: Julien Gacon <[email protected]> * Change transpilation example * Apply suggestions from Juliencode review Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Steve Wood <[email protected]> Co-authored-by: Declan Millar <[email protected]> Co-authored-by: Guillermo-Mijares-Vilarino <[email protected]> Co-authored-by: Julien Gacon <[email protected]>
Summary
Closes #9517.
Details and comments
Blocked by #9549