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

[labs.dla 4] Cartan decomposition #6392

Merged
merged 324 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
324 commits
Select commit Hold shift + click to select a range
3ba2c9b
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Oct 15, 2024
7c58575
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Oct 15, 2024
c55f947
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Oct 15, 2024
1526c93
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Oct 15, 2024
818f478
merge
Qottmann Oct 15, 2024
c001902
Add module docs for RTD gen
mlxd Oct 15, 2024
083a171
Downgrade deps for older doc build pipeline
mlxd Oct 15, 2024
79a7181
Merge branch 'labs_docs' of https://github.com/PennyLaneAI/pennylane …
Qottmann Oct 15, 2024
8f34ed0
labs level __init__
Qottmann Oct 15, 2024
db47bec
labs level __init__
Qottmann Oct 15, 2024
825ed0f
labs level __init__
Qottmann Oct 15, 2024
4e1a234
labs level __init__
Qottmann Oct 15, 2024
f6fd337
add docstring to submodule
Qottmann Oct 15, 2024
5d83505
labs level __init__
Qottmann Oct 15, 2024
c41e240
Merge branch 'master' into labs_docs
mlxd Oct 15, 2024
976b894
Merge branch 'labs_docs' of https://github.com/PennyLaneAI/pennylane …
Qottmann Oct 16, 2024
c216518
Change autosummary rules for labs page
mlxd Oct 16, 2024
94ca5a6
Change autosummary rules for labs page
mlxd Oct 16, 2024
64f553c
Merge branch 'master' into labs_docs
mlxd Oct 16, 2024
0afc0de
Update CL
mlxd Oct 16, 2024
74152c9
Merge branch 'labs_docs' of github.com:PennyLaneAI/pennylane into lab…
mlxd Oct 16, 2024
2d70ef5
Merge branch 'labs_docs' of https://github.com/PennyLaneAI/pennylane …
Qottmann Oct 16, 2024
3d5fd72
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Oct 16, 2024
17cd42f
docs
Qottmann Oct 16, 2024
bd44249
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Oct 16, 2024
e3b3e85
docs
Qottmann Oct 16, 2024
284075d
Merge branch 'master' into lie_closure_dense
dwierichs Oct 23, 2024
9fbf345
Merge branch 'master' into lie_closure_dense
dwierichs Oct 23, 2024
e45e9ab
Add temporary CI additions for labs tests
mlxd Oct 23, 2024
0786ac8
Undo CI additions
mlxd Oct 23, 2024
d64018d
Update config
mlxd Oct 23, 2024
69d9536
Fix cf
mlxd Oct 23, 2024
38c1b69
-a
dwierichs Oct 23, 2024
7098272
lint
dwierichs Oct 23, 2024
26d8811
merge
Qottmann Oct 24, 2024
6b1a15f
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Oct 24, 2024
9ee2b5b
merge
Qottmann Oct 24, 2024
6d2b460
Simple module test
mlxd Oct 24, 2024
0830835
Merge branch 'master' into add_tmp_labs_ci
mlxd Oct 24, 2024
3a207a3
pylint
Qottmann Oct 24, 2024
37286b2
Update pylint rules
mlxd Oct 24, 2024
47cdc8f
Merge branch 'add_tmp_labs_ci' of github.com:PennyLaneAI/pennylane in…
mlxd Oct 24, 2024
6459764
Merge branch 'add_tmp_labs_ci' of https://github.com/PennyLaneAI/penn…
Qottmann Oct 24, 2024
7efdf42
Merge branch 'master' into add_tmp_labs_ci
mlxd Oct 24, 2024
9c7c174
custom pylint file for labs
mlxd Oct 24, 2024
e22709a
sphinx complaints
Qottmann Oct 24, 2024
8ba2d4e
sphinx complaints
Qottmann Oct 24, 2024
e463b7e
indentation
dwierichs Oct 25, 2024
2e414ea
Add labs import fixture
mlxd Oct 25, 2024
e6b4132
Update pennylane/labs/tests/pytest.ini
mlxd Oct 28, 2024
3ca7d8c
Update pennylane/labs/tests/conftest.py
mlxd Oct 28, 2024
2880b05
Update pennylane/labs/tests/test_dummy.py
mlxd Oct 28, 2024
d5aeb01
allow list input
Qottmann Oct 28, 2024
1a5301b
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Oct 28, 2024
84c25d4
Merge branch 'add_tmp_labs_ci' of https://github.com/PennyLaneAI/penn…
Qottmann Oct 29, 2024
b5f3028
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Oct 29, 2024
ec11734
merge
Qottmann Oct 29, 2024
9f992ab
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Oct 29, 2024
93c875d
typo
Qottmann Oct 29, 2024
66ee6c0
rebase and merge
Qottmann Nov 8, 2024
0a54609
merge
Qottmann Nov 8, 2024
d49a324
remove test dummy
Qottmann Nov 8, 2024
5336f69
merge again?
Qottmann Nov 11, 2024
d8a2119
merge
Qottmann Nov 11, 2024
4f37503
new branch
Qottmann Nov 11, 2024
0e2b005
remove dense util (pushed upstream)
Qottmann Nov 11, 2024
e47d623
remove slow test
Qottmann Nov 11, 2024
3d9e7a4
merge§
Qottmann Nov 11, 2024
43211f2
merge
Qottmann Nov 11, 2024
a4b9b18
merge
Qottmann Nov 11, 2024
30c18d2
merge
Qottmann Nov 11, 2024
6fbfd17
merge
Qottmann Nov 11, 2024
dedd478
merge
Qottmann Nov 11, 2024
2b53dff
merge
Qottmann Nov 11, 2024
b8f20da
merge
Qottmann Nov 11, 2024
e6bb7ce
move entry in changelog
Qottmann Nov 11, 2024
21415f3
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Nov 11, 2024
fcdab65
changelog
Qottmann Nov 11, 2024
4a9e481
typo
Qottmann Nov 11, 2024
be97239
typo
Qottmann Nov 11, 2024
e1e080c
typo
Qottmann Nov 11, 2024
f642216
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 11, 2024
0599554
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Nov 11, 2024
f5371d7
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 11, 2024
6bcdb25
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 13, 2024
93b2810
changelog
Qottmann Nov 14, 2024
75e5e14
subbasis_length
Qottmann Nov 14, 2024
a2af092
mathfrak g
Qottmann Nov 14, 2024
05b3e5b
typing
Qottmann Nov 14, 2024
dbe4c4e
Apply suggestions from code review
Qottmann Nov 14, 2024
bf97ba2
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Nov 14, 2024
b5d84f6
comment contract
Qottmann Nov 14, 2024
b336010
Merge branch 'lie_closure_dense' of https://github.com/PennyLaneAI/pe…
Qottmann Nov 14, 2024
b92163d
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 14, 2024
a88db10
Apply suggestions from code review
Qottmann Nov 14, 2024
633589f
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 14, 2024
6132e51
update normalization
Qottmann Nov 14, 2024
50b7a93
orthonormalize function
Qottmann Nov 14, 2024
b5f4137
orthonormalize
Qottmann Nov 14, 2024
6903eff
add example from code review
Qottmann Nov 14, 2024
c03afe1
trace inner product
Qottmann Nov 14, 2024
b3bf572
consistency checks
Qottmann Nov 14, 2024
cf92b3c
trace inner product in test
Qottmann Nov 14, 2024
235acdc
Merge branch 'master' into lie_closure_dense
dwierichs Nov 14, 2024
ad9cbdd
Merge branch 'lie_closure_dense' into dense_util
dwierichs Nov 14, 2024
d5d9add
Merge branch 'dense_util' into structure_constants_dense
dwierichs Nov 14, 2024
90f62c8
merge
dwierichs Nov 14, 2024
61309e2
is_orthogonal in qml.structure_constants. tests. changelog
dwierichs Nov 14, 2024
c7006f7
indent
dwierichs Nov 14, 2024
2b60e0b
Merge branch 'dense_util' into structure_constants_dense
dwierichs Nov 14, 2024
9bbe666
Merge branch 'structure_constants_dense' into cartan
dwierichs Nov 14, 2024
04b6780
extend tests, slight polish of methods
dwierichs Nov 14, 2024
6d7662c
fix normalization in `structure_constants_dense` and its tests
dwierichs Nov 14, 2024
c8714b5
Merge branch 'structure_constants_dense' into cartan
dwierichs Nov 14, 2024
35a786c
adjvec_to_op, op_to_adjvec, tests for both
dwierichs Nov 15, 2024
fd19da5
add change_basis_ad_rep. tmp!
dwierichs Nov 15, 2024
bebb44f
addition completed
dwierichs Nov 15, 2024
1f69a90
Merge branch 'structure_constants_dense' into cartan
dwierichs Nov 15, 2024
0b886ad
fix validation
dwierichs Nov 15, 2024
ee1cbfe
Merge branch 'dense_util' into structure_constants_dense
dwierichs Nov 15, 2024
2e6ece7
Merge branch 'structure_constants_dense' into cartan
dwierichs Nov 15, 2024
191c7b6
merge
Qottmann Nov 15, 2024
258c607
merge
Qottmann Nov 15, 2024
a602170
merge
Qottmann Nov 15, 2024
f8b2183
merge
Qottmann Nov 15, 2024
86f114d
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 18, 2024
0334aa5
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 18, 2024
3a9e62a
merge
Qottmann Nov 18, 2024
95a9c6c
Merge branch 'cartan' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 18, 2024
1dc3bf0
update normalization strategy and tests
dwierichs Nov 18, 2024
92e0bf7
Merge branch 'dense_util' of github.com:PennyLaneAI/pennylane into de…
dwierichs Nov 18, 2024
6655565
merge
dwierichs Nov 18, 2024
7113c51
trace inner product
dwierichs Nov 18, 2024
75bb9eb
use tip
dwierichs Nov 18, 2024
5f783d9
merge
dwierichs Nov 18, 2024
6e7c550
Merge branch 'structure_constants_dense' into cartan
dwierichs Nov 18, 2024
f27f922
move changes from atop down
Qottmann Nov 18, 2024
cde24bf
move downwards
Qottmann Nov 18, 2024
fecadb0
move down
Qottmann Nov 18, 2024
dcfe8f6
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 18, 2024
0100842
update init
Qottmann Nov 18, 2024
8c956d8
merge
Qottmann Nov 18, 2024
1870c86
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 18, 2024
e24fcec
move test down
Qottmann Nov 18, 2024
1077845
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 18, 2024
653e073
Merge branch 'cartan' of github.com:PennyLaneAI/pennylane into cartan
dwierichs Nov 18, 2024
5844740
pauli coefficients docs
Qottmann Nov 20, 2024
eef3ab7
docs trace inner product
Qottmann Nov 20, 2024
0e4972d
adjvec docs
Qottmann Nov 20, 2024
eec1ba2
real outputs.
dwierichs Nov 20, 2024
c155ae8
Merge branch 'dense_util' of github.com:PennyLaneAI/pennylane into de…
dwierichs Nov 20, 2024
418b6e2
Merge branch 'dense_util' into structure_constants_dense
dwierichs Nov 20, 2024
2a4a607
Merge branch 'structure_constants_dense' into cartan
dwierichs Nov 20, 2024
9a6de29
update doc
Qottmann Nov 22, 2024
3085335
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 22, 2024
c07d3b0
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 22, 2024
5464d66
docs typo
Qottmann Nov 22, 2024
eb5dd29
Apply suggestions from code review
Qottmann Nov 24, 2024
65fd3d2
Merge branch 'master' into dense_util
Qottmann Nov 24, 2024
14773a8
changelog cleanup
Qottmann Nov 25, 2024
8f9dcc6
Apply suggestions from code review
Qottmann Nov 25, 2024
2313c50
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 25, 2024
d9246a9
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 25, 2024
f43b29e
revert change
Qottmann Nov 25, 2024
46ba1fa
fix bug
Qottmann Nov 25, 2024
c2c393c
docs
Qottmann Nov 25, 2024
0986eb0
broadcasting example
Qottmann Nov 25, 2024
d2d6cc1
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 25, 2024
aee02f1
bugfix
Qottmann Nov 25, 2024
91ed6ff
changelog
Qottmann Nov 25, 2024
7b7666b
changelog
Qottmann Nov 25, 2024
385bbe7
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 25, 2024
f8a5362
changelog
Qottmann Nov 25, 2024
c7e609b
improve and comment test cases
dwierichs Nov 25, 2024
b3bca16
trace inner product
Qottmann Nov 25, 2024
ff32011
lexicographic ordering
Qottmann Nov 25, 2024
6178002
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 25, 2024
2e02997
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 25, 2024
ab43fdd
batched_pauli_decompose
Qottmann Nov 25, 2024
f8f5aab
batched_pauli_decompose
Qottmann Nov 25, 2024
f7e0ece
merge
Qottmann Nov 25, 2024
6e9f829
merge
Qottmann Nov 25, 2024
1a2d9a4
merge
Qottmann Nov 25, 2024
4b9827e
Merge branch 'cartan' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 25, 2024
83453b2
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 25, 2024
4b59086
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 26, 2024
425ea80
Apply suggestions from code review
Qottmann Nov 26, 2024
97faf7e
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 26, 2024
97aab77
batched search and replace fix
Qottmann Nov 26, 2024
24c20de
merge
Qottmann Nov 26, 2024
796c7b1
Apply suggestions from code review
Qottmann Nov 26, 2024
c7e0952
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 26, 2024
8db9fa0
Update pennylane/labs/dla/dense_util.py
Qottmann Nov 26, 2024
afa6d1e
revert change
Qottmann Nov 26, 2024
c95cdf7
developer comments
Qottmann Nov 26, 2024
7d2ebdb
change basis ad rep doc
Qottmann Nov 26, 2024
c8e2945
trigger
Qottmann Nov 26, 2024
4d850a9
Merge branch 'dense_util' of https://github.com/PennyLaneAI/pennylane…
Qottmann Nov 26, 2024
ce17212
merge
Qottmann Nov 26, 2024
9212a4e
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 26, 2024
33cff82
examples
Qottmann Nov 26, 2024
817d641
examples
Qottmann Nov 26, 2024
aa8db33
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 26, 2024
aae5ebd
Merge branch 'master' into structure_constants_dense
dwierichs Nov 26, 2024
7cdc9e7
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 28, 2024
27e9095
merge fix: remove 2nd utility functions section
Qottmann Nov 28, 2024
c3b054d
Merge branch 'structure_constants_dense' of https://github.com/PennyL…
Qottmann Nov 28, 2024
47d77d0
merge
Qottmann Nov 28, 2024
2a9bfa3
changelog
Qottmann Nov 28, 2024
8adad1e
docstrings
Qottmann Nov 28, 2024
371ea4c
examples
Qottmann Nov 28, 2024
c806255
examples
Qottmann Nov 28, 2024
bf7a0d3
examples
Qottmann Nov 28, 2024
fafff4c
check cartan tools
Qottmann Nov 28, 2024
bac343a
examples
Qottmann Nov 28, 2024
74126ff
init
Qottmann Nov 28, 2024
f354062
examples
Qottmann Nov 28, 2024
d5c2deb
examples
Qottmann Nov 28, 2024
ef1d6fe
examples
Qottmann Nov 28, 2024
fd7e6f5
changelog
Qottmann Nov 28, 2024
17da10a
sphinx
Qottmann Nov 28, 2024
1cd3c79
trailing whitespaces
Qottmann Nov 28, 2024
bb73946
Apply suggestions from code review
Qottmann Nov 29, 2024
33c0bb9
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 29, 2024
bc6103e
fix test
Qottmann Nov 29, 2024
545dbc2
cartan_decompisition -> cartan_decomp
Qottmann Nov 29, 2024
7a9b58a
changelog
Qottmann Nov 29, 2024
acb2ea5
doc
Qottmann Nov 29, 2024
3db0324
early exit check_commutation
Qottmann Nov 29, 2024
6cc9b2b
add test for check_cartan_decomp
Qottmann Nov 29, 2024
4adbd64
remove simple Lie algebra
Qottmann Nov 29, 2024
ec35567
remove align
Qottmann Nov 29, 2024
1fe256b
Update pennylane/labs/dla/cartan.py
Qottmann Nov 29, 2024
3173061
Merge branch 'cartan' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 29, 2024
49b4c0c
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Nov 29, 2024
eb8ea9e
fix latex
Qottmann Nov 29, 2024
5afd23c
Apply suggestions from code review
Qottmann Nov 29, 2024
69c6e59
[ci skip]
Qottmann Nov 29, 2024
68aff6c
doc
Qottmann Nov 29, 2024
98f09ca
type hints
Qottmann Nov 29, 2024
2e9c9a2
type hints
Qottmann Nov 29, 2024
28436fe
type hints
Qottmann Nov 29, 2024
8e7b901
docs warnings
Qottmann Nov 29, 2024
a897914
type hints
Qottmann Nov 29, 2024
13545de
Merge branch 'master' into cartan
Qottmann Dec 4, 2024
2f9bc9a
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Dec 4, 2024
40150ee
fix sphinx
Qottmann Dec 4, 2024
b3a5337
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
Qottmann Dec 5, 2024
b0cbfa4
return doc cartan_decomp
Qottmann Dec 5, 2024
a2f2cf5
docs
Qottmann Dec 5, 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
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@

