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 (backport #11682) #12479

Merged
merged 2 commits into from
Jun 4, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented May 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.


This is an automatic backport of pull request #11682 done by [Mergify](https://mergify.com).

* 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)
@mergify mergify bot requested a review from a team as a code owner May 30, 2024 08:06
@mergify mergify bot mentioned this pull request May 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 following people are relevant to this code:

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

@github-actions github-actions bot added Changelog: Bugfix Include in the "Fixed" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo affects extended support This issue (also) affects extended support labels May 30, 2024
@coveralls
Copy link

coveralls commented May 30, 2024

Pull Request Test Coverage Report for Build 9365761074

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.009%) to 86.958%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 1 93.13%
Totals Coverage Status
Change from base Build 9314544782: 0.009%
Covered Lines: 75020
Relevant Lines: 86272

💛 - Coveralls

@1ucian0 1ucian0 added this to the 0.46.2 milestone Jun 4, 2024
@1ucian0 1ucian0 enabled auto-merge June 4, 2024 11:54
@1ucian0 1ucian0 added this pull request to the merge queue Jun 4, 2024
Merged via the queue into stable/0.46 with commit 939dd93 Jun 4, 2024
11 checks passed
@mergify mergify bot deleted the mergify/bp/stable/0.46/pr-11682 branch June 4, 2024 13:00
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
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants