sparse-ir 1.1.6__py3-none-any.whl → 2.0.0a2__py3-none-any.whl

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.
sparse_ir/svd.py DELETED
@@ -1,102 +0,0 @@
1
- # Copyright (C) 2020-2022 Markus Wallerberger, Hiroshi Shinaoka, and others
2
- # SPDX-License-Identifier: MIT
3
- from warnings import warn
4
- import numpy as np
5
- import scipy.linalg.interpolative as intp_decomp
6
-
7
- try:
8
- from xprec import ddouble as _ddouble, finfo
9
- import xprec.linalg as _xprec_linalg
10
-
11
- MAX_DTYPE = _ddouble
12
- MAX_EPS = 5e-32
13
- except ImportError:
14
- _ddouble = None
15
- _xprec_linalg = None
16
-
17
- MAX_DTYPE = np.double
18
- MAX_EPS = np.finfo(MAX_DTYPE).eps
19
- finfo = np.finfo
20
-
21
- try:
22
- from scipy.linalg.lapack import dgejsv as _lapack_dgejsv
23
- except ImportError:
24
- _lapack_dgejsv = None
25
-
26
-
27
- def compute(a_matrix, n_sv_hint=None, strategy='fast'):
28
- """Compute thin/truncated singular value decomposition
29
-
30
- Computes the thin/truncated singular value decomposition of a matrix ``A``
31
- into ``U``, ``s``, ``V``:
32
-
33
- A == (U * s) @ V.T
34
-
35
- Depending on the strategy, only as few as ``n_sv_hint`` most significant
36
- singular values may be returned, but applications should not rely on this
37
- behvaiour. The ``strategy`` parameter can be ``fast`` (RRQR/t-SVD),
38
- ``default`` (full SVD) or ``accurate`` (Jacobi rotation SVD).
39
- """
40
- a_matrix = np.asarray(a_matrix)
41
- m, n = a_matrix.shape
42
- if n_sv_hint is None:
43
- n_sv_hint = min(m, n)
44
- n_sv_hint = min(m, n, n_sv_hint)
45
-
46
- if _ddouble is not None and a_matrix.dtype == _ddouble:
47
- u, s, v = _ddouble_svd_trunc(a_matrix)
48
- elif strategy == 'fast':
49
- u, s, v = _idsvd(a_matrix, n_sv=n_sv_hint)
50
- elif strategy == 'default':
51
- # Usual (simple) SVD
52
- u, s, vh = np.linalg.svd(a_matrix, full_matrices=False)
53
- v = vh.T.conj()
54
- elif strategy == 'accurate':
55
- # Most accurate SVD
56
- if _lapack_dgejsv is None:
57
- warn("dgejsv (accurate SVD) is not available. Falling back to\n"
58
- "default SVD. Expect slightly lower precision.\n"
59
- "Use xprec or scipy >= 1.5 to fix the issue.")
60
- return compute(a_matrix, n_sv_hint, strategy='default')
61
- u, s, v = _dgejsv(a_matrix, mode='F')
62
- else:
63
- raise ValueError("invalid strategy:" + str(strategy))
64
-
65
- return u, s, v
66
-
67
-
68
- def _idsvd(a, n_sv):
69
- # Use interpolative decomposition, since it scales favorably to a full
70
- # SVD when we are only interested in a small subset of singular values.
71
- # NOTE: this returns the right singular vectors, not their conjugate!
72
- intp_decomp.seed(4711)
73
- return intp_decomp.svd(a, n_sv)
74
-
75
-
76
- def _dgejsv(a, mode='A'):
77
- """Compute SVD using the (more accurate) Jacobi method"""
78
- # GEJSV can only handle tall matrices
79
- m, n = a.shape
80
- if m < n:
81
- u, s, v = _dgejsv(a.T, mode)
82
- return v, s, u
83
-
84
- mode = mode.upper()
85
- joba = dict(zip("CEFGAR", range(6)))[mode]
86
- s, u, v, _stat, istat, info = _lapack_dgejsv(a, joba)
87
- if info < 0:
88
- raise ValueError("LAPACK error - invalid parameter")
89
- if istat[2] != 0:
90
- warn("a contained denormalized floats - possible loss of accuracy",
91
- UserWarning, 2)
92
- if info > 0:
93
- warn("SVD did not converge", UserWarning, 2)
94
- return u, s, v
95
-
96
-
97
- def _ddouble_svd_trunc(a):
98
- """Truncated SVD with double double precision"""
99
- if _xprec_linalg is None:
100
- raise RuntimeError("require xprec package for this precision")
101
- u, s, vh = _xprec_linalg.svd_trunc(a)
102
- return u, s, vh.T
@@ -1,155 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: sparse-ir
3
- Version: 1.1.6
4
- Summary: intermediate representation (IR) basis for electronic propagator
5
- Home-page: https://github.com/SpM-lab/sparse-ir
6
- Author: ['Markus Wallerberger', 'Hiroshi Shinaoka', 'Kazuyoshi Yoshimi', 'Junya Otsuki', 'Chikano Naoya']
7
- Author-email: markus.wallerberger@tuwien.ac.at
8
- Keywords: irbasis many-body propagator svd
9
- Classifier: Development Status :: 5 - Production/Stable
10
- Classifier: Intended Audience :: Developers
11
- Classifier: Intended Audience :: Science/Research
12
- Classifier: Topic :: Scientific/Engineering :: Physics
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Programming Language :: Python :: 3
15
- Requires-Python: >=3
16
- Description-Content-Type: text/x-rst
17
- License-File: LICENSE.txt
18
- Requires-Dist: numpy
19
- Requires-Dist: scipy
20
- Requires-Dist: setuptools
21
- Provides-Extra: doc
22
- Requires-Dist: sphinx >=2.1 ; extra == 'doc'
23
- Requires-Dist: sphinx-rtd-theme ; extra == 'doc'
24
- Provides-Extra: test
25
- Requires-Dist: irbasis ; extra == 'test'
26
- Requires-Dist: pytest ; extra == 'test'
27
- Requires-Dist: xprec ; extra == 'test'
28
- Provides-Extra: xprec
29
- Requires-Dist: xprec >=1.0 ; extra == 'xprec'
30
-
31
- sparse-ir - A library for the intermediate representation of propagators
32
- ========================================================================
33
- This library provides routines for constructing and working with the
34
- intermediate representation of correlation functions. It provides:
35
-
36
- - on-the-fly computation of basis functions for arbitrary cutoff Λ
37
- - basis functions and singular values are accurate to full precision
38
- - routines for sparse sampling
39
-
40
-
41
- Installation
42
- ------------
43
- Install via `pip <https://pypi.org/project/sparse-ir>`_::
44
-
45
- pip install sparse-ir[xprec]
46
-
47
- The above line is the recommended way to install `sparse-ir`. It automatically
48
- installs the `xprec <https://github.com/tuwien-cms/xprec>`_ package, which
49
- allows one to compute the IR basis functions with greater accuracy. If you do
50
- not want to do this, simply remove the string ``[xprec]`` from the above command.
51
-
52
- Install via `conda <https://anaconda.org/spm-lab/sparse-ir>`_::
53
-
54
- conda install -c spm-lab sparse-ir xprec
55
-
56
- Other than the optional xprec dependency, sparse-ir requires only
57
- `numpy <https://numpy.org/>`_ and `scipy <https://scipy.org/>`_.
58
-
59
- To manually install the current development version, you can use the following::
60
-
61
- # Only recommended for developers - no automatic updates!
62
- git clone https://github.com/SpM-lab/sparse-ir
63
- pip install -e sparse-ir/[xprec]
64
-
65
- Documentation and tutorial
66
- --------------------------
67
- Check out our `comprehensive tutorial`_, where we self-contained
68
- notebooks for several many-body methods - GF(2), GW, Eliashberg equations,
69
- Lichtenstein formula, FLEX, ... - are presented.
70
-
71
- Refer to the `API documentation`_ for more details on how to work
72
- with the python library.
73
-
74
- There is also a `Julia library`_ and (currently somewhat restricted)
75
- `Fortran library`_ available for the IR basis and sparse sampling.
76
-
77
- .. _comprehensive tutorial: https://spm-lab.github.io/sparse-ir-tutorial
78
- .. _API documentation: https://sparse-ir.readthedocs.io
79
- .. _Julia library: https://github.com/SpM-lab/SparseIR.jl
80
- .. _Fortran library: https://github.com/SpM-lab/sparse-ir-fortran
81
-
82
- Getting started
83
- ---------------
84
- Here is a full second-order perturbation theory solver (GF(2)) in a few
85
- lines of Python code::
86
-
87
- # Construct the IR basis and sparse sampling for fermionic propagators
88
- import sparse_ir, numpy as np
89
- basis = sparse_ir.FiniteTempBasis('F', beta=10, wmax=8, eps=1e-6)
90
- stau = sparse_ir.TauSampling(basis)
91
- siw = sparse_ir.MatsubaraSampling(basis, positive_only=True)
92
-
93
- # Solve the single impurity Anderson model coupled to a bath with a
94
- # semicircular states with unit half bandwidth.
95
- U = 1.2
96
- def rho0w(w):
97
- return np.sqrt(1-w.clip(-1,1)**2) * 2/np.pi
98
-
99
- # Compute the IR basis coefficients for the non-interacting propagator
100
- rho0l = basis.v.overlap(rho0w)
101
- G0l = -basis.s * rho0l
102
-
103
- # Self-consistency loop: alternate between second-order expression for the
104
- # self-energy and the Dyson equation until convergence.
105
- Gl = G0l
106
- Gl_prev = 0
107
- while np.linalg.norm(Gl - Gl_prev) > 1e-6:
108
- Gl_prev = Gl
109
- Gtau = stau.evaluate(Gl)
110
- Sigmatau = U**2 * Gtau**3
111
- Sigmal = stau.fit(Sigmatau)
112
- Sigmaiw = siw.evaluate(Sigmal)
113
- G0iw = siw.evaluate(G0l)
114
- Giw = 1/(1/G0iw - Sigmaiw)
115
- Gl = siw.fit(Giw)
116
-
117
- You may want to start with reading up on the `intermediate representation`_.
118
- It is tied to the analytic continuation of bosonic/fermionic spectral
119
- functions from (real) frequencies to imaginary time, a transformation mediated
120
- by a kernel ``K``. The kernel depends on a cutoff, which you should choose to
121
- be ``lambda_ >= beta * W``, where ``beta`` is the inverse temperature and ``W``
122
- is the bandwidth.
123
-
124
- One can now perform a `singular value expansion`_ on this kernel, which
125
- generates two sets of orthonormal basis functions, one set ``v[l](w)`` for
126
- real frequency side ``w``, and one set ``u[l](tau)`` for the same obejct in
127
- imaginary (Euclidean) time ``tau``, together with a "coupling" strength
128
- ``s[l]`` between the two sides.
129
-
130
- By this construction, the imaginary time basis can be shown to be *optimal* in
131
- terms of compactness.
132
-
133
- .. _intermediate representation: https://arxiv.org/abs/2106.12685
134
- .. _singular value expansion: https://w.wiki/3poQ
135
-
136
- License and citation
137
- --------------------
138
- This software is released under the MIT License. See LICENSE.txt for details.
139
-
140
- If you find the intermediate representation, sparse sampling, or this software
141
- useful in your research, please consider citing the following papers:
142
-
143
- - Hiroshi Shinaoka et al., `Phys. Rev. B 96, 035147`_ (2017)
144
- - Jia Li et al., `Phys. Rev. B 101, 035144`_ (2020)
145
- - Markus Wallerberger et al., `SoftwareX 21, 101266`_ (2023)
146
-
147
- If you are discussing sparse sampling in your research specifically, please
148
- also consider citing an independently discovered, closely related approach, the
149
- MINIMAX isometry method (Merzuk Kaltak and Georg Kresse,
150
- `Phys. Rev. B 101, 205145`_, 2020).
151
-
152
- .. _Phys. Rev. B 96, 035147: https://doi.org/10.1103/PhysRevB.96.035147
153
- .. _Phys. Rev. B 101, 035144: https://doi.org/10.1103/PhysRevB.101.035144
154
- .. _SoftwareX 21, 101266: https://doi.org/10.1016/j.softx.2022.101266
155
- .. _Phys. Rev. B 101, 205145: https://doi.org/10.1103/PhysRevB.101.205145
@@ -1,20 +0,0 @@
1
- sparse_ir/__init__.py,sha256=lepZYR0u9Twji6JLeKja9pNVP6kOSJyczrekHmlbBr8,816
2
- sparse_ir/_gauss.py,sha256=9Ou38SfucUjY83o8Tz62s-gXfWDC8QEHBjiUzcbWaY4,9621
3
- sparse_ir/_roots.py,sha256=ARpyYhhI5gR1AT1zDgezVgCxnHEaJwGF38jEv6ebarA,4351
4
- sparse_ir/_util.py,sha256=93s7tGcXxz3mwHsBQmAh-6EQ26xLbUeFHVtlnzQxRps,3004
5
- sparse_ir/abstract.py,sha256=I7RMcHwgPrtn_XBZ4x_XPxaqp32OLFtXQ5bC2mKp7ic,6604
6
- sparse_ir/adapter.py,sha256=ptiHkTBwZ8aNbtFMnr9k2Rt_v5zwrDyPJ1yx-kiDvew,8351
7
- sparse_ir/augment.py,sha256=rKnmNUREQfymdCYgtpjk8M2jc7LbvTzpvzK-HWjD1e0,9973
8
- sparse_ir/basis.py,sha256=O8wYl4LIj8qJbA_ve7j8FmRcA5i95VO3tglMC-a0j0A,13878
9
- sparse_ir/basis_set.py,sha256=yaXV7qE2RffhzfYE4cqDFdmoISj64cagrJBr5gbhVxQ,3419
10
- sparse_ir/dlr.py,sha256=X6orDjvsOAsFrZsCh8vfedu0_SmTvIpSQmGabfI9pi8,5361
11
- sparse_ir/kernel.py,sha256=2HO77HTOK2WJKizDgr1nmmyhd1mGYT2WvKrFwLiMhjM,18487
12
- sparse_ir/poly.py,sha256=moPMTxJvd2_g43vcyjHSsyBjcQ1lnuPyIjfce6j_AgI,18359
13
- sparse_ir/sampling.py,sha256=BoHOHcLAvQjYR8KwK8Ee0LgZz3q3OgMBuLPgG494VEM,13879
14
- sparse_ir/svd.py,sha256=iQwpBCFSPJeKqhAIlufzz9Ybpm1dq382Km3TU-UvNuc,3375
15
- sparse_ir/sve.py,sha256=pVUKg_cLphx-lRCfrDJXrpkow97vjIgvvSrxA7lhzzg,15179
16
- sparse_ir-1.1.6.dist-info/LICENSE.txt,sha256=3tGlA0QNYsfjETaQqJO0Ixne5PQ16PNVJiDcGsgHER0,1079
17
- sparse_ir-1.1.6.dist-info/METADATA,sha256=jKseTD7HfV70NmUVTqEVZn9dWx-kNXBl8W6-qqKPOX4,6417
18
- sparse_ir-1.1.6.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
- sparse_ir-1.1.6.dist-info/top_level.txt,sha256=UsscWAzJg7fKo9qmIwW8jnG7CAfhFzWYBOTXVySzuA0,10
20
- sparse_ir-1.1.6.dist-info/RECORD,,