qiskit
qiskit copied to clipboard
Fix evolved operator ansatz
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.
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
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.
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.
- For more information on this, see Tracking coverage changes with pull request builds.
- To avoid this issue with future PRs, see these Recommended CI Configurations.
- For a quick fix, rebase this PR at GitHub. Your next report should be accurate.
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 | |
|---|---|
| Change from base Build 7938039454: | 0.01% |
| Covered Lines: | 58916 |
| Relevant Lines: | 65977 |
💛 - Coveralls
Hi @Cryoris , I know you must've been busy, I just wanted to make sure you didn't miss this.
@Mergifyio backport stable/0.46
backport stable/0.46
✅ Backports have been created
- #12479 Fix evolved operator ansatz (backport #11682) has been created for branch
stable/0.46