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

Add helper func apply_operation for default mixed #6379

Open
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

JerryChen97
Copy link
Contributor

@JerryChen97 JerryChen97 commented Oct 10, 2024

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    test directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the doc/releases/changelog-dev.md file, summarizing the
    change, and including a link back to the PR.

  • The PennyLane source code conforms to
    PEP8 standards.
    We check all of our code against Pylint.
    To lint modified files, simply pip install pylint, and then
    run pylint pennylane/path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context:
Before getting into the implementation of new default_mixed we need to separate most of the useful logics from the older version one. One of the most important things is the apply_operation. Basically, what we want to do is to condensate everything into a new sub-module under qml/devices/qubit_mixed such that previous empirical heuristics regarding how to select between einsum and tensordot can be carried over and wrapped independently.

Description of the Change:
New script containing the helper funcs as described above.

Benefits:
Better modularization. Getting ready for the implementaion of a new default_mixed in the future.

Possible Drawbacks:

Related GitHub Issues:

Related Shortcut Stories
[sc-73319]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@JerryChen97 JerryChen97 self-assigned this Oct 10, 2024
@JerryChen97 JerryChen97 added the WIP 🚧 Work-in-progress label Oct 10, 2024
@JerryChen97 JerryChen97 changed the title Add helper func apply_operation for default mixed [WIP] Add helper func apply_operation for default mixed Oct 10, 2024
@JerryChen97
Copy link
Contributor Author

RN I've done the implementation of both einsum and tensordot.

  • The einsum method is directly adopted from current qutrit mixed module
  • The tensordot method is from the default_mixed but several necessary modifications are applied.

Due to the fact that there are quite some other shortcuting regeisters for many special cases to implement, currently I would like to put this as draft without the full CI. After all the other registers complete I will load the CI along with more tests.

@JerryChen97
Copy link
Contributor Author

In previous devices.default_mixed the apply_operation even includes some state preparation. Apparently this is a wrong scope and i will create another story for this

@JerryChen97
Copy link
Contributor Author

The following methods involve additional stories and will be neglected for now:

  • snapshot: this involves measurement submodule, missing for now
  • evolve: this involves extra refinement over how the odeint can be applied onto a density matrix

@JerryChen97
Copy link
Contributor Author

JerryChen97 commented Oct 16, 2024

I noticed that seemingly we can directly use those from pure states given the fact that the conjugated operator's wire numbers are simply all +num_wires where num_wires can be calculated from the input dm state. Let's say such transformation for operator is Shift, then for real, symmetric op e.g. X and CNOT and so on. As long as the apply method of qubit device is always only involving some local wire order, any real operator with symmetricity (e.g. Grover) should be able to be applied in same way.

@JerryChen97
Copy link
Contributor Author

JerryChen97 commented Oct 17, 2024

More tests to add:

  • identity-like ops
  • batch
  • channels
  • multiCX and Grover of larger sizes (at least 9)

@JerryChen97 JerryChen97 marked this pull request as ready for review October 17, 2024 15:04
@JerryChen97 JerryChen97 changed the title [WIP] Add helper func apply_operation for default mixed Add helper func apply_operation for default mixed Oct 17, 2024
@JerryChen97 JerryChen97 removed the WIP 🚧 Work-in-progress label Oct 17, 2024
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 93.50649% with 15 lines in your changes missing coverage. Please review.

Project coverage is 99.35%. Comparing base (88caa8e) to head (cff4b60).

Files with missing lines Patch % Lines
pennylane/devices/qubit_mixed/apply_operation.py 95.45% 9 Missing ⚠️
pennylane/devices/qubit_mixed/utils.py 80.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6379      +/-   ##
==========================================
- Coverage   99.38%   99.35%   -0.04%     
==========================================
  Files         447      451       +4     
  Lines       42418    42648     +230     
==========================================
+ Hits        42158    42373     +215     
- Misses        260      275      +15     

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

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.

1 participant