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 wrong relative phase of MCRZ #9836

Merged
merged 46 commits into from
May 22, 2023
Merged

Fix wrong relative phase of MCRZ #9836

merged 46 commits into from
May 22, 2023

Conversation

adjs
Copy link
Contributor

@adjs adjs commented Mar 22, 2023

Summary

This PR is on top of PR #9688 and fixes #9202.

rafaella-vale and others added 30 commits March 1, 2023 01:04
Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>
Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>
This reverts commit fab1c80.
@adjs
Copy link
Contributor Author

adjs commented Apr 21, 2023

I think this could be discussed in another PR, because these points are also present in the main branch.

@adjs
Copy link
Contributor Author

adjs commented Apr 21, 2023

Thanks for this addition, overall the fix looks great! I left some comments below, mainly formalities.

If possible I think we would like to include this in the upcoming release, so let us know if there's anything we can help you with 🙂

./run_experiments doesn't work on my computer and I couldn't find documentation on these tests. Could you fix the compatibility tests?

@adjs
Copy link
Contributor Author

adjs commented Apr 21, 2023

@ShellyGarion and @Cryoris thanks for the review.

@adjs adjs requested a review from Cryoris April 21, 2023 17:54
@mtreinish mtreinish added the Changelog: Bugfix Include in the "Fixed" section of the changelog label May 1, 2023
@mtreinish
Copy link
Member

I looked at the qpy test failures locally (fwiw all you need is to have gnu parallel installed and run ./run_tests.sh from the test/qpy_compat dir) the root cause of the failure is the changes to the generic .control() definition. This is causing a divergence from the nested definition of the custom controlled gate from the qpy files generate in the old release and the expected circuit we generate in the current main version of the code. I think if we're saying the definition prior to this PR was incorrect and needs to be different the only path forward here is to change https://github.com/Qiskit/qiskit-terra/blob/main/test/qpy_compat/test_qpy.py#L605-L610 to only run generate_controlled_gates() and generate_open_controlled_gates() if version_parts >= (0, 25, 0) because we're not going to be able to validate the equivalence of the stored qpy prior to this change otherwise.

# pylint: disable=cyclic-import
from qiskit import transpile

