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

Added fix for two-qubit custom gates and Added new conversion for SU4 gates #14

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Shiro-Raven
Copy link

Description

During a QML experiment, it was noted that the experiment was producing bad results due to the faulty conversion of custom gates in the Qulacs simulator, since the experiment was working fine when using the SymbolicSimulator. The reason turned out to be that the custom gate matrix not permuted properly along with the indices as was done already in the conversion. The implemented solution, which only works for two-qubit gates, applies "virtual" SWAP gates before and after the gate. This is easily done by the swapping of the second and third rows and columns of the quantum matrix. Of course, this would never work for >3-qubit gates, and so this might need to be revisited later on. (Maybe add a warning for that as well?)

In addition, support for SU4 gates (from orquestra.qml) was added because it is required by an ongoing experiment. It reuses the conversions of U3, XX, YY, and ZZ gates. An issues was testing. Since it's not efficient to include qml-core as a dev dependency, I opted for copying the original code, simplifying it, and using that for the tests.

Please verify that you have completed the following steps

  • I have self-reviewed my code.
  • I have included test cases validating introduced feature/fix.
  • I have updated documentation.

@codecov-commenter
Copy link

codecov-commenter commented Dec 25, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (e2271fe) 89.13% compared to head (eb40b3e) 85.84%.

Files Patch % Lines
src/orquestra/integrations/qulacs/conversions.py 64.70% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
- Coverage   89.13%   85.84%   -3.29%     
==========================================
  Files           2        2              
  Lines          92      106      +14     
==========================================
+ Hits           82       91       +9     
- Misses         10       15       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@max-radin max-radin 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 sorting this out Ahmed! A couple comments/questions:

  1. Can the SU(4) gate from orquestra.qml be handled by _custom_qulacs_gate now that the permutation issue is fixed? If so, I think we would not need to add SU(4) as a special case to the qulacs integration.
  2. It looks like the new test cases for permutation correctness and handling the SU(4) gate have hard coded in a bunch of numeric values, which makes it tricky to see what exactly the test is checking and whether the target wavefunction is correct. Would it be hard to come up some simpler test cases that still check the relevant behavior? Or alternatively, to include the code that generated the circuit parameters and target wavefunctions?
  3. Now that some of the test cases fortest_get_wavefunction_works_with_multiphase_operator don't use the multiphase operator, this function should be renamed.

@AthenaCaesura
Copy link
Contributor

@Shiro-Raven Hey there! Just checking in to see if we're planning to keep working on this. If not, I might close the PR for now to stop the daily GitHub reminders. Let me know what you think. 😅

@max-radin max-radin removed the request for review from AthenaCaesura February 1, 2024 15:24
@max-radin
Copy link
Contributor

@AthenaCaesura I removed you from requested reviewers, which I think will stop the daily reminders.

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.

4 participants