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 VnEntanglementEntropyMP measurement process #6270

Merged
merged 153 commits into from
Sep 19, 2024
Merged

Conversation

mudit2812
Copy link
Contributor

@mudit2812 mudit2812 commented Sep 13, 2024

Context:
With the qinfo deprecations in progress, it makes sense to have users still be able to easily access the VN entanglement entropy.

Description of the Change:
Add a VnEntanglementEntropyMP and associated qml.vn_entanglement_entropy function

Benefits:

Possible Drawbacks:

Related GitHub Issues:

isaacdevlugt and others added 30 commits June 28, 2024 11:45
**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:**
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 <[email protected]>
…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 <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: Thomas R. Bromley <[email protected]>
Co-authored-by: Korbinian Kottmann <[email protected]>
…\test_pytrees.py, fixes #6083 (#6107)

**Context:**
Add is_leaf argument to pytrees\pytrees.py with test at
tests\pytrees\test_pytrees.py
fixes #6083 

**Description of the Change:**
Added is_leaf argument to the function pytrees\pytrees.py. Should this
argument evaluate to True then no fufther flattening will be done.
Added test to tests\pytrees\test_pytrees.py, with function
test_flatten_is_leaf() having two test cases.
Added changelog with file \doc\releases\changelog-0.38.0.md

**Benefits:**
argument added to the function flatten which acts as a control mechanism
to designate a node as leaf node even if that node could be further
flattened, e.g., the node is a tuple.

**Possible Drawbacks:**

**Related GitHub Issues:**
Fixes #6083 

**Related Shortcut Stories:**
[sc-70903]

---------

Co-authored-by: Tonmoy Bhattacharya <>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Automatic update of stable requirement files to snapshot valid python
environments.

Because bots are not able to trigger CI on their own, please do so by
pushing an empty commit to this branch using the following command:

```
git commit --allow-empty -m 'trigger ci'
```

Alternatively, wait for this branch to be out-of-date with master, then
just use the "Update branch" button!

Note that it is expected that the PennyLane-Lightning repo is a version
ahead of the release, because the
version number is taken from the dev branch. Trying to `pip install`
from the files will fail until that
major version of Lightning is released. 

If pip install fails with a not found error when installing because of
this, it can be fixed by manually
downgrading the PennyLane-Lightning version number in the file by 1
version and trying again.

---------

Co-authored-by: GitHub Actions Bot <>
Co-authored-by: Christina Lee <[email protected]>
### Before submitting

Please complete the following checklist when submitting a PR:

- [x] 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!

- [x] 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`.

- [x] Ensure that the test suite passes, by running `make test`.

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

- [x] The PennyLane source code conforms to
      [PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
      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:**
The tree-traversal algorithm was first implemented using a recursive
approach for simplicity, but this potentially requires very deep stack
calls for circuits with a lot of MCMs. Tree-traversal could also support
analytic execution, optionally with a probability cutoff to ignore
branches.

**Description of the Change:**
Implement tree-traversal using an iterative approach.
Support `shots=None`.
Some profiling and optimization.

**Benefits:**
Remove system call increasing the default recursion call limit.

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-65241]

---------

Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
**Context:**

`node_count_hint` and `edge_count_hint` are only available on Rustworkx
from version 0.15 onwards.

https://www.rustworkx.org/release_notes.html

**Description of the Change:**

Checks the version of rustworkx, and decides whether to use these
arguments in `rx.Pygraph` or not.

**Benefits:**

Fixes bug with versions of Rustworkx < 0.15.
### Before submitting

Please complete the following checklist when submitting a PR:

- [x] 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!

- [x] 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`.

- [x] Ensure that the test suite passes, by running `make test`.

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

- [x] The PennyLane source code conforms to
      [PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
      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:**
This PR implements the decomposition of zyz for special unitaries with
multiple control wires defined in Lemma 7.9 of
https://arxiv.org/pdf/quant-ph/9503016.

**Benefits:**
Support decomposition of zyz for special unitaries.

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-68471]

---------

Co-authored-by: albi3ro <[email protected]>
Co-authored-by: Cristian Emiliano Godinez Ramirez <[email protected]>
@mudit2812 mudit2812 marked this pull request as ready for review September 18, 2024 17:33
pennylane/devices/_qubit_device.py Outdated Show resolved Hide resolved
pennylane/devices/_qutrit_device.py Outdated Show resolved Hide resolved
@mudit2812
Copy link
Contributor Author

[sc-73936]

@mudit2812 mudit2812 enabled auto-merge (squash) September 19, 2024 19:10
@mudit2812 mudit2812 merged commit e6fe7ea into master Sep 19, 2024
36 of 37 checks passed
@mudit2812 mudit2812 deleted the vn-entanglement-mp branch September 19, 2024 19:34
mudit2812 added a commit that referenced this pull request Sep 23, 2024
**Context:**
With the qinfo deprecations in progress, it makes sense to have users
still be able to easily access the VN entanglement entropy.

**Description of the Change:**
Add a `VnEntanglementEntropyMP` and associated
`qml.vn_entanglement_entropy` function

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**

---------

Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: Isaac De Vlugt <[email protected]>
Co-authored-by: Astral Cai <[email protected]>
Co-authored-by: Ahmed Darwish <[email protected]>
Co-authored-by: Cristian Emiliano Godinez Ramirez <[email protected]>
Co-authored-by: Ali Asadi <[email protected]>
Co-authored-by: albi3ro <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: Thomas R. Bromley <[email protected]>
Co-authored-by: Korbinian Kottmann <[email protected]>
Co-authored-by: Tonmoy Bhattacharya <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Vincent Michaud-Rioux <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Guillermo Alonso-Linaje <[email protected]>
Co-authored-by: Utkarsh <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: Romain Moyard <[email protected]>
Co-authored-by: Diksha Dhawan <[email protected]>
Co-authored-by: soranjh <[email protected]>
Co-authored-by: Jorge J. Martínez de Lejarza <[email protected]>
Co-authored-by: anthayes92 <[email protected]>
Co-authored-by: Alex Preciado <[email protected]>
Co-authored-by: Mikhail Andrenkov <[email protected]>
Co-authored-by: Jack Brown <[email protected]>
Co-authored-by: Austin Huang <[email protected]>
Co-authored-by: Pietropaolo Frisoni <[email protected]>
Co-authored-by: Justin Pickering <[email protected]>
Co-authored-by: lillian542 <[email protected]>
Co-authored-by: Will <[email protected]>
Co-authored-by: Josh Izaac <[email protected]>
Co-authored-by: Lee James O'Riordan <[email protected]>
Co-authored-by: Pietropaolo Frisoni <[email protected]>
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.