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

[new opmath 4] Update tests to pass under new opmath #5335

Merged
merged 225 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
225 commits
Select commit Hold shift + click to select a range
cf10b65
Added qml.Hamiltonian-qml.LinearCombination aliasing
mudit2812 Mar 6, 2024
9e558a5
Added op math enable to init file
mudit2812 Mar 7, 2024
c1e7b0b
Hamiltonian tests pass
Qottmann Mar 7, 2024
a99b567
black formatting
Qottmann Mar 7, 2024
77be033
[ci skip]
Qottmann Mar 7, 2024
fd8c431
update controlled
Qottmann Mar 7, 2024
1b502c7
update sum tests
Qottmann Mar 7, 2024
3e81ef4
black formatting
Qottmann Mar 7, 2024
878b6aa
update op_math, still some failures
Qottmann Mar 7, 2024
e568051
black formatting
Qottmann Mar 7, 2024
361e054
pylint
Qottmann Mar 7, 2024
88c0f8a
black formatting
Qottmann Mar 7, 2024
5c229b9
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 8, 2024
af387f1
[ci skip]
Qottmann Mar 8, 2024
f027981
merge
Qottmann Mar 8, 2024
ffd66ca
Add appropriate fixtures for legacy and new opmath, as well as one te…
Qottmann Mar 8, 2024
af4d36f
black formatting
Qottmann Mar 8, 2024
2a87a50
tests/test_operation.py passes
Qottmann Mar 8, 2024
901d738
black formatting
Qottmann Mar 8, 2024
7dd0f31
some updates to test_equal but still not all passing
Qottmann Mar 8, 2024
24fadee
update dipole
Qottmann Mar 8, 2024
ecfc9be
black formatting
Qottmann Mar 8, 2024
f0667e6
typo _usefixtures_
Qottmann Mar 8, 2024
7436215
Test fixture itself
Qottmann Mar 8, 2024
6543a90
black formatting
Qottmann Mar 8, 2024
1a4c5ac
unused imports in sum
Qottmann Mar 8, 2024
529cc0b
pylint linearcombination
Qottmann Mar 8, 2024
edab8e3
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 8, 2024
1356d40
[ci skip]
Qottmann Mar 8, 2024
77a0409
merge
Qottmann Mar 8, 2024
736b31b
pylint
Qottmann Mar 8, 2024
b2bbfd7
test circuit graph hash
Qottmann Mar 8, 2024
095477d
tests/ops/qubit/ pass
Qottmann Mar 8, 2024
9ca49c9
black formatting
Qottmann Mar 8, 2024
24c884f
test_eigvals
Qottmann Mar 8, 2024
8b3d2e8
test_eigvals
Qottmann Mar 8, 2024
cfa7c39
test_equal.py
Qottmann Mar 8, 2024
4841361
black formatting
Qottmann Mar 8, 2024
f1db21e
test_qutrit_observables
Qottmann Mar 8, 2024
9d5bed1
update tests/resource/
Qottmann Mar 8, 2024
7064b1b
update tests/tape
Qottmann Mar 8, 2024
e74cf39
Added import Hamiltonian support to toggle
mudit2812 Mar 8, 2024
550751b
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 8, 2024
a8d340a
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 8, 2024
9cb1df2
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 11, 2024
67abfa2
[ci skip]
Qottmann Mar 11, 2024
f3cef17
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 11, 2024
3f1f964
merge
Qottmann Mar 11, 2024
5fd6f13
remove top level import of LinearCombination
Qottmann Mar 11, 2024
8bc7d69
[ci skip]
Qottmann Mar 11, 2024
0a2ecd5
[ci skip]
Qottmann Mar 11, 2024
1d0f027
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 11, 2024
c067f88
add missing import
Qottmann Mar 11, 2024
5311bcb
fix error disabling new opmath when there is no Hamiltonian imported yet
Qottmann Mar 11, 2024
207792a
[ci skip]
Qottmann Mar 11, 2024
0ee2677
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 11, 2024
52539df
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 11, 2024
3c9db12
[ci skip]
Qottmann Mar 11, 2024
616f924
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 11, 2024
973bee3
[ci skip]
Qottmann Mar 11, 2024
83bf86e
update pauli grouping tests
Qottmann Mar 11, 2024
dbb0a07
update pennylane/pauli/conversion.py Hamiltonian >> qml.Hamiltonian
Qottmann Mar 11, 2024
50b5911
tests/pauli/test_conversion.py pass
Qottmann Mar 11, 2024
1e05e34
tests/pauli/test_pauli_arithmetic.py pass
Qottmann Mar 11, 2024
1f572c8
black formatting
Qottmann Mar 11, 2024
d766d94
update utils test, still fail
Qottmann Mar 11, 2024
0c62d56
[ci skip]
Qottmann Mar 11, 2024
ad25ab0
rename legacy tests to .._legacy_opmath()
Qottmann Mar 11, 2024
50eb30c
[ci skip]
Qottmann Mar 11, 2024
e67f83d
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 12, 2024
f46afb8
[ci skip]
Qottmann Mar 12, 2024
be9968d
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 12, 2024
859a5dd
[ci skip]
Qottmann Mar 12, 2024
7ecea5a
Hamiltonian -> qml.Hamiltonian in PauliSentence
Qottmann Mar 12, 2024
3ee097c
[ci skip]
Qottmann Mar 12, 2024
b6748a0
[ci skip]
Qottmann Mar 12, 2024
9ccc615
tests/pulse pass except pickle issue, could be local
Qottmann Mar 12, 2024
7906295
black formatting
Qottmann Mar 12, 2024
627b98f
[ci skip]
Qottmann Mar 12, 2024
5aacfd2
[ci skip]
Qottmann Mar 12, 2024
f1344e6
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 12, 2024
99c4594
[ci skip]
Qottmann Mar 12, 2024
c90d98d
qml.LinearCombination -> qml.ops.LinearCombination
Qottmann Mar 12, 2024
2f62e54
[ci skip]
Qottmann Mar 12, 2024
990fec1
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 12, 2024
51ada49
[ci skip]
Qottmann Mar 12, 2024
d212fd1
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 13, 2024
3ff0ef8
[ci skip]
Qottmann Mar 13, 2024
8c6871a
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 13, 2024
87c67fa
[ci skip]
Qottmann Mar 13, 2024
0bdad63
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 13, 2024
3a20dab
[ci skip]
Qottmann Mar 13, 2024
5cf3f2e
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 13, 2024
1060523
[ci skip]
Qottmann Mar 13, 2024
ab5c16c
[new opmath] Upgrade classical shadows with new opmath (#5374)
Qottmann Mar 13, 2024
0784fd4
[new opmath 4.1] Update pauli utils (#5355)
Qottmann Mar 13, 2024
5cfc947
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 13, 2024
f0b8756
[ci skip]
Qottmann Mar 13, 2024
7a117a3
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 13, 2024
1b02c06
[ci skip]
Qottmann Mar 13, 2024
11d1194
Update measurement tests for new op math (#5368)
lillian542 Mar 13, 2024
d6d5ad5
[ci skip]
Qottmann Mar 13, 2024
e919b6c
fixing tests related to generators (#5360)
PietropaoloFrisoni Mar 13, 2024
b345c9f
Update drawer tests for op_math (#5363)
lillian542 Mar 13, 2024
42a1ba3
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 14, 2024
e738552
[ci skip]
Qottmann Mar 14, 2024
be21be8
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 14, 2024
fbb8ec3
[ci skip]
Qottmann Mar 14, 2024
d4181ad
Merge branch 'ham-tests' of https://github.com/PennyLaneAI/pennylane …
Qottmann Mar 14, 2024
6bb1b3c
[ci skip]
Qottmann Mar 14, 2024
9b44f09
revert mock patch on __main__
Qottmann Mar 14, 2024
056e21a
[ci skip]
Qottmann Mar 14, 2024
575e68c
remove xfail that now works :)
Qottmann Mar 14, 2024
a2a79ce
[ci skip]
Qottmann Mar 14, 2024
a0ffccd
fixing `tests/test_device.py.test_device_default_expand_ops` (#5379)
PietropaoloFrisoni Mar 14, 2024
63a999c
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 14, 2024
fc72692
[ci skip]
Qottmann Mar 14, 2024
e1d21a4
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 14, 2024
6b82835
[ci skip]
Qottmann Mar 14, 2024
a4a4735
Updated tests to cover more cases
mudit2812 Mar 14, 2024
55548b9
Updated changelog
mudit2812 Mar 14, 2024
484dc78
Update `interfaces` and `gradients` to work with new operator arithme…
albi3ro Mar 14, 2024
f8baef5
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 15, 2024
2d5c8bf
[ci skip]
Qottmann Mar 15, 2024
41cb8ab
merge
Qottmann Mar 15, 2024
4aff7c9
fix tests/test_operation.py and update convert_to_legacy_H to use con…
Qottmann Mar 15, 2024
ea1b5c0
black formatting
Qottmann Mar 15, 2024
31ba1cb
[ci skip]
Qottmann Mar 15, 2024
29c4c62
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 15, 2024
bdb28d0
[ci skip]
Qottmann Mar 15, 2024
9f7c9fc
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 15, 2024
ce6888a
[ci skip]
Qottmann Mar 15, 2024
082f58c
remove unused imports
Qottmann Mar 15, 2024
210f49c
rename test for pylint
Qottmann Mar 15, 2024
c8033f3
[ci skip]
Qottmann Mar 15, 2024
ef49abf
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 15, 2024
d145c0b
[ci skip]
Qottmann Mar 15, 2024
ee84ace
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 15, 2024
13711f1
[ci skip]
Qottmann Mar 15, 2024
669dd10
[new opmath] `tests/optimize/` (#5382)
Qottmann Mar 15, 2024
e632097
fix generator test
Qottmann Mar 15, 2024
e19eca0
black formatting
Qottmann Mar 15, 2024
5a31435
fix generator test
Qottmann Mar 15, 2024
bfde8ad
[ci skip]
Qottmann Mar 15, 2024
64c5246
merge
Qottmann Mar 15, 2024
d42a7a2
[ci skip]
Qottmann Mar 15, 2024
02b1a10
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 15, 2024
b62829d
[ci skip]
Qottmann Mar 15, 2024
25f5672
Update `qchem` and `data` tests for opmath (#5358)
obliviateandsurrender Mar 15, 2024
093454f
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 18, 2024
de37c2a
[ci skip]
Qottmann Mar 18, 2024
f22f876
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 18, 2024
e12fcbc
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 18, 2024
484e888
[ci skip]
Qottmann Mar 18, 2024
ac85f4c
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 18, 2024
a932b26
pylint
Qottmann Mar 18, 2024
92825b0
black formatting
Qottmann Mar 18, 2024
3cacbe9
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 18, 2024
e2e9ff2
[ci skip]
Qottmann Mar 18, 2024
a498c7a
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 18, 2024
eed0100
Assert_valid tests pass with new opmath and old Hamiltonian (#5388)
lillian542 Mar 18, 2024
1b6ed57
Update tests in top-level of tests folder for new op-math (#5375)
lillian542 Mar 18, 2024
3caa63b
trigger CI
Qottmann Mar 18, 2024
34fe0dd
Update `LinearCombination.compute_grouping` to account for duplicate …
mudit2812 Mar 18, 2024
254911e
Fixing `tests/transforms` (#5365)
PietropaoloFrisoni Mar 18, 2024
357b365
Make `Prod` compatible with qutrit operators (#5400)
albi3ro Mar 18, 2024
cfa4268
[new opmath] Update tests/workflow/ (#5396)
Qottmann Mar 18, 2024
461c038
[enable new opmath] update tests/devices/ (#5391)
Qottmann Mar 18, 2024
743d842
[new upmath] `tests/test_qaoa.py` (#5383)
astralcai Mar 18, 2024
7067e9e
remove failing parameterization for now
lillian542 Mar 18, 2024
b6b8f79
Fix `Hamiltonian` loading for datasets (#5402)
obliviateandsurrender Mar 18, 2024
8b04d93
Create legacy test case in context manager
astralcai Mar 18, 2024
139ebe9
Merge branch 'ham-tests' of https://github.com/PennyLaneAI/pennylane …
astralcai Mar 18, 2024
9c08948
remove explicit enable/disables in test_hamiltonian.py
Qottmann Mar 18, 2024
e7d2c8e
black formatting
Qottmann Mar 18, 2024
e2fc12e
Merge branch 'ham-tests' of https://github.com/PennyLaneAI/pennylane …
Qottmann Mar 18, 2024
00adbec
Use qml.Hamiltonian instead of Hamiltonian in isinstance checks (#5403)
astralcai Mar 19, 2024
effbe63
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
b6bab3b
[ci skip]
Qottmann Mar 20, 2024
28cb6a6
merge
Qottmann Mar 20, 2024
c36c529
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
bbddd9e
[ci skip]
Qottmann Mar 20, 2024
9fa182f
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 20, 2024
18e34b0
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
a532483
[ci skip]
Qottmann Mar 20, 2024
a7eee13
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 20, 2024
736906b
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
db91050
[ci skip]
Qottmann Mar 20, 2024
3ac5f75
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 20, 2024
d234c76
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
4814817
[ci skip]
Qottmann Mar 20, 2024
eea4e09
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 20, 2024
9534053
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
4141a5d
[ci skip]
Qottmann Mar 20, 2024
84868d7
[new opmath 3] Make `qml.Hamiltonian` alias for `qml.LinearCombinatio…
mudit2812 Mar 20, 2024
46b10a1
Merge branch 'ham-lc-switch' of https://github.com/PennyLaneAI/pennyl…
Qottmann Mar 20, 2024
592a7b5
Merge branch 'ham-tests' of https://github.com/PennyLaneAI/pennylane …
Qottmann Mar 20, 2024
708780a
fix test
Qottmann Mar 20, 2024
0cebdff
black formatting
Qottmann Mar 20, 2024
288b66d
fix test
Qottmann Mar 20, 2024
714149c
black formatting
Qottmann Mar 20, 2024
fb39559
test name
Qottmann Mar 20, 2024
b7646a4
black formatting
Qottmann Mar 20, 2024
227ff9c
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
4b35c14
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 20, 2024
f710fab
Upate qchem op generators to return qml.Hamiltonian (#5410)
lillian542 Mar 20, 2024
1037363
Fix qutrit mixed sampling of hamiltonians (#5413)
astralcai Mar 20, 2024
377163f
Comment on generators that won't be following new_opmath (#5411)
lillian542 Mar 20, 2024
29f1d90
merge
Qottmann Mar 21, 2024
0c1cc3b
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 21, 2024
50aef2a
trigger
Qottmann Mar 21, 2024
6966f7f
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 21, 2024
c290f28
Adapting generators to opmath enabled/disabled (#5415)
PietropaoloFrisoni Mar 21, 2024
5013e4b
Update qml.generator's "hamiltonian" method to follow new operator ar…
lillian542 Mar 21, 2024
600ea3e
Merge branch 'linearcombination' of https://github.com/PennyLaneAI/pe…
Qottmann Mar 22, 2024
55d1617
Merge branch 'ham-tests' of https://github.com/PennyLaneAI/pennylane …
Qottmann Mar 22, 2024
82d26a5
revert last commit
Qottmann Mar 22, 2024
e79dd5f
Merge branch 'ham-tests' of https://github.com/PennyLaneAI/pennylane …
Qottmann Mar 22, 2024
17edf02
merge xfail with lightning as reason
Qottmann Mar 23, 2024
3b1f144
test_lighting_device_legacy_opmath
Qottmann Mar 25, 2024
2e195f6
revert last commit
Qottmann Mar 25, 2024
06426df
fix spsa test
Qottmann Mar 25, 2024
9b22957
[new opmath] Simplify `LinearCombination(coeffs, ops, simplify=True)`…
Qottmann Mar 25, 2024
0558038
Remove usage of `qml.Hamiltonian` from `hamiltonian.py` (#5429)
astralcai Mar 25, 2024
d70a355
Replace qml.Hamiltonian from isinstance checks for qml.ops.Hamiltonia…
astralcai Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ Pending deprecations

- Added and deprecated for ``Sum`` and ``Prod`` instances in v0.35

* Accessing ``qml.ops.Hamiltonian`` with new operator arithmetic enabled is deprecated. Using ``qml.Hamiltonian``
with new operator arithmetic enabled now returns a ``LinearCombination`` instance. Some functionality
may not work as expected, and use of the Hamiltonian class with the new operator arithmetic will not
be supported in future releases of PennyLane.

You can update your code to the new operator arithmetic by using ``qml.Hamiltonian`` instead of importing
the Hamiltonian class directly or via ``qml.ops.Hamiltonian``. When the new operator arithmetic is enabled,
``qml.Hamiltonian`` will access the new corresponding implementation.

Alternatively, to continue accessing the legacy functionality, you can use
``qml.operation.disable_new_opmath()``.

- Deprecated in v0.36

Completed deprecation cycles
----------------------------

Expand Down
29 changes: 27 additions & 2 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
* Added new function `qml.operation.convert_to_legacy_H` to convert `Sum`, `SProd`, and `Prod` to `Hamiltonian` instances.
[(#5309)](https://github.com/PennyLaneAI/pennylane/pull/5309)

<h3>Improvements 🛠</h3>

* The `qml.is_commuting` function now accepts `Sum`, `SProd`, and `Prod` instances.
[(#5351)](https://github.com/PennyLaneAI/pennylane/pull/5351)

* Operators can now be left multiplied `x * op` by numpy arrays.
[(#5361)](https://github.com/PennyLaneAI/pennylane/pull/5361)

* Create the `qml.Reflection` operator, useful for amplitude amplification and its variants.
[(#5159)](https://github.com/PennyLaneAI/pennylane/pull/5159)

Expand Down Expand Up @@ -151,9 +159,14 @@
* The `molecular_hamiltonian` function calls `PySCF` directly when `method='pyscf'` is selected.
[(#5118)](https://github.com/PennyLaneAI/pennylane/pull/5118)

* All generators in the source code (except those in the `qchem` module) no longer return
`Hamiltonian` or `Tensor` instances. Wherever possible, these return `Sum`, `SProd`, and `Prod` instances.
* The generators in the source code return operators consistent with the global setting for
`qml.operator.active_new_opmath()` wherever possible. `Sum`, `SProd` and `Prod` instances
will be returned even after disabling the new operator arithmetic in cases where they offer
additional functionality not available using legacy operators.
[(#5253)](https://github.com/PennyLaneAI/pennylane/pull/5253)
[(#5410)](https://github.com/PennyLaneAI/pennylane/pull/5410)
[(#5411)](https://github.com/PennyLaneAI/pennylane/pull/5411)
[(#5421)](https://github.com/PennyLaneAI/pennylane/pull/5421)

* Upgraded `null.qubit` to the new device API. Also, added support for all measurements and various modes of differentiation.
[(#5211)](https://github.com/PennyLaneAI/pennylane/pull/5211)
Expand All @@ -164,6 +177,9 @@
* `Hamiltonian.pauli_rep` is now defined if the hamiltonian is a linear combination of paulis.
[(#5377)](https://github.com/PennyLaneAI/pennylane/pull/5377)

* `Prod.eigvals()` is now compatible with Qudit operators.
[(#5400)](https://github.com/PennyLaneAI/pennylane/pull/5400)

* Obtaining classical shadows using the `default.clifford` device is now compatible with
[stim](https://github.com/quantumlib/Stim) `v1.13.0`.
[(#5409)](https://github.com/PennyLaneAI/pennylane/pull/5409)
Expand Down Expand Up @@ -230,6 +246,10 @@
* Attempting to multiply `PauliWord` and `PauliSentence` with `*` will raise an error. Instead, use `@` to conform with the PennyLane convention.
[(#5341)](https://github.com/PennyLaneAI/pennylane/pull/5341)

* When new operator arithmetic is enabled, `qml.Hamiltonian` is now an alias for `qml.ops.LinearCombination`.
`Hamiltonian` will still be accessible as `qml.ops.Hamiltonian`.
[(#5393)](https://github.com/PennyLaneAI/pennylane/pull/5393)

* Since `default.mixed` does not support snapshots with measurements, attempting to do so will result in a `DeviceError` instead of getting the density matrix.
[(#5416)](https://github.com/PennyLaneAI/pennylane/pull/5416)

Expand All @@ -249,6 +269,11 @@
... circuit = qml.from_qasm(f.read())
```

* Accessing `qml.ops.Hamiltonian` with new operator arithmetic is deprecated. Using `qml.Hamiltonian` with new operator arithmetic enabled now
returns a `LinearCombination` instance. Some functionality may not work as expected. To continue using the `Hamiltonian` class, you can use
`qml.operation.disable_new_opmath()` to disable the new operator arithmetic.
[(#5393)](https://github.com/PennyLaneAI/pennylane/pull/5393)

<h3>Documentation 📝</h3>

* Removed some redundant documentation for the `evolve` function.
Expand Down
12 changes: 12 additions & 0 deletions pennylane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ class PennyLaneDeprecationWarning(UserWarning):
"""Warning raised when a PennyLane feature is being deprecated."""


del globals()["Hamiltonian"]


def __getattr__(name):
if name == "Hamiltonian":
if pennylane.operation.active_new_opmath():
return pennylane.ops.LinearCombination
return pennylane.ops.Hamiltonian

raise AttributeError(f"module 'pennylane' has no attribute '{name}'")


def _get_device_entrypoints():
"""Returns a dictionary mapping the device short name to the
loadable entrypoint"""
Expand Down
1 change: 0 additions & 1 deletion pennylane/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ def default_expand_fn(self, circuit, max_expansion=10):
obs_on_same_wire &= not any(
isinstance(o, (Hamiltonian, LinearCombination)) for o in circuit._obs_sharing_wires
)

ops_not_supported = not all(self.stopping_condition(op) for op in circuit.operations)

if obs_on_same_wire:
Expand Down
32 changes: 28 additions & 4 deletions pennylane/data/attributes/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ def consumes_types(cls) -> FrozenSet[Type[Operator]]:
qml.QubitCarry,
qml.QubitSum,
# pennylane/ops/qubit/hamiltonian.py
qml.Hamiltonian,
qml.ops.Hamiltonian,
# pennylane/ops/op_math/linear_combination.py
qml.ops.LinearCombination,
# pennylane/ops/op_math - prod.py, s_prod.py, sum.py
qml.ops.Prod,
qml.ops.SProd,
qml.ops.Sum,
# pennylane/ops/qubit/matrix_qml.py
qml.QubitUnitary,
qml.DiagonalQubitUnitary,
Expand Down Expand Up @@ -206,6 +212,8 @@ def _ops_to_hdf5(
op_class_names = []
for i, op in enumerate(value):
op_key = f"op_{i}"
if isinstance(op, (qml.ops.Prod, qml.ops.SProd, qml.ops.Sum)):
op = op.simplify()
if type(op) not in self.consumes_types():
raise TypeError(
f"Serialization of operator type '{type(op).__name__}' is not supported."
Expand All @@ -214,11 +222,19 @@ def _ops_to_hdf5(
if isinstance(op, Tensor):
self._ops_to_hdf5(bind, op_key, op.obs)
op_wire_labels.append("null")
elif isinstance(op, qml.Hamiltonian):
elif isinstance(op, (qml.ops.Hamiltonian, qml.ops.LinearCombination)):
coeffs, ops = op.terms()
ham_grp = self._ops_to_hdf5(bind, op_key, ops)
ham_grp["hamiltonian_coeffs"] = coeffs
op_wire_labels.append("null")
elif isinstance(op, (qml.ops.Prod, qml.ops.Sum)):
self._ops_to_hdf5(bind, op_key, op.operands)
op_wire_labels.append("null")
elif isinstance(op, qml.ops.SProd):
coeffs, ops = op.terms()
sprod_grp = self._ops_to_hdf5(bind, op_key, ops)
sprod_grp["sprod_scalar"] = coeffs
op_wire_labels.append("null")
else:
bind[op_key] = op.data if len(op.data) else h5py.Empty("f")
op_wire_labels.append(wires_to_json(op.wires))
Expand All @@ -238,21 +254,29 @@ def _hdf5_to_ops(self, bind: HDF5Group) -> List[Operator]:
wires_bind = bind["op_wire_labels"]
op_class_names = [] if names_bind.shape == (0,) else names_bind.asstr()
op_wire_labels = [] if wires_bind.shape == (0,) else wires_bind.asstr()

with qml.QueuingManager.stop_recording():
for i, op_class_name in enumerate(op_class_names):
op_key = f"op_{i}"

op_cls = self._supported_ops_dict()[op_class_name]
if op_cls is Tensor:
ops.append(Tensor(*self._hdf5_to_ops(bind[op_key])))
elif op_cls is qml.Hamiltonian:
elif op_cls in (qml.ops.Hamiltonian, qml.ops.LinearCombination):
ops.append(
qml.Hamiltonian(
coeffs=list(bind[op_key]["hamiltonian_coeffs"]),
observables=self._hdf5_to_ops(bind[op_key]),
)
)
elif op_cls in (qml.ops.Prod, qml.ops.Sum):
ops.append(op_cls(*self._hdf5_to_ops(bind[op_key])))
elif op_cls is qml.ops.SProd:
ops.append(
qml.ops.s_prod(
scalar=bind[op_key]["sprod_scalar"][0],
operator=self._hdf5_to_ops(bind[op_key])[0],
)
)
else:
wire_labels = json.loads(op_wire_labels[i])
op_data = bind[op_key]
Expand Down
6 changes: 3 additions & 3 deletions pennylane/devices/default_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,9 @@ def _measure_single_sample(stim_ct, meas_ops, meas_idx, meas_wire):
"""Sample a single qubit Pauli measurement from a stim circuit"""
stim_sm = stim.TableauSimulator()
stim_sm.do_circuit(stim_ct)
return stim_sm.measure_observable(
stim.PauliString([0] * meas_idx + meas_ops + [0] * (meas_wire - meas_idx - 1))
)
res = [0] * meas_idx + meas_ops + [0] * (meas_wire - meas_idx - 1)
res = [int(r) for r in res]
return stim_sm.measure_observable(stim.PauliString(res))

def _sample_classical_shadow(self, meas, stim_circuit, shots, seed):
"""Measures classical shadows from the state of simulator device"""
Expand Down
7 changes: 2 additions & 5 deletions pennylane/devices/default_qutrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
OMEGA = qml.math.exp(2 * np.pi * 1j / 3)


# pylint: disable=too-many-arguments
class DefaultQutrit(QutritDevice):
"""Default qutrit device for PennyLane.

Expand Down Expand Up @@ -87,11 +88,7 @@ class DefaultQutrit(QutritDevice):

# Identity is supported as an observable for qml.state() to work correctly. However, any
# measurement types that rely on eigenvalue decomposition will not work with qml.Identity
observables = {
"THermitian",
"GellMann",
"Identity",
}
observables = {"THermitian", "GellMann", "Identity", "Prod"}

# Static methods to use qml.math to allow for backprop differentiation
_reshape = staticmethod(qml.math.reshape)
Expand Down
2 changes: 1 addition & 1 deletion pennylane/devices/qubit/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def get_measurement_function(
return full_dot_products

backprop_mode = math.get_interface(state, *measurementprocess.obs.data) != "numpy"
if isinstance(measurementprocess.obs, (LinearCombination, Hamiltonian)):
if isinstance(measurementprocess.obs, (Hamiltonian, LinearCombination)):
# need to work out thresholds for when its faster to use "backprop mode" measurements
return sum_of_terms_method if backprop_mode else csr_dot_products

Expand Down
2 changes: 1 addition & 1 deletion pennylane/devices/qubit/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _group_measurements(mps: List[Union[SampleMeasurement, ClassicalShadowMP, Sh
elif mp.obs is None:
mp_no_obs.append(mp)
mp_no_obs_indices.append(i)
elif isinstance(mp.obs, (Sum, Hamiltonian, LinearCombination, SProd, Prod)):
elif isinstance(mp.obs, (Hamiltonian, Sum, SProd, Prod)):
# Sum, Hamiltonian, SProd, and Prod are treated as valid Pauli words, but
# aren't accepted in qml.pauli.group_observables
mp_other_obs.append([mp])
Expand Down
4 changes: 2 additions & 2 deletions pennylane/devices/qutrit_mixed/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import Callable
from string import ascii_letters as alphabet
from pennylane import math
from pennylane.ops import Sum, Hamiltonian, LinearCombination
from pennylane.ops import Sum, Hamiltonian
from pennylane.measurements import (
StateMeasurement,
MeasurementProcess,
Expand Down Expand Up @@ -262,7 +262,7 @@ def get_measurement_function(
if isinstance(measurementprocess, ExpectationMP):
# TODO add faster methods
# TODO add support for sparce Hamiltonians
if isinstance(measurementprocess.obs, (Hamiltonian, Sum, LinearCombination)):
if isinstance(measurementprocess.obs, (Hamiltonian, Sum)):
return calculate_expval_sum_of_terms
if measurementprocess.obs.has_matrix:
return calculate_expval
Expand Down
8 changes: 5 additions & 3 deletions pennylane/devices/qutrit_mixed/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import numpy as np
import pennylane as qml
from pennylane import math
from pennylane.ops import Sum, Hamiltonian
from pennylane.ops import Sum
from pennylane.measurements import (
Shots,
SampleMeasurement,
Expand Down Expand Up @@ -203,13 +203,15 @@ def _sum_for_single_shot(s):
)
)

if isinstance(mp.obs, Hamiltonian):
if isinstance(mp.obs, qml.ops.Hamiltonian):
# If Hamiltonian apply coefficients
return sum((c * res for c, res in zip(mp.obs.terms()[0], results)))

return sum(results)

if shots.has_partitioned_shots:
return tuple(_sum_for_single_shot(type(shots)(s)) for s in shots)

return _sum_for_single_shot(shots)


Expand Down Expand Up @@ -350,7 +352,7 @@ def measure_with_samples(
TensorLike[Any]: Sample measurement results
"""

if isinstance(mp, ExpectationMP) and isinstance(mp.obs, (Hamiltonian, Sum)):
if isinstance(mp, ExpectationMP) and isinstance(mp.obs, (qml.ops.Hamiltonian, Sum)):
measure_fn = _measure_sum_with_samples
else:
# measure with the usual method (rotate into the measurement basis)
Expand Down
2 changes: 1 addition & 1 deletion pennylane/gradients/gradient_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _try_zero_grad_from_graph_or_get_grad_method(tape, param_index, use_graph=Tr
# there is no influence of this operation on any of the observables
return "0"

return par_info["op"].grad_method
return getattr(par_info["op"], "grad_method", None)


def _find_gradient_methods(tape, trainable_param_indices, use_graph=True):
Expand Down
6 changes: 2 additions & 4 deletions pennylane/gradients/hadamard_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def _expval_hadamard_grad(tape, argnum, aux_wire):
obs_new = [qml.Z(i) for i in m.wires]

obs_new.append(qml.Y(aux_wire))
obs_new = qml.operation.Tensor(*obs_new)
obs_type = qml.prod if qml.operation.active_new_opmath() else qml.operation.Tensor
obs_new = obs_type(*obs_new)

if isinstance(m, qml.measurements.ExpectationMP):
measurements.append(qml.expval(op=obs_new))
Expand Down Expand Up @@ -460,9 +461,6 @@ def _get_generators(trainable_op):
elif isinstance(trainable_op, qml.Rot):
generators = [qml.Z(trainable_op.wires)]
coeffs = [-0.5]
elif isinstance(trainable_op, (qml.RX, qml.RY, qml.RZ)):
generators = [trainable_op.generator().base]
coeffs = [trainable_op.generator().scalar]
else:
generators = trainable_op.generator().ops
coeffs = trainable_op.generator().coeffs
Expand Down
12 changes: 8 additions & 4 deletions pennylane/gradients/hamiltonian_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ def hamiltonian_grad(tape, idx):
# get position in queue
queue_position = m_pos - len(tape.operations)
new_measurements = list(tape.measurements)
new_measurements[queue_position] = qml.expval(op.ops[p_idx])

new_parameters = [0 * d for d in op.data]
new_parameters[p_idx] = qml.math.ones_like(op.data[p_idx])
new_obs = qml.ops.functions.bind_new_parameters(op, new_parameters)
new_obs = qml.simplify(new_obs)

new_measurements[queue_position] = qml.expval(new_obs)

new_tape = qml.tape.QuantumScript(tape.operations, new_measurements, shots=tape.shots)

Expand All @@ -40,9 +46,7 @@ def processing_fn(results):
res = results[0][queue_position]
zeros = qml.math.zeros_like(res)

final = []
for i, _ in enumerate(tape.measurements):
final.append(res if i == queue_position else zeros)
final = [res if i == queue_position else zeros for i, _ in enumerate(tape.measurements)]

return qml.math.expand_dims(qml.math.stack(final), 0)

Expand Down
Loading
Loading