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

Take wire ordering in the wires argument to qml.density_matrix into account #4072

Merged
merged 17 commits into from
May 25, 2023

Conversation

dwierichs
Copy link
Contributor

Context:
#878 added the functionality to return reduced density matrices by introducing qml.density_matrix(wires=...) as a return object in a QNode. While the reduction by tracing out the correct wires is respected, the ordering of the given wires is not taken into account.
The following code therefore produces the same result for wires=[0, 1] and wires=[1, 0], although it should differ:

import pennylane as qml

wires = [0, 1]
#wires = [1, 0]
dev = qml.device("default.qubit", wires=2)
@qml.qnode(dev)
def circuit():
    qml.Hadamard(0)
    return qml.density_matrix(wires=wires)

circuit()

Description of the Change:
This PR takes the wire ordering into account as well by applying pennylane.math.matrix_manipulation.py::_permute_dense_matrix to the computed density matrix in pennylane.math.quantum.py::reduced_dm.

In addition, this PR raises an error when broadcasting is detected in reduced_dm, because this is not supported and currently crashes in some cases somewhat incomprehensibly.

Benefits:
Bug fix of the above. Transparency of broadcasting scenario that is not supported anyways.

Possible Drawbacks:

Related GitHub Issues:

@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Merging #4072 (521fa52) into master (8af8514) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #4072      +/-   ##
==========================================
- Coverage   99.77%   99.77%   -0.01%     
==========================================
  Files         340      340              
  Lines       30565    30564       -1     
==========================================
- Hits        30496    30495       -1     
  Misses         69       69              
Impacted Files Coverage Δ
pennylane/math/quantum.py 100.00% <100.00%> (ø)

Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @dwierichs and for the rigorous testing. I have concerns about the condition that checks for broadcasting, but other than that, this looks good!

pennylane/math/quantum.py Outdated Show resolved Hide resolved
@dwierichs dwierichs requested a review from mudit2812 May 15, 2023 07:48
Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

I'm happy to approve this PR in it's current state. One way of avoiding overriding QubitDevice.density_matrix is to check what type of device is being used in QubitDevice.density_matrix itself:

input_is_dm = self.short_name[-5:] == "mixed"
return qml.math.reduced_dm(state, indices=wires, c_dtype=self.C_DTYPE, input_is_dm=input_is_dm)

I'm hopeful this change wouldn't interfere with plugins as I'm not sure if any of the plugin devices support state measurements, but it's probably something that should be checked before my suggested change is potentially implemented.

Copy link
Contributor

@eddddddy eddddddy left a comment

Choose a reason for hiding this comment

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

Looks good @dwierichs, thanks for this 💯

@dwierichs dwierichs requested a review from eddddddy May 19, 2023 08:26
Copy link
Contributor

@eddddddy eddddddy left a comment

Choose a reason for hiding this comment

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

Thanks for separating out the broadcasting logic! Happy to approve now, but this is conditional on @albi3ro's comment being addressed.

@dwierichs
Copy link
Contributor Author

@albi3ro , could you check whether I understood you correctly and implemented the checks you were thinking of? :)

Thanks @eddddddy for the quick reviews and discussions!

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

Looks good to me, and can be merged as is.

