qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Fix evolved operator ansatz

Open sesajad opened this issue 1 year ago • 5 comments

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.

https://github.com/Qiskit/qiskit/blob/d033e8a4185c0299b644f0bdf4e8ed1d17d2bb08/qiskit/circuit/quantumcircuit.py#L1454

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 avatar Jan 30 '24 21:01 sesajad

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

qiskit-bot avatar Jan 30 '24 21:01 qiskit-bot

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 30 '24 21:01 CLAassistant

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Jan 30 '24 21:01 CLAassistant

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%
<!-- Total: 4
Totals Coverage Status
Change from base Build 7938039454: 0.01%
Covered Lines: 58916
Relevant Lines: 65977

💛 - Coveralls

coveralls avatar Jan 31 '24 11:01 coveralls

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

sesajad avatar Feb 08 '24 14:02 sesajad

@Mergifyio backport stable/0.46

1ucian0 avatar May 30 '24 08:05 1ucian0

backport stable/0.46

✅ Backports have been created

mergify[bot] avatar May 30 '24 08:05 mergify[bot]