* Added utility functions for handling dense matrices in the Lie theory context.
[(#6563)](https://github.com/PennyLaneAI/pennylane/pull/6563)
[(#6392)](https://github.com/PennyLaneAI/pennylane/pull/6392)

* Added a ``cartan_decomp`` function along with two standard involutions ``even_odd_involution`` and ``concurrence_involution``.
[(#6392)](https://github.com/PennyLaneAI/pennylane/pull/6392)

* Added `unary_mapping()` function to map `BoseWord` and `BoseSentence` to qubit operators, using unary mapping
[(#6576)](https://github.com/PennyLaneAI/pennylane/pull/6576);
Expand Down
19 changes: 19 additions & 0 deletions pennylane/labs/dla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

~lie_closure_dense
~structure_constants_dense
~cartan_decomp


Utility functions
Expand All @@ -35,17 +36,32 @@
~adjvec_to_op
~change_basis_ad_rep
~check_orthonormal
~check_commutation
~check_all_commuting
~check_cartan_decomp
~op_to_adjvec
~orthonormalize
~pauli_coefficients
~batched_pauli_decompose
~trace_inner_product

Involutions
~~~~~~~~~~~

.. currentmodule:: pennylane.labs.dla

.. autosummary::
:toctree: api

~even_odd_involution
~concurrence_involution


"""

from .lie_closure_dense import lie_closure_dense
from .structure_constants_dense import structure_constants_dense
from .cartan import cartan_decomp, even_odd_involution, concurrence_involution
from .dense_util import (
change_basis_ad_rep,
pauli_coefficients,
Expand All @@ -55,4 +71,7 @@
trace_inner_product,
adjvec_to_op,
op_to_adjvec,
check_commutation,
check_all_commuting,
check_cartan_decomp,
)
253 changes: 253 additions & 0 deletions pennylane/labs/dla/cartan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
# Copyright 2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Functionality for Cartan decomposition"""
from functools import singledispatch
from typing import List, Tuple, Union

import numpy as np

import pennylane as qml
from pennylane import Y
from pennylane.operation import Operator
from pennylane.pauli import PauliSentence


def cartan_decomp(
g: List[Union[PauliSentence, Operator]], involution: callable
) -> Tuple[List[Union[PauliSentence, Operator]], List[Union[PauliSentence, Operator]]]:
r"""Cartan Decomposition :math:`\mathfrak{g} = \mathfrak{k} \oplus \mathfrak{m}`.

Given a Lie algebra :math:`\mathfrak{g}`, the Cartan decomposition is a decomposition
:math:`\mathfrak{g} = \mathfrak{k} \oplus \mathfrak{m}` into orthogonal complements.
This is realized by an involution :math:`\Theta(g)` that maps each operator :math:`g \in \mathfrak{g}`
back to itself after two consecutive applications, i.e., :math:`\Theta(\Theta(g)) = g \ \forall g \in \mathfrak{g}`.

The ``involution`` argument can be any function that maps the operators in the provided ``g`` to a boolean output.
``True`` for operators that go into :math:`\mathfrak{k}` and ``False`` for operators in :math:`\mathfrak{m}`.

The resulting subspaces fulfill the Cartan commutation relations

.. math:: [\mathfrak{k}, \mathfrak{k}] \subseteq \mathfrak{k} \text{ ; } [\mathfrak{k}, \mathfrak{m}] \subseteq \mathfrak{m} \text{ ; } [\mathfrak{m}, \mathfrak{m}] \subseteq \mathfrak{k}

Args:
g (List[Union[PauliSentence, Operator]]): the (dynamical) Lie algebra to decompose
involution (callable): Involution function :math:`\Theta(\cdot)` to act on the input operator, should return ``0/1`` or ``False/True``.
E.g., :func:`~even_odd_involution` or :func:`~concurrence_involution`.

Returns:
Tuple(List[Union[PauliSentence, Operator]], List[Union[PauliSentence, Operator]]): Tuple ``(k, m)`` containing the even
parity subspace :math:`\Theta(\mathfrak{k}) = \mathfrak{k}` and the odd
parity subspace :math:`\Theta(\mathfrak{m}) = -\mathfrak{m}`.

.. seealso:: :func:`~even_odd_involution`, :func:`~concurrence_involution`, :func:`~check_cartan_decomp`
dwierichs marked this conversation as resolved.
Show resolved Hide resolved

**Example**

We first construct a Lie algebra.

>>> from pennylane import X, Z
>>> from pennylane.labs.dla import concurrence_involution, even_odd_involution, cartan_decomp
>>> generators = [X(0) @ X(1), Z(0), Z(1)]
>>> g = qml.lie_closure(generators)
>>> g
[X(0) @ X(1),
Z(0),
Z(1),
-1.0 * (Y(0) @ X(1)),
-1.0 * (X(0) @ Y(1)),
-1.0 * (Y(0) @ Y(1))]

We compute the Cartan decomposition with respect to the :func:`~concurrence_involution`.

>>> k, m = cartan_decomp(g, concurrence_involution)
>>> k, m
([-1.0 * (Y(0) @ X(1)), -1.0 * (X(0) @ Y(1))],
[X(0) @ X(1), Z(0), Z(1), -1.0 * (Y(0) @ Y(1))])

We can check the validity of the decomposition using :func:`~check_cartan_decomp`.

>>> check_cartan_decomp(k, m)
True

There are other Cartan decomposition induced by other involutions. For example using :func:`~even_odd_involution`.

>>> from pennylane.labs.dla import check_cartan_decomp
>>> k, m = cartan_decomp(g, even_odd_involution)
Qottmann marked this conversation as resolved.
Show resolved Hide resolved
>>> k, m
([Z(0), Z(1)],
[X(0) @ X(1),
-1.0 * (Y(0) @ X(1)),
-1.0 * (X(0) @ Y(1)),
-1.0 * (Y(0) @ Y(1))])
>>> check_cartan_decomp(k, m)
True
"""
# simple implementation assuming all elements in g are already either in k and m
# TODO: Figure out more general way to do this when the above is not the case
m = []
k = []

for op in g:
if involution(op): # odd parity
k.append(op)
else: # even parity
m.append(op)

return k, m


# dispatch to different input types
def even_odd_involution(op: Union[PauliSentence, np.ndarray, Operator]) -> bool:
r"""The Even-Odd involution

This is defined in `quant-ph/0701193 <https://arxiv.org/pdf/quant-ph/0701193>`__.
For Pauli words and sentences, it comes down to counting non-trivial Paulis in Pauli words.

Args:
op ( Union[PauliSentence, np.ndarray, Operator]): Input operator

Returns:
bool: Boolean output ``True`` or ``False`` for odd (:math:`\mathfrak{k}`) and even parity subspace (:math:`\mathfrak{m}`), respectively

.. seealso:: :func:`~cartan_decomp`

**Example**

>>> from pennylane import X, Y, Z
>>> from pennylane.labs.dla import even_odd_involution
>>> ops = [X(0), X(0) @ Y(1), X(0) @ Y(1) @ Z(2)]
>>> [even_odd_involution(op) for op in ops]
[True, False, True]

Operators with an odd number of non-identity Paulis yield ``1``, whereas even ones yield ``0``.

The function also works with dense matrix representations.

>>> ops_m = [qml.matrix(op, wire_order=range(3)) for op in ops]
>>> [even_odd_involution(op_m) for op_m in ops_m]
[True, False, True]

"""
return _even_odd_involution(op)


@singledispatch
def _even_odd_involution(op): # pylint:disable=unused-argument
return NotImplementedError(f"Involution not defined for operator {op} of type {type(op)}")


@_even_odd_involution.register(PauliSentence)
def _even_odd_involution_ps(op: PauliSentence):
# Generalization to sums of Paulis: check each term and assert they all have the same parity
parity = []
for pw in op.keys():
parity.append(len(pw) % 2)

# only makes sense if parity is the same for all terms, e.g. Heisenberg model
assert all(
parity[0] == p for p in parity
), f"The Even-Odd involution is not well-defined for operator {op} as individual terms have different parity"
return bool(parity[0])


@_even_odd_involution.register(np.ndarray)
def _even_odd_involution_matrix(op: np.ndarray):
"""see Table CI in https://arxiv.org/abs/2406.04418"""
n = int(np.round(np.log2(op.shape[-1])))
YYY = qml.prod(*[Y(i) for i in range(n)])
YYY = qml.matrix(YYY, range(n))

transformed = YYY @ op.conj() @ YYY
if np.allclose(transformed, op):
return False
if np.allclose(transformed, -op):
return True
raise ValueError(f"The Even-Odd involution is not well-defined for operator {op}.")


@_even_odd_involution.register(Operator)
def _even_odd_involution_op(op: Operator):
"""use pauli representation"""
return _even_odd_involution_ps(op.pauli_rep)


# dispatch to different input types
def concurrence_involution(op: Union[PauliSentence, np.ndarray, Operator]) -> bool:
r"""The Concurrence Canonical Decomposition :math:`\Theta(g) = -g^T` as a Cartan involution function

This is defined in `quant-ph/0701193 <https://arxiv.org/pdf/quant-ph/0701193>`__.
For Pauli words and sentences, it comes down to counting Pauli-Y operators.

Args:
op ( Union[PauliSentence, np.ndarray, Operator]): Input operator

Returns:
bool: Boolean output ``True`` or ``False`` for odd (:math:`\mathfrak{k}`) and even parity subspace (:math:`\mathfrak{m}`), respectively

.. seealso:: :func:`~cartan_decomp`

**Example**

>>> from pennylane import X, Y, Z
>>> from pennylane.labs.dla import concurrence_involution
>>> ops = [X(0), X(0) @ Y(1), X(0) @ Y(1) @ Z(2), Y(0) @ Y(2)]
>>> [concurrence_involution(op) for op in ops]
[False, True, True, False]

Operators with an odd number of ``Y`` operators yield ``1``, whereas even ones yield ``0``.

The function also works with dense matrix representations.

>>> ops_m = [qml.matrix(op, wire_order=range(3)) for op in ops]
>>> [even_odd_involution(op_m) for op_m in ops_m]
[False, True, True, False]

"""
return _concurrence_involution(op)


@singledispatch
def _concurrence_involution(op):
return NotImplementedError(f"Involution not defined for operator {op} of type {type(op)}")


@_concurrence_involution.register(PauliSentence)
def _concurrence_involution_pauli(op: PauliSentence):
# Generalization to sums of Paulis: check each term and assert they all have the same parity
parity = []
for pw in op.keys():
result = sum(1 if el == "Y" else 0 for el in pw.values())
parity.append(result % 2)

# only makes sense if parity is the same for all terms, e.g. Heisenberg model
assert all(
parity[0] == p for p in parity
), f"The concurrence canonical decomposition is not well-defined for operator {op} as individual terms have different parity"
return bool(parity[0])


@_concurrence_involution.register(Operator)
def _concurrence_involution_operator(op: Operator):
return _concurrence_involution_matrix(op.matrix())


@_concurrence_involution.register(np.ndarray)
def _concurrence_involution_matrix(op: np.ndarray):
if np.allclose(op, -op.T):
return True
if np.allclose(op, op.T):
return False
raise ValueError(
f"The concurrence canonical decomposition is not well-defined for operator {op}"
)
Loading
Loading