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 314 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

Related GitHub Issues:
[sc-73324]

@JerryChen97 JerryChen97 requested a review from mudit2812 January 3, 2025 15:44
@JerryChen97 JerryChen97 added the do not merge ⚠️ Do not merge the pull request until this label is removed label Jan 3, 2025
@JerryChen97
Copy link
Contributor Author

Let's merge this after the v0.40 release is live

Comment on lines +730 to +732
# Validate Hermiticity
if not math.allclose(density_matrix, math.conjugate(math.transpose(density_matrix))):
raise ValueError("Density matrix must be Hermitian.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for missing this earlier, but this seems like a check that should be performed in the initialization of QubitDensityMatrix rather than here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge ⚠️ Do not merge the pull request until this label is removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants