Skip to content
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

Merged
merged 10 commits into from
Mar 7, 2024

Conversation

sesajad
Copy link
Contributor

@sesajad sesajad commented Jan 30, 2024

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:

e = EvolvedOperatorAnsatz(operators=[])

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.

if regs[0] == 0:

We have mirrored this behavior in EvolvedOperatorAnsatz to ensure that EvolvedOperatorAnsatz(operators=[]) behaves the same as QuantumCircuit(). This equivalence is also asserted in a test.

Please note that a brief release note has been added to the branch.

@sesajad sesajad requested a review from a team as a code owner January 30, 2024 21:43
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jan 30, 2024
@qiskit-bot
Copy link
Collaborator

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:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@CLAassistant
Copy link

CLAassistant commented Jan 30, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant

This comment was marked as outdated.

@1ucian0 1ucian0 added Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable labels Jan 31, 2024
@1ucian0 1ucian0 added this to the 1.0.0 milestone Jan 31, 2024
@coveralls
Copy link

coveralls commented Jan 31, 2024

Pull Request Test Coverage Report for Build 7942899973

Warning: 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

  • 0 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 89.298%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.94%
Totals Coverage Status
Change from base Build 7938039454: 0.01%
Covered Lines: 58916
Relevant Lines: 65977

💛 - Coveralls

Copy link
Contributor

@Cryoris Cryoris left a 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.

@jakelishman jakelishman modified the milestones: 1.0.0, 1.0.1 Feb 1, 2024
@sesajad
Copy link
Contributor Author

sesajad commented Feb 8, 2024

Hi @Cryoris , I know you must've been busy, I just wanted to make sure you didn't miss this.

@sesajad sesajad requested a review from Cryoris February 17, 2024 16:28
@jakelishman jakelishman modified the milestones: 1.0.1, 1.0.2 Feb 22, 2024
@kevinhartman kevinhartman self-assigned this Mar 6, 2024
Copy link
Contributor

@kevinhartman kevinhartman left a 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.

@kevinhartman kevinhartman added this pull request to the merge queue Mar 7, 2024
Merged via the queue into Qiskit:main with commit 8b6e4fe Mar 7, 2024
12 checks passed
mergify bot pushed a commit that referenced this pull request Mar 7, 2024
* 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)
github-merge-queue bot pushed a commit that referenced this pull request Mar 7, 2024
* 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]>
IsmaelCesar pushed a commit to comp-quantica/qiskit-terra that referenced this pull request Mar 13, 2024
* 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]>
@1ucian0 1ucian0 added the affects extended support This issue (also) affects extended support label May 30, 2024
@1ucian0
Copy link
Member

1ucian0 commented May 30, 2024

@Mergifyio backport stable/0.46

Copy link
Contributor

mergify bot commented May 30, 2024

backport stable/0.46

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 30, 2024
* 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)
github-merge-queue bot pushed a commit that referenced this pull request Jun 4, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects extended support This issue (also) affects extended support Changelog: Bugfix Include in the "Fixed" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

EvolvedOperatorAnsatz with an empty list of operators
8 participants