quadlib 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {quadlib-0.1.0 → quadlib-0.1.1}/CITATION.cff +3 -3
  2. {quadlib-0.1.0 → quadlib-0.1.1}/PKG-INFO +2 -2
  3. {quadlib-0.1.0 → quadlib-0.1.1}/README.md +1 -1
  4. {quadlib-0.1.0 → quadlib-0.1.1}/pyproject.toml +1 -1
  5. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/__init__.py +7 -1
  6. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/expdvr.py +10 -9
  7. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/hodvr.py +23 -3
  8. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/propagation/exact.py +3 -1
  9. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/propagation/integrators.py +3 -1
  10. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib.egg-info/PKG-INFO +2 -2
  11. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib.egg-info/SOURCES.txt +1 -0
  12. quadlib-0.1.1/tests/test_dvr.py +47 -0
  13. {quadlib-0.1.0 → quadlib-0.1.1}/HEADER +0 -0
  14. {quadlib-0.1.0 → quadlib-0.1.1}/LICENSE +0 -0
  15. {quadlib-0.1.0 → quadlib-0.1.1}/MANIFEST.in +0 -0
  16. {quadlib-0.1.0 → quadlib-0.1.1}/setup.cfg +0 -0
  17. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/__init__.py +0 -0
  18. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/boson.py +0 -0
  19. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/discrete.py +0 -0
  20. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/jbasis.py +0 -0
  21. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/sindvr.py +0 -0
  22. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/basis/spin.py +0 -0
  23. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/cli/__init__.py +0 -0
  24. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/cli/qlb_offset_oper_dof.py +0 -0
  25. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/experimental/__init__.py +0 -0
  26. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/experimental/cpd_eom.py +0 -0
  27. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/experimental/mctdh.py +0 -0
  28. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/experimental/node.py +0 -0
  29. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/experimental/pdof.py +0 -0
  30. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/experimental/tree.py +0 -0
  31. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/hdmctdh/__init__.py +0 -0
  32. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/hdmctdh/rundirectory.py +0 -0
  33. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/legacy/__init__.py +0 -0
  34. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/legacy/math.py +0 -0
  35. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/operator/sop.py +0 -0
  36. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/propagation/__init__.py +0 -0
  37. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/propagation/cpd.py +0 -0
  38. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/__init__.py +0 -0
  39. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/bath.py +0 -0
  40. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/constants.py +0 -0
  41. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/iterators.py +0 -0
  42. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/linalg.py +0 -0
  43. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/pulses.py +0 -0
  44. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/spectra.py +0 -0
  45. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/tools/tensor.py +0 -0
  46. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/wavefunction/__init__.py +0 -0
  47. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/wavefunction/wfn_cpd.py +0 -0
  48. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib/wavefunction/wfn_exact.py +0 -0
  49. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib.egg-info/dependency_links.txt +0 -0
  50. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib.egg-info/entry_points.txt +0 -0
  51. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib.egg-info/requires.txt +0 -0
  52. {quadlib-0.1.0 → quadlib-0.1.1}/src/quadlib.egg-info/top_level.txt +0 -0
  53. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_cli.py +0 -0
  54. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_cpd.py +0 -0
  55. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_exact.py +0 -0
  56. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_integrate.py +0 -0
  57. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_linalg.py +0 -0
  58. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_simdiag.py +0 -0
  59. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_sindvr.py +0 -0
  60. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_sop.py +0 -0
  61. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_spectra.py +0 -0
  62. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_spin_boson.py +0 -0
  63. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_tensor.py +0 -0
  64. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_tree.py +0 -0
  65. {quadlib-0.1.0 → quadlib-0.1.1}/tests/test_wfn_exact.py +0 -0
@@ -21,6 +21,6 @@ abstract: >-
21
21
  research, development, and educational use and builds on
22
22
  established numerical libraries.
23
23
  license: MIT
24
- # version and date-released are stamped at release time by tools/publish.sh
25
- version: 0.1.0
26
- date-released: '2026-10-06'
24
+ # version and date-released are stamped at release time by tools/make-release.sh
25
+ version: 0.1.1
26
+ date-released: '2026-11-09'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quadlib
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: QuaDLib: Quantum Dynamics Library for Research, Development and Education
5
5
  Author-email: Oriol Vendrell <oriol.vendrell@uni-heidelberg.de>, Sudip Sasmal <sudipsasmal.chem@gmail.com>
