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 spin_op multiplication. #2292

Merged
merged 5 commits into from
Oct 22, 2024
Merged

Fix spin_op multiplication. #2292

merged 5 commits into from
Oct 22, 2024

Conversation

boschmitt
Copy link
Collaborator

Description

The spin operator class, spin_op, gives wrong results when multiplying. The following output demonstrates that how it gets wrong the multiplication of single-qubit, single-term spin operators:

**********************************************************
Testing 1 qubits
**********************************************************
I * I = I == I [OK]
I * X = X == X [OK]
I * Y = Y == Y [OK]
I * Z = Z == Z [OK]
X * I = X == X [OK]
X * X = I == I [OK]
X * Y = iZ == iZ [OK]
X * Z = -iY == -iY [OK]
Y * I = Y == Y [OK]
Y * X = -iZ != iZ [FAILURE]
  [Coefficient error] got: (0,1) expected: (0,-1)
  Sanity check:
    [q0] Y * X = -iZ

    Expression: (-iZ) = -iZ
Y * Y = I == I [OK]
Y * Z = iX == iX [OK]
Z * I = Z == Z [OK]
Z * X = iY != -iY [FAILURE]
  [Coefficient error] got: (0,-1) expected: (0,1)
  Sanity check:
    [q0] Z * X = iY

    Expression: (iY) = iY
Z * Y = -iX != iX [FAILURE]
  [Coefficient error] got: (0,1) expected: (0,-1)
  Sanity check:
    [q0] Z * Y = -iX

    Expression: (-iX) = -iX
Z * Z = I == I [OK]

This PR fixes the issue, adds more comprehensive testing, and simplify the logic behind doing the cartesian product of the terms of two spin_op objects, which shows better performance on some tests (YMMV).

Copy link

copy-pr-bot bot commented Oct 17, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@boschmitt
Copy link
Collaborator Author

boschmitt commented Oct 17, 2024

/ok to test

Command Bot: Processing...

@boschmitt
Copy link
Collaborator Author

boschmitt commented Oct 17, 2024

/ok to test

Command Bot: Processing...

@boschmitt boschmitt force-pushed the fix_spin branch 3 times, most recently from 9a86136 to 0abd709 Compare October 17, 2024 18:38
@boschmitt boschmitt marked this pull request as ready for review October 17, 2024 19:35
@sacpis
Copy link
Collaborator

sacpis commented Oct 21, 2024

Thanks @boschmitt. LGTM!

@boschmitt boschmitt force-pushed the fix_spin branch 2 times, most recently from fdac944 to 7cc06c1 Compare October 22, 2024 13:25
@amccaskey
Copy link
Collaborator

amccaskey commented Oct 22, 2024

/ok to test

Command Bot: Processing...

@amccaskey amccaskey merged commit 9ccd598 into NVIDIA:main Oct 22, 2024
132 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants