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

Change operator comparison from np.array_equal to np.allclose (#6473) #6644

Merged
merged 6 commits into from
Jul 13, 2021

Conversation

mattwright99
Copy link
Contributor

Summary

Fixes #6473

Details and comments

Optimize1qGatesDecompositions would not optimize single qubit gates if they are sufficiently close to the identity (see #6473 for example). This was fixed by replacing the np.array_equals function with the np.allclose function to compare the operator to the identity. We use an absolute threshold of 1e-15.

New output:

>>> import qiskit as qk
>>> from qiskit.transpiler.passes import Optimize1qGates, Optimize1qGatesDecomposition
>>> qc = qk.QuantumCircuit(1)
>>> qc.u1(1e-17, 0)
>>> qc.draw()
     ┌───────┐
q_0: ┤ U1(0) ├
     └───────┘
>>> Optimize1qGatesDecomposition(basis=['u1', 'u2', 'u3'])(qc).draw()

q_0:

>>>      

@mattwright99 mattwright99 requested a review from a team as a code owner June 25, 2021 21:18
@mattwright99 mattwright99 changed the title Change operator comparison from np.array_equal to np.allclose. Change operator comparison from np.array_equal to np.allclose (#6473) Jun 25, 2021
@levbishop
Copy link
Member

Looks good can you add a release note?

@levbishop levbishop added bug Something isn't working Changelog: Bugfix Include in the "Fixed" section of the changelog and removed bug Something isn't working labels Jul 9, 2021
@mattwright99
Copy link
Contributor Author

@levbishop should be good now!

Copy link
Member

@levbishop levbishop 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 this

@kdk kdk added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Jul 13, 2021
@kdk kdk added this to the 0.19 milestone Jul 13, 2021
@mergify mergify bot merged commit 3fcc055 into Qiskit:main Jul 13, 2021
mergify bot pushed a commit that referenced this pull request Jul 13, 2021
) (#6644)

* Change operator comparison from `np.array_equal` to `np.allclose`.

* Added release notes

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 3fcc055)
@mattwright99 mattwright99 deleted the issue6473 branch July 14, 2021 00:00
mergify bot added a commit that referenced this pull request Jul 14, 2021
) (#6644) (#6739)

* Change operator comparison from `np.array_equal` to `np.allclose`.

* Added release notes

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 3fcc055)

Co-authored-by: Matt Wright <44040188+mattwright99@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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
None yet
Development

Successfully merging this pull request may close these issues.

Optimize1qGatesDecompositions does not optimize single (non-parameterized) epsilon rotations
4 participants