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

Integration into the current PL device ecosys #6684

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

Conversation

JerryChen97
Copy link
Contributor

@JerryChen97 JerryChen97 commented Dec 6, 2024

Context:
We finished all the necessary components of the new API interface of default_mixed. However, since this is an internal change, which involves many different files and paths, we would like to have one more round of check, success and merge of which should concludes the whole epic.

Description of the Change:

  • DefaultMixedLegacy removed! keep DefaultMixed, but rename it to DefaultMixedLegacy (note: still the legacy one will be purged before this PR merged into master; it's kept right now due to great help in debug)
  • rename DefaultMixedNewAPI to DefaultMixed
  • a previous TODO: renaming operations_mixed back to operations, and copy it to DefaultMixedLegacy
  • add a intermediate step to apply readout_error just as BitFlip with arbitrary input error channels
  • remove redundant measure process functions
  • add an IntegrationTest for our new DefaultMixed
  • modify all the device tests in tests/devices accordingly. Basically the tests/devices/test_default_mixed*.py Deleted legacy specified device tests. These should be covered in the integration test suite mentioned above
  • if no errors come up, then separate the legacy code into another file Lots of errors, see drawback section for a record along with updates.
  • some meaningless tests were deleted:
    • all the legacy-specific tests
    • some tests that appear to be all-device, but actually skip all the other dev but legacy default mixed (e.g. tests in test_return_types_qnode
  • with completed PL package, test against all qml demos. REQUIREMENT: literally nothing should be modified for any downstreaming applications, except for few necessary breaking
    • After search we found the following 9 demos explicitly using default.mixed
    • tutorial_noisy_circuits.py the usage of dev._state needs to be removed and may be replaced by equivalent or not. Sol: had a PR to improve this line
    • tutorial_error_mitigation.py other irrelavant breaks involved (removal of top-level access to QubitStateVec) (!Note: to reproduce this one has to install the latest version of pennylane qiskit via pip install git+https://github.com/PennyLaneAI/pennylane-qiskit.git@master)
    • !The following two demos are super heavy and resource consuming.

some by-the-way improvement:

  • applied the new get_canonical_interface_name and removed the hardcoded dictionary mimic of enum.
  • aligned the implementation of qubit_mixed much more with qubit module

Benefits:

  • Legacy code was preserved for reference purpose as well as catering for potential users
  • Better separation between new interface and legacy
  • Maintained the functionalities from demos
  • Device default.mixed is ported directly with our new API.

Possible Drawbacks:

  • Some advanced users that involved the src code deep within legacy default_mixed might find it annoying for a while. However, we would include a direct indication in changelog as well as the new class.
  • Fixed unexpected bug 1: finite-diff support for PurityMP on torch, tf, and jax down
  • Fixed unexpected bug 2: gradient calculation at PhaseFlip(0) breaks with nan returned at initial state |0> (all good for other other channels or other state with PhaseFlip`
  • Fixed. expected bug 3: classical shadow is down for most of tests. This is due to the fact that the implementation is hidden inside QubitDevice which was missed out before. Need to be fixed asap

The drop of legacy device might introduce some missing in related code coverage. For visibility, we track them as todos here as well.

  • ClassicalShadow related missing: the entire ClassicalShadowMP.process() method; shadow_expval branch in _qubit_device.py
  • (coverage affected files: single_dispatch and mutliple_dispatch) scatter related missing: this is suspicious since it might imply that some functinoalities were lost. nothing has been lost. The legacy code that use scatter was for initializing states in a bruteforce way, which is not needed anymore.

Related GitHub Issues:
[sc-73324]

JerryChen97 and others added 30 commits December 3, 2024 15:32
This reverts commit a776e59c5bb6435bdac71f644db22afc8603bab9.
@JerryChen97
Copy link
Contributor Author

Comments for apply_operation docs:
Due to the singledispatch, the docs for apply_operation look really weird: image
We can fix this by using a similar strategy to devices.qubit.apply_operation, which calls an internal apply_operation_default method. This apply_operation_default method is what gets decorated with singledispatch, so we don't get the weird doc rendering.

Still hard to understand why this happend though, because the dispatch strategy in default.mixed is exactly the same as default.qubit. From the day one of implementing it I didn't want anything to be wrong so just faithfully copy paste the code structure all along the way

Oh I think I got it. By counting numbers it's clear that the number of weird apply_operation doesn't match the actual registers. So it should be something else. Second lookup I foudn that the number matches the symmetric ops dispatch...

@mudit2812 fixed with a super nasty hack at 6caf6e1 hope you don't mind 😂 it's a very rare time that I miss those days of writing in Julia

@JerryChen97
Copy link
Contributor Author

Another thing I found. The Qubit mixed-state simulation tools heading in the qml.devices docs is not showing all functions. Additionally, sampling should not be in the docs at all since that is a submodule, not a function/class. image

fixed 3baccc4

@JerryChen97
Copy link
Contributor Author

Now the state() measurement should be functioning as normal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP 🚧 Work-in-progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants