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

Bug fix in HoareOptimizer #13083

Merged
merged 4 commits into from
Sep 4, 2024
Merged

Bug fix in HoareOptimizer #13083

merged 4 commits into from
Sep 4, 2024

Conversation

alexanderivrii
Copy link
Contributor

Summary

Fixes #13079.

Detailed Comments

The problem was due to first simplifying a controlled-gate by removing its controls (in the example: the control qubit of a CX-gate is at |1>, allowing to replace the CX-gate by an X-gate), then incorrectly keeping track of the simplified gate (in order to store the new X-gate for later purposes, the code mutated the original CX-gate in some weird way).

The code was already using substitute_node_with_dag to replace the controlled-gate by the base-gate (I don't really like this, but I don't think we can use substitute_node as the simplified node has fewer qubits than the original node). To fix the problem, we can instead read off the simplified gate from substitute_node_with_dag's output.

While this fixes the immediate problem, the code in HoareOptimizer is very messy and quite possibly contains many other sources of bugs (for instance, I did not like the idea of iterating over the DAG's topological nodes, while removing and simplifying some of the nodes in-place) and not optimized for performance. A complete rewrite while porting to Rust would be ideal :).

@alexanderivrii alexanderivrii added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Sep 4, 2024
@alexanderivrii alexanderivrii added this to the 1.3 beta milestone Sep 4, 2024
@alexanderivrii alexanderivrii requested a review from a team as a code owner September 4, 2024 06:38
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Sep 4, 2024

Pull Request Test Coverage Report for Build 10701833297

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • 32 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-0.03%) to 89.159%

Files with Coverage Reduction New Missed Lines %
qiskit/synthesis/two_qubit/xx_decompose/decomposer.py 1 95.42%
crates/qasm2/src/lex.rs 2 92.23%
crates/circuit/src/circuit_instruction.rs 5 86.32%
crates/circuit/src/dag_node.rs 6 82.17%
crates/qasm2/src/parse.rs 18 96.69%
Totals Coverage Status
Change from base Build 10691830429: -0.03%
Covered Lines: 72513
Relevant Lines: 81330

💛 - Coveralls

@Cryoris Cryoris added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Sep 4, 2024
@mtreinish mtreinish modified the milestones: 1.3 beta, 1.2.1 Sep 4, 2024
@Cryoris Cryoris added this pull request to the merge queue Sep 4, 2024
Merged via the queue into Qiskit:main with commit 576efcf Sep 4, 2024
15 checks passed
mergify bot pushed a commit that referenced this pull request Sep 4, 2024
* bug fix, test, reno

* suggestions from code review; lint

(cherry picked from commit 576efcf)
github-merge-queue bot pushed a commit that referenced this pull request Sep 4, 2024
* bug fix, test, reno

* suggestions from code review; lint

(cherry picked from commit 576efcf)

Co-authored-by: Alexander Ivrii <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

HoareOptimizer() changes circuit semantics
5 participants