6
6
  License-Expression: MIT
@@ -103,7 +103,7 @@ pip install -e ".[plot,dev]" # dev adds pytest and ruff
103
103
  or a specific release without cloning:
104
104
 
105
105
  ```bash
106
- pip install git+https://gitlab.com/tc-heidelberg/quadlib.git@v0.1.0
106
+ pip install git+https://gitlab.com/tc-heidelberg/quadlib.git@v0.1.1
107
107
  ```
108
108
 
109
109
  ## Tests and examples
@@ -65,7 +65,7 @@ pip install -e ".[plot,dev]" # dev adds pytest and ruff
65
65
  or a specific release without cloning:
66
66
 
67
67
  ```bash
68
- pip install git+https://gitlab.com/tc-heidelberg/quadlib.git@v0.1.0
68
+ pip install git+https://gitlab.com/tc-heidelberg/quadlib.git@v0.1.1
69
69
  ```
70
70
 
71
71
  ## Tests and examples
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "quadlib"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "QuaDLib: Quantum Dynamics Library for Research, Development and Education"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -36,6 +36,11 @@ class DVRBasis(Basis, Protocol):
36
36
 
37
37
  All array attributes are real unless otherwise noted.
38
38
 
39
+ With FBR functions chi_n and DVR amplitudes psi_dvr[a] = sqrt(w_a) psi(x_a),
40
+ the transformation is u[n, a] = conj(chi_n(x_a)) sqrt(w_a): the FBR index
41
+ comes first, c_fbr = u @ psi_dvr and psi_dvr = u^+ @ c_fbr. u is unitary;
42
+ it is real for Sindvr and HOdvr and complex for Expdvr (plane waves).
43
+
39
44
  Attributes
40
45
  ----------
41
46
  x : ndarray of shape (n,)
@@ -49,7 +54,8 @@ class DVRBasis(Basis, Protocol):
49
54
  dq2 : ndarray of shape (n, n)
50
55
  Second-derivative matrix in the DVR basis.
51
56
  u : ndarray of shape (n, n)
52
- FBR → DVR transformation matrix.
57
+ Unitary FBR/DVR transformation, u[n, a] = conj(chi_n(x_a)) sqrt(w_a);
58
+ c_fbr = u @ psi_dvr (see above).
53
59
  """
54
60
 
55
61
  x: np.ndarray
@@ -5,6 +5,10 @@ class Expdvr:
5
5
  """
6
6
  Exp DVR (plane wave) basis.
7
7
 
