Skip to content

Commit b66c675

Browse files
authored
Merge pull request #104 from qutech/py313
Add python 3.13 compatibility
2 parents 1dba77b + 0ccd88d commit b66c675

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python_version: ['3.9', '3.10', '3.11', '3.12']
14+
python_version: ['3.9', '3.10', '3.11', '3.12', '3.13']
1515
install_extras: ['tests', 'plotting,fancy_progressbar,tests', 'plotting,bloch_sphere_visualization,fancy_progressbar,doc,tests']
1616

1717
steps:

filter_functions/superoperator.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import numpy as np
4343
from numpy import linalg as nla
4444
from numpy import ndarray
45+
from scipy import linalg as sla
4546

4647
from . import basis as _b
4748

@@ -181,7 +182,7 @@ def liouville_is_CP(
181182
"""
182183

183184
choi = liouville_to_choi(superoperator, basis)
184-
D, V = nla.eigh(choi)
185+
D, V = _robust_eigh(choi)
185186

186187
CP = (D >= -(atol or basis._atol)).all(axis=-1)
187188

@@ -254,11 +255,31 @@ def liouville_is_cCP(
254255
Q = np.eye(Omega.shape[-1]) - Omega
255256

256257
choi = liouville_to_choi(superoperator, basis)
257-
D, V = nla.eigh(Q @ choi @ Q)
258+
D, V = _robust_eigh(Q @ choi @ Q)
258259

259260
cCP = (D >= -(atol or basis._atol)).all(axis=-1)
260261

261262
if return_eig:
262263
return cCP, (D, V)
263264

264265
return cCP
266+
267+
268+
def _robust_eigh(a: ndarray) -> Tuple[ndarray, ndarray]:
269+
"""Try computing the eigenvalue decomposition using numpy's
270+
vectorized but less robust (uses heevd driver) function and if it
271+
fails resort to scipy's using the heevr driver."""
272+
try:
273+
D, V = nla.eigh(a)
274+
except nla.LinAlgError:
275+
shp = a.shape[:-2]
276+
if a.ndim == 2:
277+
a.shape = (1,) + a.shape
278+
elif a.ndim > 3:
279+
a.shape = (-1,) + a.shape[-2:]
280+
281+
D, V = map(np.array, zip(*(sla.eigh(c, driver='evr') for c in a)))
282+
D.shape = shp + D.shape[-1:]
283+
V.shape = shp + V.shape[-2:]
284+
285+
return D, V

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
"Programming Language :: Python :: 3.10",
2020
"Programming Language :: Python :: 3.11",
2121
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
2223
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
2324
"Operating System :: OS Independent",
2425
"Topic :: Scientific/Engineering :: Physics",

0 commit comments

Comments
 (0)