self = transpile(self, basis_gates=["p", "u", "cx"], optimization_level=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is quite correct, sorry if I didn't express it correctly before. With this code, the whole circuit will get transpiled to the specified basis -- but we only want the newly added mcrz to be in that basis 🙂 maybe we can just change mcsu2_real_diagonal to return the MCRZ subcircuit and then transpile that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Cryoris , I removed the transpile call.
I think that we should not transpile the MCRZ circuit here, because of the transpile cost with a higher number of controls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's not the most efficient way, but we should ensure that use_basis_gates=True will still behave as it did before 🙂 If we want to avoid transpiling, would it be possible to express mcsu2 in the P U CX basis?

@mtreinish mtreinish modified the milestones: 0.24.0, 0.24.1 May 4, 2023
@adjs adjs requested a review from Cryoris May 4, 2023 21:01
@Cryoris
Copy link
Contributor

Cryoris commented May 16, 2023

I pushed a small change to accomodate the use_basis_gates, other than that the PR LGTM. Since I modified the code maybe @mtreinish, @ShellyGarion or @alexanderivrii could have another look?

@adjs
Copy link
Contributor Author

adjs commented May 18, 2023

Thanks @Cryoris. Your modifications LGTM.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too

@mtreinish mtreinish added this pull request to the merge queue May 22, 2023
Merged via the queue into Qiskit:main with commit 7b677ed May 22, 2023
mergify bot pushed a commit that referenced this pull request May 22, 2023
* efficient multicontrolled su2 gate decomposition

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* removed optimization flag

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* tox -eblack

* updated docstrings

* Adds `MCSU2Gate` to `__init__`

* fixed circular import

* defined control and inverse methods

* changed MCSU2Gate from Gate to ControlledGate

* adjusted some tests for controlled gates

* reformatting

* Fix regarding the integer `ctrl_state` parameter

* Tests to check the CX count upper bound

* Gate's `label` in the `control` function

* Upd. Qiskit tests to include cases for MCSU2Gate

* Upd. Qiskit tests to include cases for MCSU2Gate

* Revert "Upd. Qiskit tests to include cases for MCSU2Gate"

This reverts commit c1ceaf6.

* Revert "Upd. Qiskit tests to include cases for MCSU2Gate"

This reverts commit 7c75611.

* Revert "Tests to check the CX count upper bound"

This reverts commit 100a690.

* Update test_controlled_gate.py

* Update test_circuit_operations.py

* remove mcsu2gate class

* remove mcsu2gate class

* fix mcry

* lint

* fix mcrx

* add reference

* Create `s_gate` directly

* Revert "Create `s_gate` directly"

This reverts commit b762b39.

* review

* release notes

* review 2

* backwards compat

* function signature and number of controls

* fix mcrz

* Update multi_control_rotation_gates.py

* review

* Update test_qpy.py

* Revert "Update test_qpy.py"

This reverts commit fab1c80.

* Update test_qpy.py

* Update multi_control_rotation_gates.py

* Fix `use_basis_gates=True` case

* lint

---------

Co-authored-by: rafaella-vale <26910380+rafaella-vale@users.noreply.github.com>
Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Rafaella Vale <rfv@cin.ufpe.br>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
(cherry picked from commit 7b677ed)

# Conflicts:
#	qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py
Cryoris pushed a commit that referenced this pull request May 23, 2023
* efficient multicontrolled su2 gate decomposition

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* removed optimization flag

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* tox -eblack

* updated docstrings

* Adds `MCSU2Gate` to `__init__`

* fixed circular import

* defined control and inverse methods

* changed MCSU2Gate from Gate to ControlledGate

* adjusted some tests for controlled gates

* reformatting

* Fix regarding the integer `ctrl_state` parameter

* Tests to check the CX count upper bound

* Gate's `label` in the `control` function

* Upd. Qiskit tests to include cases for MCSU2Gate

* Upd. Qiskit tests to include cases for MCSU2Gate

* Revert "Upd. Qiskit tests to include cases for MCSU2Gate"

This reverts commit c1ceaf6.

* Revert "Upd. Qiskit tests to include cases for MCSU2Gate"

This reverts commit 7c75611.

* Revert "Tests to check the CX count upper bound"

This reverts commit 100a690.

* Update test_controlled_gate.py

* Update test_circuit_operations.py

* remove mcsu2gate class

* remove mcsu2gate class

* fix mcry

* lint

* fix mcrx

* add reference

* Create `s_gate` directly

* Revert "Create `s_gate` directly"

This reverts commit b762b39.

* review

* release notes

* review 2

* backwards compat

* function signature and number of controls

* fix mcrz

* Update multi_control_rotation_gates.py

* review

* Update test_qpy.py

* Revert "Update test_qpy.py"

This reverts commit fab1c80.

* Update test_qpy.py

* Update multi_control_rotation_gates.py

* Fix `use_basis_gates=True` case

* lint

---------

Co-authored-by: rafaella-vale <26910380+rafaella-vale@users.noreply.github.com>
Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Rafaella Vale <rfv@cin.ufpe.br>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
(cherry picked from commit 7b677ed)

# Conflicts:
#	qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py
jakelishman pushed a commit that referenced this pull request May 23, 2023
* Fix wrong relative phase of MCRZ (#9836)

* efficient multicontrolled su2 gate decomposition

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* removed optimization flag

Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>

* tox -eblack

* updated docstrings

* Adds `MCSU2Gate` to `__init__`

* fixed circular import

* defined control and inverse methods

* changed MCSU2Gate from Gate to ControlledGate

* adjusted some tests for controlled gates

* reformatting

* Fix regarding the integer `ctrl_state` parameter

* Tests to check the CX count upper bound

* Gate's `label` in the `control` function

* Upd. Qiskit tests to include cases for MCSU2Gate

* Upd. Qiskit tests to include cases for MCSU2Gate

* Revert "Upd. Qiskit tests to include cases for MCSU2Gate"

This reverts commit c1ceaf6.

* Revert "Upd. Qiskit tests to include cases for MCSU2Gate"

This reverts commit 7c75611.

* Revert "Tests to check the CX count upper bound"

This reverts commit 100a690.

* Update test_controlled_gate.py

* Update test_circuit_operations.py

* remove mcsu2gate class

* remove mcsu2gate class

* fix mcry

* lint

* fix mcrx

* add reference

* Create `s_gate` directly

* Revert "Create `s_gate` directly"

This reverts commit b762b39.

* review

* release notes

* review 2

* backwards compat

* function signature and number of controls

* fix mcrz

* Update multi_control_rotation_gates.py

* review

* Update test_qpy.py

* Revert "Update test_qpy.py"

This reverts commit fab1c80.

* Update test_qpy.py

* Update multi_control_rotation_gates.py

* Fix `use_basis_gates=True` case

* lint

---------

Co-authored-by: rafaella-vale <26910380+rafaella-vale@users.noreply.github.com>
Co-authored-by: thiagom123 <thiagomdazevedo@hotmail.com>
Co-authored-by: IsmaelCesar <leamscesar@gmail.com>
Co-authored-by: Israel F. Araujo <israelferrazaraujo@hotmail.com>
Co-authored-by: Rafaella Vale <rfv@cin.ufpe.br>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
(cherry picked from commit 7b677ed)

# Conflicts:
#	qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py

* fix conflicts

---------

Co-authored-by: Adenilton Silva <7927558+adjs@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
@adjs adjs deleted the fix-mcrz branch August 2, 2023 18:58
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 Community PR PRs from contributors that are not 'members' of the Qiskit repo priority: medium 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.

QuantumCircuit.mcrz not correct
8 participants