8
+ Periodic grid x_a = x0 + a L/N, a = 0..N-1 (N odd), FBR functions
9
+ chi_m(x) = exp(i k_m (x - x0)) / sqrt(L), k_m = 2 pi m / L,
10
+ m = -(N-1)/2 .. (N-1)/2. The transformation u is complex:
11
+ u[m, a] = conj(chi_m(x_a)) sqrt(w_a), so c = u @ psi_dvr.
8
12
  """
9
13
 
10
14
  def __init__(self, N, x0=0, L=2*np.pi):
@@ -39,15 +43,12 @@ def _dx(N, L):
39
43
 
40
44
 
41
45
  def _calcumat(N, x0, L):
42
- U = np.zeros((N, N), float)
43
- X = np.zeros(N, float)
44
- dx = L/N
45
- N1 = N + 1
46
- fac = np.sqrt(2.0/(N + 1))
47
- for j in range(N):
48
- X[j] = x0 + j*dx
49
- for a in range(N):
50
- U[j, a] = fac*np.sin(j*a*np.pi/N1)
46
+ """Grid and FBR <-> DVR transformation, u[m, a] = conj(chi_m(x_a)) sqrt(L/N)
47
+ with the plane waves chi_m(x) = exp(i k_m (x - x0)) / sqrt(L), k_m = 2 pi m / L,
48
+ m = -(N-1)/2 .. (N-1)/2 (unitary; u @ dq2 @ u^+ = diag(-k_m^2))."""
49
+ X = x0 + np.arange(N)*L/N
50
+ k = 2*np.pi/L*np.arange(-(N//2), N//2 + 1)
51
+ U = np.exp(-1j*np.outer(k, X - x0))/np.sqrt(N)
51
52
  return X, U
52
53
 
53
54
 
@@ -18,7 +18,6 @@ class HOdvr:
18
18
  m = float(m)
19
19
  w = float(w)
20
20
  mw = m*w
21
- mw4 = (mw/np.pi)**-0.25
22
21
  B = boson.Boson(N)
23
22
  H = (B.Nop + np.diag(np.ones(N))*0.5)*w
24
23
  x_fbr = (B.C + B.A)/np.sqrt(2*mw) + np.diag(np.ones(N))*x0
@@ -46,6 +45,27 @@ class HOdvr:
46
45
  self.xmat = np.diag(X)
47
46
  self.x0 = self.x[0]
48
47
  self.xf = self.x[-1]
49
- w12 = mw4*np.exp(0.5*mw*X**2)*np.abs(U[0])
50
- self.w = w12**2
48
+ self.w = _weights(X, N, mw, x0)
51
49
 
50
+
51
+
52
+
53
+ def _weights(X, N, mw, x0):
54
+ """
55
+ DVR weights from the Christoffel sum, w_a = 1 / sum_n phi_n(x_a)^2, with
56
+ the HO eigenfunctions phi_n centred at x0 (normalised Hermite functions by
57
+ their three-term recurrence). Equal to the Gauss-Hermite weights
58
+ times exp(xi^2) / sqrt(mw), xi = sqrt(mw) (x - x0), to relative precision
59
+ ~1e-14 also at the outer grid points of large grids, where the previous
60
+ formula from the ground-state eigenvector component lost all precision.
61
+ The weights grow like exp(xi^2) and overflow for N of a few hundred.
62
+ """
63
+ xi = np.sqrt(mw)*(np.asarray(X, float) - x0)
64
+ p_prev = np.zeros_like(xi)
65
+ p = np.pi**-0.25*np.exp(-0.5*xi**2)
66
+ total = p**2
67
+ for n in range(1, N):
68
+ p, p_prev = np.sqrt(2.0/n)*xi*p - np.sqrt((n - 1.0)/n)*p_prev, p
69
+ total += p**2
70
+ with np.errstate(divide='ignore', over='ignore'):
71
+ return 1.0/(np.sqrt(mw)*total)
@@ -29,7 +29,9 @@ def propagate_exact(psi0, op, dt, tfinal, *, tinit=0.0, solver='zvode', **opts):
29
29
  machine precision, but H must fit in memory
30
30
  opts - store_psi, observables (both solvers; observables receive psi
31
31
  flattened to 1D); for 'zvode' also method, atol, rtol,
32
- maxstep (see quadlib.propagation.integrate)
32
+ maxstep (see quadlib.propagation.integrate; maxstep counts the
33
+ internal steps per output interval dt, so a long dt may need a
34
+ larger maxstep)
33
35
 
34
36
  Returns the integrate()-style output dict; 'psi' entries and 'final'
35
37
  have the shape of psi0.
@@ -69,7 +69,9 @@ def integrate(func, psi0, dt, tfinal=None, *,
69
69
  is deliberate: at 1e-8, the 4-mode spin-boson example
70
70
  (20000 states, t = 25) developed a 2.5e-3 error in the
71
71
  highest boson states (tests/test_spin_boson.py)
72
- maxstep - maximum number of internal steps per output interval
72
+ maxstep - maximum number of internal steps per output interval, so a
73
+ long output interval dt also needs a larger maxstep (or a
74
+ shorter dt); zvode fails with "excess work" otherwise
73
75
  store_psi - keep psi at every output time (False keeps only the last)
74
76
  observables - optional dict {name: callable(t, psi)} evaluated at
75
77
  every output time
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quadlib
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: QuaDLib: Quantum Dynamics Library for Research, Development and Education
5
5
  Author-email: Oriol Vendrell <oriol.vendrell@uni-heidelberg.de>, Sudip Sasmal <sudipsasmal.chem@gmail.com>
6
6
  License-Expression: MIT
@@ -103,7 +103,7 @@ pip install -e ".[plot,dev]" # dev adds pytest and ruff
103
103
  or a specific release without cloning:
104
104
 
105
105
  ```bash
106
- pip install git+https://gitlab.com/tc-heidelberg/quadlib.git@v0.1.0
106
+ pip install git+https://gitlab.com/tc-heidelberg/quadlib.git@v0.1.1
107
107
  ```
108
108
 
109
109
  ## Tests and examples
@@ -49,6 +49,7 @@ src/quadlib/wavefunction/wfn_cpd.py
49
49
  src/quadlib/wavefunction/wfn_exact.py
50
50
  tests/test_cli.py
51
51
  tests/test_cpd.py
52
+ tests/test_dvr.py
52
53
  tests/test_exact.py
53
54
  tests/test_integrate.py
54
55
  tests/test_linalg.py
@@ -0,0 +1,47 @@
1
+ """DVR bases against independent references: Gauss-Hermite quadrature for the
2
+ HO weights, the plane-wave spectrum for the exponential DVR, and the
3
+ documented convention u[n, a] = conj(chi_n(x_a)) sqrt(w_a), c = u @ psi_dvr."""
4
+ import numpy as np
5
+ import pytest
6
+ from numpy.polynomial.hermite import hermgauss
7
+
8
+ import quadlib as qua
9
+
10
+
11
+ @pytest.mark.parametrize('N,m,w,x0', [(15, 1.0, 1.0, 0.0), (15, 2.0, 1.5, 1.3), (31, 1.0, 1.0, 0.0),
12
+ (61, 0.7, 2.0, -0.4), (101, 1.0, 1.0, 0.0), (151, 1.0, 1.0, 0.0)])
13
+ def test_hodvr_grid_and_weights_are_gauss_hermite(N, m, w, x0):
14
+ """Regression: the weights were wrong for x0 != 0 (Gaussian not centred at
15
+ x0) and lost all precision at the outer points for N >~ 30."""
16
+ h = qua.HOdvr(N, m, w, x0)
17
+ xg, wg = hermgauss(N)
18
+ mw = m * w
19
+ assert np.allclose(h.x, xg / np.sqrt(mw) + x0, rtol=0, atol=1e-12 * max(1.0, np.abs(xg).max()))
20
+ assert np.allclose(h.w, wg * np.exp(xg**2) / np.sqrt(mw), rtol=1e-12, atol=0)
21
+
22
+
23
+ @pytest.mark.parametrize('N,x0,L', [(21, -5.0, 10.0), (7, 0.0, 2 * np.pi), (31, 1.0, 3.0)])
24
+ def test_expdvr_u_is_the_plane_wave_transformation(N, x0, L):
25
+ """Regression: Expdvr.u was a (wrong) sine transformation, singular and not unitary."""
26
+ e = qua.Expdvr(N, x0, L)
27
+ k = 2 * np.pi / L * np.arange(-(N // 2), N // 2 + 1)
28
+ assert np.allclose(e.u @ e.u.conj().T, np.eye(N), atol=1e-13)
29
+ assert np.allclose(e.u @ e.dq2 @ e.u.conj().T, np.diag(-k**2), atol=1e-11 * max(1.0, k.max()**2))
30
+ assert np.allclose(e.u @ e.dq1 @ e.u.conj().T, np.diag(1j * k), atol=1e-12 * max(1.0, k.max()))
31
+ chi = np.exp(1j * np.outer(k, e.x - x0)) / np.sqrt(L) # FBR functions on the grid
32
+ assert np.allclose(e.u, chi.conj() * np.sqrt(e.w)[None, :], atol=1e-13)
33
+
34
+
35
+ @pytest.mark.parametrize('basis', [qua.Sindvr(12, -2.0, 3.0), qua.HOdvr(12, 1.3, 0.8, 0.5), qua.Expdvr(13, -1.0, 4.0)])
36
+ def test_dvr_u_is_unitary_and_maps_dvr_to_fbr(basis):
37
+ """c = u @ psi_dvr with psi_dvr[a] = sqrt(w_a) psi(x_a): the FBR coefficients of
38
+ the DVR representation of an FBR function chi_n are the unit vector e_n."""
39
+ u = basis.u
40
+ assert np.allclose(u @ u.conj().T, np.eye(basis.n), atol=1e-12)
41
+ for n in (0, 1, basis.n // 2):
42
+ psi_dvr = u.conj().T[:, n] # chi_n as DVR amplitudes
43
+ assert np.allclose(u @ psi_dvr, np.eye(basis.n)[n], atol=1e-12)
44
+ # Sindvr and Expdvr: the FBR diagonalises the second derivative
45
+ if not isinstance(basis, qua.HOdvr):
46
+ d = u @ basis.dq2 @ u.conj().T
47
+ assert np.allclose(d, np.diag(np.diag(d)), atol=1e-10 * np.abs(d).max())
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes