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 a misprint in a formula in two_qubit_decompose #11953

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

ShellyGarion
Copy link
Member

@ShellyGarion ShellyGarion commented Mar 6, 2024

Summary

Fix a misprint in a formula in the function _closest_partial_swap in two_qubit_decompose,
according to @levbishop .

Details and comments

The formula is based on equations (B3)-(B5) in https://arxiv.org/abs/1811.12926

image
image

Set m = (a+b+c)/3 and write everything as deviations from that mean
a -> eps da + m, b-> eps db + m, c -> eps dc + m
x -> eps dx + m
and then solve for d/dx = 0 up to nth order in eps gives:

image

Since this change is of order eps^6 it does not affect the tests, and is almost undetectable.

@ShellyGarion ShellyGarion requested review from alexanderivrii and a team as code owners March 6, 2024 08:58
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @levbishop

@coveralls
Copy link

Pull Request Test Coverage Report for Build 8169395262

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 89.299%

Totals Coverage Status
Change from base Build 8144782269: 0.02%
Covered Lines: 59116
Relevant Lines: 66200

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Certainly the symmetry of this feels more correct, given the structure of $U_d$. I scanned through https://arxiv.org/abs/1811.12926 and couldn't immediately see any justification for the approximation, and I didn't bother to attempt the maths myself right now - does anybody have the justification more immediately to hand?

mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Mar 6, 2024
This commit fixes a typo the formula in the function.
This is the same fix from Qiskit#11953.

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Ha - I guess you edited the top comment while I was writing my own! Thanks Shelly.

@jakelishman jakelishman added this pull request to the merge queue Mar 6, 2024
@jakelishman jakelishman added Changelog: None Do not include in changelog mod: transpiler Issues and PRs related to Transpiler labels Mar 6, 2024
@jakelishman
Copy link
Member

@Mergifyio backport stable/0.46 stable/1.0

@jakelishman jakelishman added this to the 1.0.2 milestone Mar 6, 2024
Copy link
Contributor

mergify bot commented Mar 6, 2024

backport stable/0.46 stable/1.0

✅ Backports have been created

Merged via the queue into Qiskit:main with commit 3e7f8b8 Mar 6, 2024
12 checks passed
mergify bot pushed a commit that referenced this pull request Mar 6, 2024
(cherry picked from commit 3e7f8b8)
mergify bot pushed a commit that referenced this pull request Mar 6, 2024
(cherry picked from commit 3e7f8b8)
github-merge-queue bot pushed a commit that referenced this pull request Mar 6, 2024
(cherry picked from commit 3e7f8b8)

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Mar 6, 2024
(cherry picked from commit 3e7f8b8)

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Mar 11, 2024
This commit fixes a typo the formula in the function.
This is the same fix from Qiskit#11953.

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Mar 11, 2024
This commit fixes a typo the formula in the function.
This is the same fix from Qiskit#11953.

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
IsmaelCesar pushed a commit to comp-quantica/qiskit-terra that referenced this pull request Mar 13, 2024
github-merge-queue bot pushed a commit that referenced this pull request Mar 14, 2024
* Oxidize TwoQubitWeylDecomposition

This commit is part 1 of migrating the default 2q unitary synthesis to leverage
parallel rust described in #8774, the eventual goal is to be able to
run unitary synthesis in parallel for all the unitary matrices in a
circuit in a single call from the `UnitarySynthesis` pass. This commit
lays the initial groundwork for doing this by starting with the largest
piece of the default 2q unitary synthesis code, the
TwoQubitWeylDecomposition class. It migrates the entire class
to be a pyclass in rust. There is still a Python subclass for it that
handles the actual QuantumCircuit generation and also the string
representations which are dependent on circuit generation. The goal of
this is to keep the same basic algorithm in place but re-implement
as-is in Rust as a common starting point for eventual improvements to
the underlying algorithm as well as parallelizing the synthesis of
multiple 2q unitary matrices.

* Fix typo in closest_partial_swap()

This commit fixes a typo the formula in the function.
This is the same fix from #11953.

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>

* Run black and lint

* Fix potential imaginary component sign flip in determinant

* Run cargo fmt

* Simplify using numpy eigh example comment

* Add missing checks to decompose_two_qubit_product_gate()

* Use rng first trial from Python implementation

To aid in debugging and rule out rng differences causing different
results this commit switches the first iteration of the randomized loop
to have hard coded values that are identical to what the rng in numpy
was returning. It is very unlikely that this will have any impact
because the specific random numbers used shouldn't matter, this is
mostly to just rule it out as a possibility in debugging the remaining
test failures.

* Fix whitespace in error message

* Fix assert check

* Fix missing multiplier on specialized weyl gate

* Fix various mistakes

This commit fixes two fundamental issues in the code. The first is the
rz and ry matrix were being incorrectly constructed for a given angle.
This caused the specializations that were computing the 1q matrices in
the decomposition based on a product with these gates' matrices to
return invalid results. The second issue is for the MirrorControlledEquiv
specialization had the angles backwards for computing the matrix of the
rz gates used in the products for the 1q matrices:

`K1l = K1l @ Rz(K1r)` and `K1r = K1r @ Rz(K1l)` not
`K1l = K1l @ Rz(K1l)` and `K1r = K1r @ Rz(K1r)`

This was a typo from the original transcription.

* Add pickle serialization support for TwoQubitWeylDecomposition

* Remove duplicate conjs increment

* Fix fSim abmb equivalent specialization

* Add specialized test class back

* Use QiskitError for backwards compatibility

* Add release note

* Make explicit specialization private

* Use explicit inheritance from general decomposition (#23)

* Apply suggestions from code review

* Use smallvec for circuit sequence params and qubits

* Use const 2x2 identity array where possible

* circuit() and weyl_gate don't need a mutable self

* Remove unnecessary inline annotations

* Rename Specializations enum Specialization

* Add back specialize() method and deprecate

* Reorganize Python/Rust split to wrap rust instead of subclass

This commit reworks the handoff between python and rust space for the
TwoQubitWeylDecomposition class. Previously the Python side
TwoQubitWeylDecomposition was a subclass of the Rust struct/pyclass of
the same name. This was originally done to deduplicate the the getters
for the attributes. However, because of the overhead associated with
some of the rust getters and needing to do some import normalization to
a numpy array the deduplication wasn't worth the cost.

* Remove unecessary allocations

* Rename DEFAULT_ATOL to ANGLE_ZERO_EPSILON

* Stop obsessing over -0

* Handle enum to int conversion as method

* Cleanup decompose_two_qubit_product_gate()

* Use a trait for trace_to_fid()

* Use an enum instead of string for euler basis

* Fix release note typo

* Improve magic basis transformation functions

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* Remove eigh() util function

* Revert unecessary changes to callers of TwoQubitWeylDecomposition

* Restore debug logging and add test assertions for it

* Update qiskit/synthesis/two_qubit/two_qubit_decompose.py

Co-authored-by: Lev Bishop <18673315+levbishop@users.noreply.github.com>

* Add specialization to __str__

* Add previous specialized class docstrings as inline rust code comments

* Rename fSim variants and suprress rustc warning about camel case

* Update tests for correct specialization enum name

* Expose specialization enum via private class attr and use for __repr__

---------

Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Lev Bishop <18673315+levbishop@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: transpiler Issues and PRs related to Transpiler synthesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants