-
Notifications
You must be signed in to change notification settings - Fork 603
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
qinfo
module deprecations and removals
#5911
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5911 +/- ##
=======================================
Coverage 99.58% 99.59%
=======================================
Files 443 444 +1
Lines 42273 42325 +52
=======================================
+ Hits 42096 42152 +56
+ Misses 177 173 -4 ☔ View full report in Codecov by Sentry. |
**Context:** https://app.shortcut.com/xanaduai/story/66713/deprecate-qml-qinfo-transforms-mutual-info?vc_group_by=day&ct_workflow=all&cf_workflow=500000005 **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:**
**Context:** https://app.shortcut.com/xanaduai/story/66716/deprecate-qml-qinfo-transforms-vn-entropy **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:**
**Context:** https://app.shortcut.com/xanaduai/story/66714/deprecate-qml-qinfo-transforms-purity?vc_group_by=day&ct_workflow=all&cf_workflow=500000005 **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:**
**Context:** https://app.shortcut.com/xanaduai/story/67446/deprecate-qml-qinfo-transforms-vn-entanglement-entropy **Description of the Change:** Deprecate `qinfo.vn_entanglement_entropy`, add a `vn_entanglement_entropy` MP **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:**
…py` (#5915) **Context:** https://app.shortcut.com/xanaduai/story/66715/deprecate-qml-qinfo-transforms-reduced-dm?vc_group_by=day&ct_workflow=all&cf_workflow=500000005 https://app.shortcut.com/xanaduai/story/67663/deprecate-qml-qinfo-fidelity **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:**
Fixes recent failures with legacy opmath.
**Context:** Part of the ongoing efforts to localize and isolate the impact of legacy devices. **Description of the Change:** - Moved all of `_qubit_device`, `_qutrit_device` and `_device` files to the `devices` module. - Disentangled `DeviceError` and the `_device` module to avoid messy circular imports. The Exception lives separately in the top-level `__init__` file now. - Changed import behaviour of legacy devices from `pennylane` module to happen through `__getattr__`. This will help upcoming deprecation efforts by not making them visible through an IDE's suggestion and allowing a more programmatic handling of the import. **Benefits:** More localized class structure. [[sc-66007](https://app.shortcut.com/xanaduai/story/66007)]
**Context:** `qml.pauli.group_observables` has several areas of improvement that make the calculation slow. This PR attempts to address some of them. **Description of the Change:** 1. Solve the Graph colouring algorithm using `Rustworkx` instead of custom implementation. This adds 2 additional methods to solve the Minimum Clique cover problem: DSATUR (`'dsatur'`) and IndependentSet (`'gis'`) 2. Use the symplectic representation of the Pauli observables to construct the adjacency matrix of the complement graph. 3. Introduce a new function to obtain the indices of the partitions directly: `qml.pauli.compute_partition_indices` **Benefits:** Improves of orders of magnitude compared to the current implementation of the `qwc` grouping type strategy. The current implementation is based on an $\mathcal{O}(m^2)$ computation, with $m$ the number of observables to be grouped. Instead, taking advantage of the symplectic inner product, and its relation with the commutator and anti commutator of Pauli observables [1], we can obtain a significant improvement. ![image](https://github.com/user-attachments/assets/3f0ec70b-2082-44a3-acf9-9cdf4238da08) In addition, by introducing `qml.pauli.compute_partition_indices`, we now avoid the (rather often) inefficient computation of partitions of observables, just to then calculate the indices from them - see https://github.com/PennyLaneAI/pennylane/blob/2892a9a0aa6797912ef4a03f3c4759eaff01d8ef/pennylane/ops/qubit/hamiltonian.py#L37 Instead, we obtain the indices of the partitions directly from the graph colouring algorithm. Putting all together, the improvement in performance when calculating the partitions of large Hamiltonians is evident. ![image](https://github.com/user-attachments/assets/7bd047a9-a628-46c8-9d3e-58818fd7acc0) This graph was obtained by running ``` python %timeit hamiltonian.compute_grouping(grouping_type="qwc", method='lf') ``` **Notes:** Profiling the implementation from `linear_combination` demonstrates that the post processing to obtain the indices remains a significant burden in the calculations, and therefore should be addressed for the remaining functions - see reference code above. ![image](https://github.com/user-attachments/assets/09cf4ca6-601a-4e91-8865-8bf727dd3f1d) [1] Andrew Jena (2019). Partitioning Pauli Operators: in Theory and in Practice. UWSpace. http://hdl.handle.net/10012/15017 [sc-64594] ## Performance comparisons between colouring algorithms Comparison for `LinearCombination.compute_grouping()` ![image](https://github.com/user-attachments/assets/042d040a-f75b-4642-b6e4-0e903c5d58c5) ![image](https://github.com/user-attachments/assets/a89197ee-9c3d-424d-9bba-36829ee33388) Comparison for `colour_paui_graph` (only between `Rustworkx` algorithms) ![image](https://github.com/user-attachments/assets/52ae4d0f-acaa-4d45-aab5-d3c40c37863a) --------- Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
…ode/execute functions (#6046) **Context:** With the `LegacyDeviceFacade` now in place, we can add automatic wrapping of legacy devices. **Description of the Change:** Add automatic wrapping to `qml.device`, `qml.execute`, `QNode` constructor, and the `get_best_method` and `best_method_str` functions of the QNode class. The tests are also updated accordingly. **Benefits:** Users no longer need to worry about upgrading their devices to the new Device API and can use the facade to access the basic functions of the new API. **Possible Drawbacks:** The facade doesn't yet provide all potential advantages of fully upgrading to the new API [[sc-65998](https://app.shortcut.com/xanaduai/story/65998)] --------- Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai> Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: David Wierichs <david.wierichs@xanadu.ai> Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com> Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
A follow up of #6252, does the same but with a different test.
[sc-72795] --------- Co-authored-by: Pietropaolo Frisoni <pietropaolo.frisoni@xanadu.ai>
**Context:** `qml.Device`, `qml.QubitDevice`, and `qml.QutritDevice` all reflect the legacy device interface, which is no longer the recommended way of creating devices. **Description of the Change:** Deprecate top level access to the `Device`, `QubitDevice`, and `QutritDevice`. **Benefits:** Further isolation of the legacy device interface. **Possible Drawbacks:** All deprecations propagate through the ecosystem and can cause issues. **Related GitHub Issues:** [sc-71519] --------- Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
…jacobian` (#6134) **Context:** #6120 and #6127 add support to capture `qml.grad` and `qml.jacobian` in plxpr. Once captured, they dispatch to `jax.grad` and `jax.jacobian`. **Description of the Change:** This PR adds support for pytree inputs and outputs of the differentiated functions, similar to #6081. For this, it extends the internal class `FlatFn` by the extra functionality to turn the wrapper into a `*flat_args -> *flat_outputs` function, instead of a `*pytree_args -> *flat_outputs` function. **Benefits:** Pytree support 🌳 **Possible Drawbacks:** **Related GitHub Issues:** [sc-70930] [sc-71862] --------- Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
**Context:** We want to make Pennylane compatible with Numpy 2.0. After several discussions, we decided to test NumPy 2.0 on the CI by default in every PR (testing both Python versions would have been to slow). Some jobs still downgrade automatically to Numpy 1.x, since some interfaces (such as Tensorflow) still do not support NumPy 2.0. **Description of the Change:** We can distinguish the changes into 3 main categories: *Changes to workflows* - None in the final version *Changes to requirements and setup files* - Unpin the Numpy version in `setup.py` (now we also allow Numpy 2.0). - Update `requirements-ci.txt` to include Scipy 1.13 (this adds support for Numpy 2.0). - Pin Numpy in `requirements-ci.txt` to 2.0. *Changes to the source code* - Change `np.NaN` to `np.nan`. - Use legacy printing representation in tests, contrary to the new numpy representation of scalars, e.g. np.float64(3.0) rather than just 3.0. - Update probabilities warning to be case insensitive and check for a partial match, since this warning was changed in Numpy 2.0. - Check the datatype of np.exp from the Global phase only for Numpy 1.x, since this gets promoted to complex128 in Numpy 2.x. https://numpy.org/neps/nep-0050-scalar-promotion.html#schema-of-the-new-proposed-promotion-rules. **Benefits:** Make Pennylane compatible with Numpy 2.0. **Possible Drawbacks:** - We need to create a separate workflow to keep testing PennyLane with NumPy 1.x, since we still want to maintain compatibility with previous NumPy versions. This will be done in a separate PR. - We are not testing Numpy 2.x for the interfaces that implicitly require Numpy 1.x. These currently seem to be `tensorflow` and `openfermionpyscf` (notice that `tensorflow` is required in some code sections like qcut). In particular, `openfermionpyscf` causes an error: ``` AttributeError: np.string_ was removed in the NumPy 2.0 release. Use np.bytes_ instead. ``` in the qchem tests. The attribute `np.string_` is not used in the PL source code, so it is a problem with the package itself. [sc-61399] [sc-66548] --------- Co-authored-by: PietropaoloFrisoni <pietropaolo.frisoni@xanadu.ai> Co-authored-by: Pietropaolo Frisoni <pietropfrisoni@gmail.com>
Regarding `numpy` and `autograd`: - When the parameters are of the `numpy` interface, internally treat it as `interface=None`. - Does not change the behaviour of treating user specified `interface="numpy"` as using autograd. Regarding interfaces in general: - The set of canonical interface names in `INTERFACE_MAP` is expanded to include more specific names such as `jax-jit`, and `tf-autograph`. `_convert_to_interfaces` in `qnode.py` uses a separate `interface_conversion_map` to further map the specific interfaces to their corresponding general interface names that can be passed to the `like` argument of `qml.math.asarray` (e.g. "tf" to "tensorflow", "jax-jit" to "jax"). - In `QNode` and `qml.execute`, every time we get an interface from user input or `qml.math.get_interface`, we map it to a canonical interface name using `INTERFACE_MAP`. Aside from these two scenarios, we assume that the interface name is one of the canonical interface names everywhere else. `QNode.interface` is now assumed to be one of the canonical interface names. - User input of `interface=None` gets mapped to `numpy` immediately. Internally, `QNode.interface` will never be `None`. It'll be `numpy` for having no interface. - If `qml.math.get_interface` returns `numpy`, we do not map it to anything. We keep `numpy`. Collateral bug fix included as well: - Fixes a bug where a circuit of the `autograd` interfaces sometimes returns results that are not `autograd`. - Adds `compute_sparse_matrix` to `Hermitian` [sc-73144] --------- Co-authored-by: Christina Lee <christina@xanadu.ai>
**Context:** We want to make PL compatible with torch 2.3.0 (including GPU tests) after updating Numpy from 1.x to 2.x. **Description of the Change:** As above. **Benefits:** We are sure that PL is compatible with torch 2.3.0. **Possible Drawbacks:** None that I can think of right now. **Related GitHub Issues:** None. **Related Shortcut Stories:** [sc-61391]
astralcai
reviewed
Sep 16, 2024
PietropaoloFrisoni
approved these changes
Sep 16, 2024
Co-authored-by: Pietropaolo Frisoni <pietropaolo.frisoni@xanadu.ai>
mudit2812
requested review from
astralcai
and removed request for
astralcai
September 16, 2024 19:58
astralcai
approved these changes
Sep 17, 2024
mudit2812
added a commit
that referenced
this pull request
Sep 18, 2024
**Context:** As part of our v0.39 deprecation cycle, `qinfo` will be deprecated. All PRs for deprecating each function can be merged to here, **Description of the Change:** Deprecates `qinfo`. Specifically: - [x] deprecate `qinfo.mutual_info`: #5917 - [x] deprecate `qinfo.reduced_dm`: #5915 - [x] deprecate `qinfo.purity`: #5916 - [x] deprecate `qinfo.vn_entropy`: #5912 - [x] deprecate `qinfo.vn_entanglement_entropy` #5914 - [x] deprecate `qinfo.fidelity`: #5915 - [x] deprecate `qinfo.relative_entropy`: #5915 - [x] deprecate `qinfo.trace_distance` - [x] remove `qinfo.classical_fisher` - [x] remove `qinfo.quantum_fisher` **Benefits:** Desired UI and less redundancies. **Possible Drawbacks:** None **Related GitHub Issues:** [sc-67217] [sc-67216] [sc-66716] [sc-66715] [sc-66714] [sc-66713] [sc-67664] [sc-67665] [sc-67663] [sc-67446] --------- Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai> Co-authored-by: Astral Cai <astral.cai@xanadu.ai> Co-authored-by: Ahmed Darwish <exclass9.24@gmail.com> Co-authored-by: Cristian Emiliano Godinez Ramirez <57567043+EmilianoG-byte@users.noreply.github.com> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: David Wierichs <david.wierichs@xanadu.ai> Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com> Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com> Co-authored-by: Tonmoy Bhattacharya <ultraton_16@yahoo.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Vincent Michaud-Rioux <vincent.michaud-rioux@xanadu.ai> Co-authored-by: Matthew Silverman <matthews@xanadu.ai> Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com> Co-authored-by: Utkarsh <utkarshazad98@gmail.com> Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com> Co-authored-by: Romain Moyard <rmoyard@gmail.com> Co-authored-by: Diksha Dhawan <40900030+ddhawan11@users.noreply.github.com> Co-authored-by: soranjh <soran.jahangiri@gmail.com> Co-authored-by: Jorge J. Martínez de Lejarza <61199780+gmlejarza@users.noreply.github.com> Co-authored-by: anthayes92 <34694788+anthayes92@users.noreply.github.com> Co-authored-by: Alex Preciado <alex.preciado@xanadu.ai> Co-authored-by: Mikhail Andrenkov <mikhail@xanadu.ai> Co-authored-by: Jack Brown <jack@xanadu.ai> Co-authored-by: Austin Huang <65315367+austingmhuang@users.noreply.github.com> Co-authored-by: Pietropaolo Frisoni <pietropaolo.frisoni@xanadu.ai> Co-authored-by: Justin Pickering <79890410+justinpickering@users.noreply.github.com> Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com> Co-authored-by: Will <wmaxwell90@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Lee James O'Riordan <mlxd@users.noreply.github.com> Co-authored-by: Pietropaolo Frisoni <pietropfrisoni@gmail.com>
mudit2812
added a commit
that referenced
this pull request
Sep 23, 2024
**Context:** As part of our v0.39 deprecation cycle, `qinfo` will be deprecated. All PRs for deprecating each function can be merged to here, **Description of the Change:** Deprecates `qinfo`. Specifically: - [x] deprecate `qinfo.mutual_info`: #5917 - [x] deprecate `qinfo.reduced_dm`: #5915 - [x] deprecate `qinfo.purity`: #5916 - [x] deprecate `qinfo.vn_entropy`: #5912 - [x] deprecate `qinfo.vn_entanglement_entropy` #5914 - [x] deprecate `qinfo.fidelity`: #5915 - [x] deprecate `qinfo.relative_entropy`: #5915 - [x] deprecate `qinfo.trace_distance` - [x] remove `qinfo.classical_fisher` - [x] remove `qinfo.quantum_fisher` **Benefits:** Desired UI and less redundancies. **Possible Drawbacks:** None **Related GitHub Issues:** [sc-67217] [sc-67216] [sc-66716] [sc-66715] [sc-66714] [sc-66713] [sc-67664] [sc-67665] [sc-67663] [sc-67446] --------- Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai> Co-authored-by: Astral Cai <astral.cai@xanadu.ai> Co-authored-by: Ahmed Darwish <exclass9.24@gmail.com> Co-authored-by: Cristian Emiliano Godinez Ramirez <57567043+EmilianoG-byte@users.noreply.github.com> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Co-authored-by: albi3ro <chrissie.c.l@gmail.com> Co-authored-by: Christina Lee <christina@xanadu.ai> Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: David Wierichs <david.wierichs@xanadu.ai> Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com> Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com> Co-authored-by: Tonmoy Bhattacharya <ultraton_16@yahoo.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Vincent Michaud-Rioux <vincent.michaud-rioux@xanadu.ai> Co-authored-by: Matthew Silverman <matthews@xanadu.ai> Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com> Co-authored-by: Utkarsh <utkarshazad98@gmail.com> Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com> Co-authored-by: Romain Moyard <rmoyard@gmail.com> Co-authored-by: Diksha Dhawan <40900030+ddhawan11@users.noreply.github.com> Co-authored-by: soranjh <soran.jahangiri@gmail.com> Co-authored-by: Jorge J. Martínez de Lejarza <61199780+gmlejarza@users.noreply.github.com> Co-authored-by: anthayes92 <34694788+anthayes92@users.noreply.github.com> Co-authored-by: Alex Preciado <alex.preciado@xanadu.ai> Co-authored-by: Mikhail Andrenkov <mikhail@xanadu.ai> Co-authored-by: Jack Brown <jack@xanadu.ai> Co-authored-by: Austin Huang <65315367+austingmhuang@users.noreply.github.com> Co-authored-by: Pietropaolo Frisoni <pietropaolo.frisoni@xanadu.ai> Co-authored-by: Justin Pickering <79890410+justinpickering@users.noreply.github.com> Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com> Co-authored-by: Will <wmaxwell90@gmail.com> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: Lee James O'Riordan <mlxd@users.noreply.github.com> Co-authored-by: Pietropaolo Frisoni <pietropfrisoni@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context:
As part of our v0.39 deprecation cycle,
qinfo
will be deprecated. All PRs for deprecating each function can be merged to here,Description of the Change:
Deprecates
qinfo
. Specifically:qinfo.mutual_info
: Deprecateqinfo.mutual_info
#5917qinfo.reduced_dm
: Deprecateqinfo.reduced_dm
,qinfo.fidelity
,qinfo.relative_entropy
#5915qinfo.purity
: Deprecateqinfo.purity
#5916qinfo.vn_entropy
: Deprecateqinfo.vn_entropy
#5912qinfo.vn_entanglement_entropy
Deprecateqinfo.vn_entanglement_entropy
#5914qinfo.fidelity
: Deprecateqinfo.reduced_dm
,qinfo.fidelity
,qinfo.relative_entropy
#5915qinfo.relative_entropy
: Deprecateqinfo.reduced_dm
,qinfo.fidelity
,qinfo.relative_entropy
#5915qinfo.trace_distance
qinfo.classical_fisher
qinfo.quantum_fisher
Benefits:
Desired UI and less redundancies.
Possible Drawbacks:
None
Related GitHub Issues:
[sc-67217] [sc-67216] [sc-66716] [sc-66715] [sc-66714] [sc-66713] [sc-67664] [sc-67665] [sc-67663] [sc-67446]