-
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
Fix evolved operator ansatz #11682
Fix evolved operator ansatz #11682
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:
|
This comment was marked as outdated.
This comment was marked as outdated.
Pull Request Test Coverage Report for Build 7942899973Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
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 for the fix, this looks very good! I left some minor comments below.
releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml
Show resolved
Hide resolved
…fae8f1e1001.yaml Co-authored-by: Julien Gacon <[email protected]>
Hi @Cryoris , I know you must've been busy, I just wanted to make sure you didn't miss this. |
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.
Looks good to me, thanks for the contribution!
Typically, I would request that we avoid accessing property method getters/setters from within the class's own implementation in most cases (e.g. prefer self._operators
over self.operators
). Chains of such accesses get confusing pretty quickly and can easily lead to initialization ordering bugs. This class is already guilty of this, and this PR doesn't add any additional use of this, so no changes requested.
* Fix handling of empty operators list in EvolvedOperatorAnsatz * Add test for empty operator list in EvolvedOperatorAnsatz * add release note for fixing evolved operator ansatz * Update releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml Co-authored-by: Julien Gacon <[email protected]> * add a note to fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * Update fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * merge two conditions in evolved_operator_ansatz Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Julien Gacon <[email protected]> (cherry picked from commit 8b6e4fe)
* Fix handling of empty operators list in EvolvedOperatorAnsatz * Add test for empty operator list in EvolvedOperatorAnsatz * add release note for fixing evolved operator ansatz * Update releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml Co-authored-by: Julien Gacon <[email protected]> * add a note to fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * Update fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * merge two conditions in evolved_operator_ansatz Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Julien Gacon <[email protected]> (cherry picked from commit 8b6e4fe) Co-authored-by: Seyed Sajad Kahani <[email protected]>
* Fix handling of empty operators list in EvolvedOperatorAnsatz * Add test for empty operator list in EvolvedOperatorAnsatz * add release note for fixing evolved operator ansatz * Update releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml Co-authored-by: Julien Gacon <[email protected]> * add a note to fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * Update fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * merge two conditions in evolved_operator_ansatz Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Julien Gacon <[email protected]>
@Mergifyio backport stable/0.46 |
✅ Backports have been created
|
* Fix handling of empty operators list in EvolvedOperatorAnsatz * Add test for empty operator list in EvolvedOperatorAnsatz * add release note for fixing evolved operator ansatz * Update releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml Co-authored-by: Julien Gacon <[email protected]> * add a note to fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * Update fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * merge two conditions in evolved_operator_ansatz Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Julien Gacon <[email protected]> (cherry picked from commit 8b6e4fe)
* Fix handling of empty operators list in EvolvedOperatorAnsatz * Add test for empty operator list in EvolvedOperatorAnsatz * add release note for fixing evolved operator ansatz * Update releasenotes/notes/fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml Co-authored-by: Julien Gacon <[email protected]> * add a note to fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * Update fix-evolved-operator-ansatz-empty-ops-bf8ecfae8f1e1001.yaml * merge two conditions in evolved_operator_ansatz Co-authored-by: Julien Gacon <[email protected]> --------- Co-authored-by: Julien Gacon <[email protected]> (cherry picked from commit 8b6e4fe) Co-authored-by: Seyed Sajad Kahani <[email protected]> Co-authored-by: Luciano Bello <[email protected]>
Summary
This resolves #11680, which pertains to a bug encountered when creating an EvolvedOperatorAnsatz with an empty list of operators.
Details and comments
The changes implemented ensure that EvolvedOperatorAnsatz.num_qubits returns a sensible result (specifically zero) when operators is an empty list, rather than throwing an error. This adjustment alone enables the following code to function correctly:
By solely doing this, in the above code, e.qregs contains a QuantumRegister with zero qubits. While its base class, QuantumCircuit, handles the case with no qubits by setting qregs to an empty list.
qiskit/qiskit/circuit/quantumcircuit.py
Line 1454 in d033e8a
We have mirrored this behavior in EvolvedOperatorAnsatz to ensure that
EvolvedOperatorAnsatz(operators=[])
behaves the same asQuantumCircuit()
. This equivalence is also asserted in a test.Please note that a brief release note has been added to the branch.