@eddddddy eddddddy merged commit f7cc39d into master May 25, 2023
@eddddddy eddddddy deleted the dm-wires branch May 25, 2023 16:58
frederikwilde pushed a commit that referenced this pull request May 25, 2023
…to account (#4072)

* include wire ordering, test for that, raise error for broadcasting, test for that

* reduce

* changelog

* add test for qinfo transform

* more tests for math module

* lint math tests

* lint

* black

* introduce, use and test input_is_dm kwarg to reduced_dm

* tmp

* reverting

* seed fix

---------

Co-authored-by: Edward Jiang <[email protected]>
frederikwilde added a commit that referenced this pull request Aug 15, 2023
* Change seed setting in spsa_grad.

* Update changelog.

* Adapt tests. Note that lots of tests still set a global seed!

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: Christina Lee <[email protected]>

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: Christina Lee <[email protected]>

* use Shots class in gradients module (#4152)

* linting

* add num_copies property to shots

* change gradients to use new Shots class

* fix missing update in vjp

* fix stacking and single-shots in shot_adaptive

* remove unneeded cast to tuple

* type-hints and touch-ups

* code review feedback

* changelog

---------

Co-authored-by: Romain Moyard <[email protected]>

* Qutrit Rotations #2 (TRY) (#2846)

* Adding tests for tensor observables

* Added tests for tensor sample

* Updated tests

* Apply suggestions from code review

* Partition device apply ops test case.

* Run black

* Fix pylint

* Update pennylane/devices/default_qutrit.py

* black and pylint

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_non_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated test_default_qutrit.py

* Updated _apply_tadd documentation

* Added eigvals method for TSWAP

* Reverted TSWAP eigval changes

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Jay Soni <[email protected]>

* Added TSWAP eigvals

* Updated changelog-dev.md to include GellMannObs

* Removed empty file

* Added linting comments

* Updated tests to use gate_data

* Updated test parameter names to be more accurate

* Remove unused file

* Updated GellMannObs doc-string

* Update changelog-dev.md

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Added changes to GellMann to address PR comments

* Updated test

* Reformatting

* Trying out changes to Gell-Mann docstring

* Updated Changelog

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Testing LaTeX align

* Added non-diag tests

* Added diag, complex case for tensor sample

* Added example to doc string

* Fixed label test

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Added tests for controlled qutrit unitary

* Fix broadcasting, finish tests for CQutritUnitary

* Added TRX and created skeleton files

* Adding tests for TRX

* Fixed broadcasting issue in controlled qutrit unitary

* Fixed broadcasting issue with ControlledQutritUnitary

* Fixed broadcasting issue in TRX

* Updated TRX documentation

* Added tests

* Added tests for TRX

* Removed unused imports

* Removed unused imports, linting changes

* Added TRX parameter frequencies

* Updated matrix dtype for TRX generator

* Added test for param frequencies

* Added param-shift capability for qutrit devices

* Updated changelog

* Update changelog

* Added change for TRX generator

* Updated utils.py to support higher dimensions

* Added tests for updated utils.sparse_hamiltonian

* Added Identity as supported obs

* Updated TRX docstring

* Update tests/ops/qutrit/test_qutrit_non_parametric_ops.py

Co-authored-by: Jay Soni <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Jay Soni <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Jay Soni <[email protected]>

* Added ControlledQutritUnitary

* Update changelog-dev.md

* Removed empty files

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated to address PR

* Fixed uncommented lines in test suite

* Added complex values to state

* Updated test_mixed_polarity_controls

* Fixed QutritUnitary._controlled

* Updated test_controlled for matrix ops

* Updated ControlledQutritUnitary._controlled

* Reformatting

* Update pennylane/ops/qutrit/matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated ControlledQutritUnitary and tests

* Addressing PR review

* Updated sparse_hamiltonian, fixed TRX docstring

* Addressing PR review

* Refactoring

* Fixed changelog

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/test_qnode.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Reverted changes to sparse_hamiltonian

* Fixed sparse_hamiltonian test

* Updated changelog

* Updated TRX documentation

* Fixed generator

* Adding levels to sparse_hamiltonian

* Updated test sparse hamiltonian

* Fixed sparse hamiltonian test

* Fixed constant level kwarg

* Updated changelog, added test coverage

* Fixed coverage

* Updated test suite

* Updated files to address PR review

* Updated tests to include subspace error tests

* Added TRX tests for parameter shift

* Update doc/releases/changelog-dev.md

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/utils.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update utils.py to remove trailing whitespace

* Updated to address PR review

* Fixed class/object confusion bug

* Testing changes to adjust lines changed in PR

* Fixing changes

* Fixing changes

* Resetting problem files

* Fixing changes

* updated TRX docs

* Fixed TRX docs

* Updated TRX docs

* Fixed PR too many lines changed issue

* Updated subspace error tests

* Tweaked THadamard docs to fix rendering

* Test dos2unix

* Fixed subspace testing

* Merge changes

* Started adding tests for grad

* Updated tests to parametrize diff-method

* Linted tests

* Fiex tests using in-place inversion

* Added diff tests

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Fixed formatting

* Update pennylane/utils.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated TRY and tests

* Updated utils.py

* Fixed TRX generator

* Updated generator TRY

* Updated subspace validation for TRY

* Updated subspace validation

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Christina Lee <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Matthew Silverman <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Matthew Silverman <[email protected]>

* Reverted `validate_subspace` changes

* Updated test

* Added parameter shift test

* Fixed test

* Update doc/releases/changelog-dev.md

* Update changelog

* Updated grad tests

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated subspace docstring

---------

Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>

* jax integration for for DefaultQubit2 (#4137)

* copy-paste autograd test file

* port to jax in tests; update shots in jax interface

* add argnums when needed; skip tests that do not work with jax

* use pytest imports to skip

* pylint tests

* changelog

* take shots change from Christina's PR

* Update doc/releases/changelog-dev.md

Co-authored-by: Mudit Pandey <[email protected]>

* copy changes to autograd as well

* rename to indicate bool; slight autograd fixup

---------

Co-authored-by: Mudit Pandey <[email protected]>

* Treat identities as equivalent in `pauli.are_identical_pauli_words` (#4161)

* fix hamiltonian grouping indices bug

* Update doc/releases/changelog-dev.md

* Take wire ordering in the `wires` argument to `qml.density_matrix` into account (#4072)

* include wire ordering, test for that, raise error for broadcasting, test for that

* reduce

* changelog

* add test for qinfo transform

* more tests for math module

* lint math tests

* lint

* black

* introduce, use and test input_is_dm kwarg to reduced_dm

* tmp

* reverting

* seed fix

---------

Co-authored-by: Edward Jiang <[email protected]>

* CY inherits from ControlledOp (#4116)

`qml.CY` has been moved from `qml.ops.qubit.non_parametric_ops` to `qml.ops.op_math.controlled_ops`
  and now inherits from `qml.ops.op_math.ControlledOp`.
---------
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Christina Lee <[email protected]>

* Empty hamiltonians are compatible with `qml.pauli_sentence()` (#4171)

* fix ps rep for empty hamiltonian

* changelog

* Update doc/releases/changelog-dev.md

Co-authored-by: Utkarsh <[email protected]>

---------

Co-authored-by: Utkarsh <[email protected]>

* Update tests/interfaces/test_torch_qnode.py

Co-authored-by: Christina Lee <[email protected]>

* Python 3.8 compatibility and increase num_directions, since spsa_grad, with num_directions=1, fails sometimes, depending on the seed.

* Fix failing tests

* Fix docs.

* Fix unsupported NoneType import

* Undo irrelevant change.

* Fix failing tests. Still not reliable.

* Fix tolerance issue with SPSA second derivative.

* Increase tolerance. This test has also been failing spontaneously on the master branch 3468885

* Switch to sampler_rng kwarg and fix tolerance issues.

* More migration to sampler_rng

* Migrate more tests to sampler_rng

* Migrate legacy tests to sampler_rng

* black

* Deprecated the sampler_seed argument

* black

* Increase tolerance for test_hamiltonian_expansion_finite_shots tests.

* Fix tol

* Pin autoray for CI

* Set num_directions=20 in all hamiltonian_expansion_finite_shots tests.

* Make black and pylint happy

* Set device seed for DQ2 tests.

* Add tests for new return type system.

* Fix bug

* Adapt dq2 tests for spsa

* Remove qml.disable_return()

* Change DQ2 tests to new seed setting system.

* Fix bug

* Fix failing tests. TF tests pass locally. Not sure what the problem is.

* Fix missing grad_kwarg

* black

* Increase tol

* Increase num_directions

* Apply suggestions from code review

Co-authored-by: David Wierichs <[email protected]>

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: David Wierichs <[email protected]>

* Copy TestRademacherSampler into new tests

* Make docs more precise and add tests for rng kwarg of samplers.

* black

* black

* Fix error message in _spsa_grad_legacy

* pylint

* Update changelog-dev.md

* black

* Increase num_directions for Hessian test.

---------

Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Romain Moyard <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: Edward Jiang <[email protected]>
Co-authored-by: Utkarsh <[email protected]>
ludmilaasb pushed a commit to ludmilaasb/pennylane that referenced this pull request Aug 15, 2023
* Change seed setting in spsa_grad.

* Update changelog.

* Adapt tests. Note that lots of tests still set a global seed!

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: Christina Lee <[email protected]>

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: Christina Lee <[email protected]>

* use Shots class in gradients module (PennyLaneAI#4152)

* linting

* add num_copies property to shots

* change gradients to use new Shots class

* fix missing update in vjp

* fix stacking and single-shots in shot_adaptive

* remove unneeded cast to tuple

* type-hints and touch-ups

* code review feedback

* changelog

---------

Co-authored-by: Romain Moyard <[email protected]>

* Qutrit Rotations PennyLaneAI#2 (TRY) (PennyLaneAI#2846)

* Adding tests for tensor observables

* Added tests for tensor sample

* Updated tests

* Apply suggestions from code review

* Partition device apply ops test case.

* Run black

* Fix pylint

* Update pennylane/devices/default_qutrit.py

* black and pylint

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_non_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated test_default_qutrit.py

* Updated _apply_tadd documentation

* Added eigvals method for TSWAP

* Reverted TSWAP eigval changes

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Jay Soni <[email protected]>

* Added TSWAP eigvals

* Updated changelog-dev.md to include GellMannObs

* Removed empty file

* Added linting comments

* Updated tests to use gate_data

* Updated test parameter names to be more accurate

* Remove unused file

* Updated GellMannObs doc-string

* Update changelog-dev.md

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Added changes to GellMann to address PR comments

* Updated test

* Reformatting

* Trying out changes to Gell-Mann docstring

* Updated Changelog

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Testing LaTeX align

* Added non-diag tests

* Added diag, complex case for tensor sample

* Added example to doc string

* Fixed label test

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Added tests for controlled qutrit unitary

* Fix broadcasting, finish tests for CQutritUnitary

* Added TRX and created skeleton files

* Adding tests for TRX

* Fixed broadcasting issue in controlled qutrit unitary

* Fixed broadcasting issue with ControlledQutritUnitary

* Fixed broadcasting issue in TRX

* Updated TRX documentation

* Added tests

* Added tests for TRX

* Removed unused imports

* Removed unused imports, linting changes

* Added TRX parameter frequencies

* Updated matrix dtype for TRX generator

* Added test for param frequencies

* Added param-shift capability for qutrit devices

* Updated changelog

* Update changelog

* Added change for TRX generator

* Updated utils.py to support higher dimensions

* Added tests for updated utils.sparse_hamiltonian

* Added Identity as supported obs

* Updated TRX docstring

* Update tests/ops/qutrit/test_qutrit_non_parametric_ops.py

Co-authored-by: Jay Soni <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Jay Soni <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Jay Soni <[email protected]>

* Added ControlledQutritUnitary

* Update changelog-dev.md

* Removed empty files

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated to address PR

* Fixed uncommented lines in test suite

* Added complex values to state

* Updated test_mixed_polarity_controls

* Fixed QutritUnitary._controlled

* Updated test_controlled for matrix ops

* Updated ControlledQutritUnitary._controlled

* Reformatting

* Update pennylane/ops/qutrit/matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated ControlledQutritUnitary and tests

* Addressing PR review

* Updated sparse_hamiltonian, fixed TRX docstring

* Addressing PR review

* Refactoring

* Fixed changelog

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/test_qnode.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Reverted changes to sparse_hamiltonian

* Fixed sparse_hamiltonian test

* Updated changelog

* Updated TRX documentation

* Fixed generator

* Adding levels to sparse_hamiltonian

* Updated test sparse hamiltonian

* Fixed sparse hamiltonian test

* Fixed constant level kwarg

* Updated changelog, added test coverage

* Fixed coverage

* Updated test suite

* Updated files to address PR review

* Updated tests to include subspace error tests

* Added TRX tests for parameter shift

* Update doc/releases/changelog-dev.md

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/utils.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update utils.py to remove trailing whitespace

* Updated to address PR review

* Fixed class/object confusion bug

* Testing changes to adjust lines changed in PR

* Fixing changes

* Fixing changes

* Resetting problem files

* Fixing changes

* updated TRX docs

* Fixed TRX docs

* Updated TRX docs

* Fixed PR too many lines changed issue

* Updated subspace error tests

* Tweaked THadamard docs to fix rendering

* Test dos2unix

* Fixed subspace testing

* Merge changes

* Started adding tests for grad

* Updated tests to parametrize diff-method

* Linted tests

* Fiex tests using in-place inversion

* Added diff tests

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Fixed formatting

* Update pennylane/utils.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated TRY and tests

* Updated utils.py

* Fixed TRX generator

* Updated generator TRY

* Updated subspace validation for TRY

* Updated subspace validation

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Christina Lee <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Matthew Silverman <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Matthew Silverman <[email protected]>

* Reverted `validate_subspace` changes

* Updated test

* Added parameter shift test

* Fixed test

* Update doc/releases/changelog-dev.md

* Update changelog

* Updated grad tests

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated subspace docstring

---------

Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>

* jax integration for for DefaultQubit2 (PennyLaneAI#4137)

* copy-paste autograd test file

* port to jax in tests; update shots in jax interface

* add argnums when needed; skip tests that do not work with jax

* use pytest imports to skip

* pylint tests

* changelog

* take shots change from Christina's PR

* Update doc/releases/changelog-dev.md

Co-authored-by: Mudit Pandey <[email protected]>

* copy changes to autograd as well

* rename to indicate bool; slight autograd fixup

---------

Co-authored-by: Mudit Pandey <[email protected]>

* Treat identities as equivalent in `pauli.are_identical_pauli_words` (PennyLaneAI#4161)

* fix hamiltonian grouping indices bug

* Update doc/releases/changelog-dev.md

* Take wire ordering in the `wires` argument to `qml.density_matrix` into account (PennyLaneAI#4072)

* include wire ordering, test for that, raise error for broadcasting, test for that

* reduce

* changelog

* add test for qinfo transform

* more tests for math module

* lint math tests

* lint

* black

* introduce, use and test input_is_dm kwarg to reduced_dm

* tmp

* reverting

* seed fix

---------

Co-authored-by: Edward Jiang <[email protected]>

* CY inherits from ControlledOp (PennyLaneAI#4116)

`qml.CY` has been moved from `qml.ops.qubit.non_parametric_ops` to `qml.ops.op_math.controlled_ops`
  and now inherits from `qml.ops.op_math.ControlledOp`.
---------
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Christina Lee <[email protected]>

* Empty hamiltonians are compatible with `qml.pauli_sentence()` (PennyLaneAI#4171)

* fix ps rep for empty hamiltonian

* changelog

* Update doc/releases/changelog-dev.md

Co-authored-by: Utkarsh <[email protected]>

---------

Co-authored-by: Utkarsh <[email protected]>

* Update tests/interfaces/test_torch_qnode.py

Co-authored-by: Christina Lee <[email protected]>

* Python 3.8 compatibility and increase num_directions, since spsa_grad, with num_directions=1, fails sometimes, depending on the seed.

* Fix failing tests

* Fix docs.

* Fix unsupported NoneType import

* Undo irrelevant change.

* Fix failing tests. Still not reliable.

* Fix tolerance issue with SPSA second derivative.

* Increase tolerance. This test has also been failing spontaneously on the master branch 3468885

* Switch to sampler_rng kwarg and fix tolerance issues.

* More migration to sampler_rng

* Migrate more tests to sampler_rng

* Migrate legacy tests to sampler_rng

* black

* Deprecated the sampler_seed argument

* black

* Increase tolerance for test_hamiltonian_expansion_finite_shots tests.

* Fix tol

* Pin autoray for CI

* Set num_directions=20 in all hamiltonian_expansion_finite_shots tests.

* Make black and pylint happy

* Set device seed for DQ2 tests.

* Add tests for new return type system.

* Fix bug

* Adapt dq2 tests for spsa

* Remove qml.disable_return()

* Change DQ2 tests to new seed setting system.

* Fix bug

* Fix failing tests. TF tests pass locally. Not sure what the problem is.

* Fix missing grad_kwarg

* black

* Increase tol

* Increase num_directions

* Apply suggestions from code review

Co-authored-by: David Wierichs <[email protected]>

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: David Wierichs <[email protected]>

* Copy TestRademacherSampler into new tests

* Make docs more precise and add tests for rng kwarg of samplers.

* black

* black

* Fix error message in _spsa_grad_legacy

* pylint

* Update changelog-dev.md

* black

* Increase num_directions for Hessian test.

---------

Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Romain Moyard <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: Edward Jiang <[email protected]>
Co-authored-by: Utkarsh <[email protected]>
mlxd pushed a commit that referenced this pull request Aug 23, 2023
* Change seed setting in spsa_grad.

* Update changelog.

* Adapt tests. Note that lots of tests still set a global seed!

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: Christina Lee <[email protected]>

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: Christina Lee <[email protected]>

* use Shots class in gradients module (#4152)

* linting

* add num_copies property to shots

* change gradients to use new Shots class

* fix missing update in vjp

* fix stacking and single-shots in shot_adaptive

* remove unneeded cast to tuple

* type-hints and touch-ups

* code review feedback

* changelog

---------

Co-authored-by: Romain Moyard <[email protected]>

* Qutrit Rotations #2 (TRY) (#2846)

* Adding tests for tensor observables

* Added tests for tensor sample

* Updated tests

* Apply suggestions from code review

* Partition device apply ops test case.

* Run black

* Fix pylint

* Update pennylane/devices/default_qutrit.py

* black and pylint

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_non_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated test_default_qutrit.py

* Updated _apply_tadd documentation

* Added eigvals method for TSWAP

* Reverted TSWAP eigval changes

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Jay Soni <[email protected]>

* Added TSWAP eigvals

* Updated changelog-dev.md to include GellMannObs

* Removed empty file

* Added linting comments

* Updated tests to use gate_data

* Updated test parameter names to be more accurate

* Remove unused file

* Updated GellMannObs doc-string

* Update changelog-dev.md

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Added changes to GellMann to address PR comments

* Updated test

* Reformatting

* Trying out changes to Gell-Mann docstring

* Updated Changelog

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Testing LaTeX align

* Added non-diag tests

* Added diag, complex case for tensor sample

* Added example to doc string

* Fixed label test

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/devices/test_default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Added tests for controlled qutrit unitary

* Fix broadcasting, finish tests for CQutritUnitary

* Added TRX and created skeleton files

* Adding tests for TRX

* Fixed broadcasting issue in controlled qutrit unitary

* Fixed broadcasting issue with ControlledQutritUnitary

* Fixed broadcasting issue in TRX

* Updated TRX documentation

* Added tests

* Added tests for TRX

* Removed unused imports

* Removed unused imports, linting changes

* Added TRX parameter frequencies

* Updated matrix dtype for TRX generator

* Added test for param frequencies

* Added param-shift capability for qutrit devices

* Updated changelog

* Update changelog

* Added change for TRX generator

* Updated utils.py to support higher dimensions

* Added tests for updated utils.sparse_hamiltonian

* Added Identity as supported obs

* Updated TRX docstring

* Update tests/ops/qutrit/test_qutrit_non_parametric_ops.py

Co-authored-by: Jay Soni <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Jay Soni <[email protected]>

* Update pennylane/ops/qutrit/observables.py

Co-authored-by: Jay Soni <[email protected]>

* Added ControlledQutritUnitary

* Update changelog-dev.md

* Removed empty files

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated to address PR

* Fixed uncommented lines in test suite

* Added complex values to state

* Updated test_mixed_polarity_controls

* Fixed QutritUnitary._controlled

* Updated test_controlled for matrix ops

* Updated ControlledQutritUnitary._controlled

* Reformatting

* Update pennylane/ops/qutrit/matrix_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated ControlledQutritUnitary and tests

* Addressing PR review

* Updated sparse_hamiltonian, fixed TRX docstring

* Addressing PR review

* Refactoring

* Fixed changelog

* Update pennylane/devices/default_qutrit.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/test_qnode.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Reverted changes to sparse_hamiltonian

* Fixed sparse_hamiltonian test

* Updated changelog

* Updated TRX documentation

* Fixed generator

* Adding levels to sparse_hamiltonian

* Updated test sparse hamiltonian

* Fixed sparse hamiltonian test

* Fixed constant level kwarg

* Updated changelog, added test coverage

* Fixed coverage

* Updated test suite

* Updated files to address PR review

* Updated tests to include subspace error tests

* Added TRX tests for parameter shift

* Update doc/releases/changelog-dev.md

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update pennylane/utils.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update utils.py to remove trailing whitespace

* Updated to address PR review

* Fixed class/object confusion bug

* Testing changes to adjust lines changed in PR

* Fixing changes

* Fixing changes

* Resetting problem files

* Fixing changes

* updated TRX docs

* Fixed TRX docs

* Updated TRX docs

* Fixed PR too many lines changed issue

* Updated subspace error tests

* Tweaked THadamard docs to fix rendering

* Test dos2unix

* Fixed subspace testing

* Merge changes

* Started adding tests for grad

* Updated tests to parametrize diff-method

* Linted tests

* Fiex tests using in-place inversion

* Added diff tests

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Update tests/ops/qutrit/test_qutrit_parametric_ops.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Fixed formatting

* Update pennylane/utils.py

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated TRY and tests

* Updated utils.py

* Fixed TRX generator

* Updated generator TRY

* Updated subspace validation for TRY

* Updated subspace validation

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Christina Lee <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Matthew Silverman <[email protected]>

* Update pennylane/ops/qutrit/parametric_ops.py

Co-authored-by: Matthew Silverman <[email protected]>

* Reverted `validate_subspace` changes

* Updated test

* Added parameter shift test

* Fixed test

* Update doc/releases/changelog-dev.md

* Update changelog

* Updated grad tests

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <[email protected]>

* Updated subspace docstring

---------

Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>

* jax integration for for DefaultQubit2 (#4137)

* copy-paste autograd test file

* port to jax in tests; update shots in jax interface

* add argnums when needed; skip tests that do not work with jax

* use pytest imports to skip

* pylint tests

* changelog

* take shots change from Christina's PR

* Update doc/releases/changelog-dev.md

Co-authored-by: Mudit Pandey <[email protected]>

* copy changes to autograd as well

* rename to indicate bool; slight autograd fixup

---------

Co-authored-by: Mudit Pandey <[email protected]>

* Treat identities as equivalent in `pauli.are_identical_pauli_words` (#4161)

* fix hamiltonian grouping indices bug

* Update doc/releases/changelog-dev.md

* Take wire ordering in the `wires` argument to `qml.density_matrix` into account (#4072)

* include wire ordering, test for that, raise error for broadcasting, test for that

* reduce

* changelog

* add test for qinfo transform

* more tests for math module

* lint math tests

* lint

* black

* introduce, use and test input_is_dm kwarg to reduced_dm

* tmp

* reverting

* seed fix

---------

Co-authored-by: Edward Jiang <[email protected]>

* CY inherits from ControlledOp (#4116)

`qml.CY` has been moved from `qml.ops.qubit.non_parametric_ops` to `qml.ops.op_math.controlled_ops`
  and now inherits from `qml.ops.op_math.ControlledOp`.
---------
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Christina Lee <[email protected]>

* Empty hamiltonians are compatible with `qml.pauli_sentence()` (#4171)

* fix ps rep for empty hamiltonian

* changelog

* Update doc/releases/changelog-dev.md

Co-authored-by: Utkarsh <[email protected]>

---------

Co-authored-by: Utkarsh <[email protected]>

* Update tests/interfaces/test_torch_qnode.py

Co-authored-by: Christina Lee <[email protected]>

* Python 3.8 compatibility and increase num_directions, since spsa_grad, with num_directions=1, fails sometimes, depending on the seed.

* Fix failing tests

* Fix docs.

* Fix unsupported NoneType import

* Undo irrelevant change.

* Fix failing tests. Still not reliable.

* Fix tolerance issue with SPSA second derivative.

* Increase tolerance. This test has also been failing spontaneously on the master branch 3468885

* Switch to sampler_rng kwarg and fix tolerance issues.

* More migration to sampler_rng

* Migrate more tests to sampler_rng

* Migrate legacy tests to sampler_rng

* black

* Deprecated the sampler_seed argument

* black

* Increase tolerance for test_hamiltonian_expansion_finite_shots tests.

* Fix tol

* Pin autoray for CI

* Set num_directions=20 in all hamiltonian_expansion_finite_shots tests.

* Make black and pylint happy

* Set device seed for DQ2 tests.

* Add tests for new return type system.

* Fix bug

* Adapt dq2 tests for spsa

* Remove qml.disable_return()

* Change DQ2 tests to new seed setting system.

* Fix bug

* Fix failing tests. TF tests pass locally. Not sure what the problem is.

* Fix missing grad_kwarg

* black

* Increase tol

* Increase num_directions

* Apply suggestions from code review

Co-authored-by: David Wierichs <[email protected]>

* Update pennylane/gradients/spsa_gradient.py

Co-authored-by: David Wierichs <[email protected]>

* Copy TestRademacherSampler into new tests

* Make docs more precise and add tests for rng kwarg of samplers.

* black

* black

* Fix error message in _spsa_grad_legacy

* pylint

* Update changelog-dev.md

* black

* Increase num_directions for Hessian test.

---------

Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: Romain Moyard <[email protected]>
Co-authored-by: Mudit Pandey <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Olivia Di Matteo <[email protected]>
Co-authored-by: Jay Soni <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Matthew Silverman <[email protected]>
Co-authored-by: David Wierichs <[email protected]>
Co-authored-by: Edward Jiang <[email protected]>
Co-authored-by: Utkarsh <[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.

4 participants