-
Notifications
You must be signed in to change notification settings - Fork 621
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
Bosonic fitting #2260
Draft
gsuarezr
wants to merge
107
commits into
qutip:master
Choose a base branch
from
gsuarezr:bosonic_fitting
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Bosonic fitting #2260
Changes from 48 commits
Commits
Show all changes
107 commits
Select commit
Hold shift + click to select a range
1a2e5d0
Added FitBath and OhmicBath classes, fix spelling on solver_base
gsuarezr 27ed772
notebooks as example
gsuarezr 3ba219d
formatting
gsuarezr 40a914d
added tests
gsuarezr 3edecc0
Merge branch 'qutip:master' into master
gsuarezr f51033a
Make fit classes inherit, which broke tests, refactored functions and…
gsuarezr c880375
minor refactoring
gsuarezr 7080102
replaced tests to match new classes
gsuarezr 390c596
added parity support changed prints to __str__
gsuarezr fa563b5
deleted innecessary comments and code
gsuarezr c6a7d4e
Rewrote summary methods,added comments,eliminated unnecessary code
gsuarezr 5c03d92
Rewrote summary methods,added comments,eliminated unnecessary code
gsuarezr 5f0003c
moving parity to another branch
gsuarezr 3c1fcbe
Merge branch 'qutip:master' into master
gsuarezr 76a135b
aligned the text in summary
gsuarezr 3242c97
removed rwa stuff
gsuarezr 228d763
deleted unnecessary code
gsuarezr 13a0b1c
changed formatting from black to autopep8
gsuarezr 02c6d99
changed formatting from black to autopep8
gsuarezr 2361a6c
removed typo from the tests file
gsuarezr 3a0c493
moved plots, added functions so tutorial looks better
gsuarezr cd4b034
Merge branch 'qutip:master' into bosonic_fitting
gsuarezr eaa7bd7
modified code to satisfy pycodestyle
gsuarezr 82ae9f3
modified code to satisfy pycodestyle
gsuarezr 5fe5932
fixed string formatting
gsuarezr e36c9ab
added functions for correlation functions,spectral densities and powe…
gsuarezr a507467
try catch on mpmath to avoid tests failing
gsuarezr 6463371
removed warning
gsuarezr a2219c7
fixed tests after refactoring
gsuarezr 013fb2c
refactored according to codeclimate
gsuarezr 336a04d
fixed tests that fail due to refactoring
gsuarezr b5dfdfc
fixed failed tests
gsuarezr c3e3457
added changelog, fix tests issue
gsuarezr 7300aad
pep8 issues
gsuarezr 7f75616
Remove Bosonic class instances, renamed functions, fixed tests
gsuarezr 357104b
skip tests where mpmath is required
gsuarezr 662b7e3
removed exception
gsuarezr ac174ca
codeclimate refactoring suggestions
gsuarezr f899877
changes proposed monday
gsuarezr 1ef2240
Merge branch 'qutip:master' into bosonic_fitting
gsuarezr 2ee86b7
Fixed typo in file name
pmenczel 382b63a
correction of tests
gsuarezr b3dfeac
broken after pull, commit to see diff
gsuarezr dfa31e0
changed tests to match refactor
gsuarezr 7cc95ec
refactored/ changed tests
gsuarezr 67a7178
I had forgotten pytest fixtures on some tests
gsuarezr 94b192f
fixed spectral density on Pade Bath
gsuarezr b7ce167
refactored and added tests
gsuarezr 1f76959
cleaned visualization.py
gsuarezr 50f771b
pep8 formatting
gsuarezr e398051
codeclimate issues
gsuarezr a60cf8f
filtered overflow warning on integrals
gsuarezr 38f003d
Merge branch 'qutip:master' into bosonic_fitting
gsuarezr 2724e22
filtered overflow warning on integrals
gsuarezr a240f35
Fixing small mistakes and adding some todo comments
pmenczel d4a579d
modified docstrings
gsuarezr 712a492
correlation test
gsuarezr b039a10
suggestions from tuesday
gsuarezr 122c3b2
skip test if mp not available
gsuarezr 8e526c3
added zero temperature support to ohmic correlations
gsuarezr 5db3ce7
Merge branch 'qutip:master' into bosonic_fitting
gsuarezr 85fa0d2
minor typos, failing fit test fix
gsuarezr 9557c82
reduce tests time, mark generate bath as slow
gsuarezr fa3c8f7
Moved Nk of the SpectralFitter class from initialization to get_fit, …
gsuarezr 4595496
Added a few lines so fitting correlation functions with no imaginary …
gsuarezr 27646f3
accidentaly used wrong formatter
gsuarezr 3b45396
accidentaly used wrong formatter
gsuarezr c218a89
codeclimate details
gsuarezr 20af021
fix broken tests
gsuarezr 98c08e6
Made some docstrings more clear
pmenczel 28cc484
Merge branch 'bosonic_fitting' of github.com:mcditoos/qutip_gsoc_app …
pmenczel 70cc2f5
Simplify correlation function / power spectrum calculations by assumi…
pmenczel cbf4629
Small updates for D-L bath classes
pmenczel 0033ea2
Changed default number of exponents in exact correlation function to …
pmenczel 72b0018
Updated docstrings, formatting and minor improvements in bofin_fit mo…
pmenczel 6827344
Bugfixes
pmenczel 55d5226
HEOM fitting: minor fixes
pmenczel 1a60dc6
Work on docstrings
gsuarezr 9a8e3c8
Modified ansatz and better guesses
gsuarezr 18e17d1
new ansatz
gsuarezr 45211a3
docstrings
gsuarezr 0e322f2
Some TODOS
gsuarezr 556a4ec
puntuation on docstrings
gsuarezr 88cae59
Working version before refactoring
gsuarezr 96568b4
Merged fix correlation ansatz
gsuarezr 9952111
codeclimate suggested refactoring
gsuarezr 68139e5
Update qutip/solver/heom/bofin_baths.py
gsuarezr 9ed0f7b
failed tests
gsuarezr bbc0af5
Prefer classmethod over staticmethod
pmenczel da6172f
Some docstring formatting
pmenczel 15c2bab
Work on Docstrings, made test that fails due to time to a simpler one
gsuarezr 3928d4d
Merge branch 'qutip:master' into bosonic_fitting
gsuarezr 12d694b
minor pep8 issues
gsuarezr e2e40b4
changes in documentation
gsuarezr 498badd
removed returns that make documentation fail
gsuarezr fa8f237
reverted default guesses
gsuarezr bacffdd
Modified Ansatz to be general when Imaginary part of the correlation …
gsuarezr d953dcf
changed handling of user guesses
gsuarezr 6803c61
readded returns that made documentation fail in another format
gsuarezr 33b3889
codeclimate suggested refactor
gsuarezr dd3cfdf
Changed selection of correlation ansatz from imaginary part different…
gsuarezr bb4c763
latex documentation fix
gsuarezr 937dae6
pop8 formatting
gsuarezr d42ebe7
Testing if latexpdf documentation breaks
gsuarezr 1504426
documentation issues
gsuarezr d586a9d
added changes to missing docstrings
gsuarezr 421b475
Merge branch 'qutip:master' into bosonic_fitting
gsuarezr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added support for arbitrary spectral densities in HEOM by fitting underdamped modes, added an Ohmic Bath class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from qutip.core import data as _data | ||
from qutip.core.qobj import Qobj | ||
from qutip.core.superoperator import spre, spost | ||
from scipy.integrate import quad_vec | ||
|
||
__all__ = [ | ||
"BathExponent", | ||
|
@@ -243,8 +244,9 @@ def _check_coup_op(self, Q): | |
|
||
def __init__( | ||
self, Q, ck_real, vk_real, ck_imag, vk_imag, combine=True, | ||
tag=None, | ||
tag=None, T=None | ||
): | ||
self.T = T | ||
self._check_cks_and_vks(ck_real, vk_real, ck_imag, vk_imag) | ||
self._check_coup_op(Q) | ||
|
||
|
@@ -337,6 +339,85 @@ def combine(cls, exponents, rtol=1e-5, atol=1e-7): | |
|
||
return new_exponents | ||
|
||
def spectral_density(self, w): | ||
raise NotImplemented | ||
|
||
def correlation_function( | ||
self, t, epsabs=1e-6, epsrel=1e-6, method='gk15'): | ||
""" Calculates the correlation function | ||
by numerically computing the integral | ||
Parameters | ||
---------- | ||
t : np.array or float | ||
the time at which to evaluare the correlation function | ||
epsabs : float | ||
Absolute error tolerance | ||
epsrel : float | ||
Relative error tolerance | ||
""" | ||
def c_i(w, t): return (1/np.pi)*self.spectral_density(w)*( | ||
(1/np.tanh(w/(2*self.T)))*np.cos(w*t) - 1j*np.sin(w*t)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it make sense to also have a check for zerodivisionerror here, and if it catches it use np.sign() or something instead? |
||
|
||
def c(t): return quad_vec( | ||
lambda x: c_i(x, t), | ||
0, | ||
np.Inf, | ||
epsabs=epsabs, | ||
epsrel=epsrel, | ||
quadrature=method, | ||
)[0] | ||
return c(t) | ||
|
||
def bose_einstein(self, w): | ||
try: | ||
return (1 / (np.e**(w / self.T) - 1)) | ||
except ZeroDivisionError: | ||
return 0 | ||
|
||
def power_spectrum(self, w): | ||
"""Calculates the power spectrum from the spectral density | ||
""" | ||
S = self.spectral_density( | ||
w)*((self.bose_einstein(w) + 1) * 2) | ||
return S | ||
|
||
def correlation_function_approx(self, t): | ||
"""Computes the correlation function from | ||
the exponents""" | ||
corr = 0+0j | ||
for exp in self.exponents: | ||
if ( | ||
exp.type == BathExponent.types['R'] or | ||
exp.type == BathExponent.types['RI'] | ||
): | ||
corr += exp.ck * np.exp(-exp.vk * t) | ||
if exp.type == BathExponent.types['I']: | ||
corr += 1j*exp.ck * np.exp(-exp.vk * t) | ||
if exp.type == BathExponent.types['RI']: | ||
corr += 1j*exp.ck2 * np.exp(-exp.vk * t) | ||
return corr | ||
|
||
def power_spectrum_approx(self, w): | ||
S = 0+0j | ||
for exp in self.exponents: | ||
if exp.ck is None: | ||
exp.ck = 0 | ||
if exp.ck2 is None: | ||
exp.ck2 = 0 | ||
if exp.type == BathExponent.types['I']: | ||
S += 2*np.real((1j*exp.ck-exp.ck2)/(exp.vk - 1j*w)) | ||
else: | ||
S += 2*np.real((exp.ck+1j*exp.ck2)/(exp.vk - 1j*w)) | ||
|
||
return S | ||
|
||
def spectral_density_approx(self, w): | ||
J = np.real( | ||
self.power_spectrum_approx(w) / | ||
((self.bose_einstein(w) + 1) * 2) | ||
) | ||
return J | ||
|
||
|
||
class DrudeLorentzBath(BosonicBath): | ||
""" | ||
|
@@ -373,16 +454,18 @@ class DrudeLorentzBath(BosonicBath): | |
def __init__( | ||
self, Q, lam, gamma, T, Nk, combine=True, tag=None, | ||
): | ||
self.lam = lam | ||
self.gamma = gamma | ||
gsuarezr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.T = T | ||
ck_real, vk_real, ck_imag, vk_imag = self._matsubara_params( | ||
lam=lam, | ||
gamma=gamma, | ||
T=T, | ||
Nk=Nk, | ||
) | ||
|
||
super().__init__( | ||
Q, ck_real, vk_real, ck_imag, vk_imag, combine=combine, tag=tag, | ||
) | ||
super().__init__(Q, ck_real, vk_real, ck_imag, | ||
vk_imag, combine=combine, tag=tag, T=T) | ||
|
||
self._dl_terminator = _DrudeLorentzTerminator( | ||
Q=Q, lam=lam, gamma=gamma, T=T, | ||
|
@@ -427,6 +510,9 @@ def _matsubara_params(self, lam, gamma, T, Nk): | |
vk_imag = [gamma] | ||
|
||
return ck_real, vk_real, ck_imag, vk_imag | ||
|
||
def spectral_density(self, w): | ||
return 2*self.lam*self.gamma*w/(self.gamma**2 + w**2) | ||
|
||
|
||
class DrudeLorentzPadeBath(BosonicBath): | ||
|
@@ -437,7 +523,7 @@ class DrudeLorentzPadeBath(BosonicBath): | |
A Padé approximant is a sum-over-poles expansion ( | ||
see https://en.wikipedia.org/wiki/Pad%C3%A9_approximant). | ||
|
||
The application of the Padé method to spectrum decompoisitions is described | ||
The application of the Padé method to spectrum decompositions is described | ||
in "Padé spectrum decompositions of quantum distribution functions and | ||
optimal hierarchical equations of motion construction for quantum open | ||
systems" [1]. | ||
|
@@ -479,6 +565,8 @@ class DrudeLorentzPadeBath(BosonicBath): | |
def __init__( | ||
self, Q, lam, gamma, T, Nk, combine=True, tag=None | ||
): | ||
self.lam = lam | ||
self.gamma = gamma | ||
eta_p, gamma_p = self._corr(lam=lam, gamma=gamma, T=T, Nk=Nk) | ||
|
||
ck_real = [np.real(eta) for eta in eta_p] | ||
|
@@ -488,9 +576,8 @@ def __init__( | |
ck_imag = [np.imag(eta_p[0])] | ||
vk_imag = [gamma_p[0]] | ||
|
||
super().__init__( | ||
Q, ck_real, vk_real, ck_imag, vk_imag, combine=combine, tag=tag, | ||
) | ||
super().__init__(Q, ck_real, vk_real, ck_imag, | ||
vk_imag, combine=combine, tag=tag, T=T) | ||
|
||
self._dl_terminator = _DrudeLorentzTerminator( | ||
Q=Q, lam=lam, gamma=gamma, T=T, | ||
|
@@ -565,8 +652,8 @@ def _delta(self, i, j): | |
|
||
def _calc_eps(self, Nk): | ||
alpha = np.diag([ | ||
1. / np.sqrt((2 * k + 5) * (2 * k + 3)) | ||
for k in range(2 * Nk - 1) | ||
1. / np.sqrt((2 * k + 5) * (2 * k + 3)) | ||
for k in range(2 * Nk - 1) | ||
], k=1) | ||
alpha += alpha.transpose() | ||
evals = eigvalsh(alpha) | ||
|
@@ -575,14 +662,17 @@ def _calc_eps(self, Nk): | |
|
||
def _calc_chi(self, Nk): | ||
alpha_p = np.diag([ | ||
1. / np.sqrt((2 * k + 7) * (2 * k + 5)) | ||
for k in range(2 * Nk - 2) | ||
1. / np.sqrt((2 * k + 7) * (2 * k + 5)) | ||
for k in range(2 * Nk - 2) | ||
], k=1) | ||
alpha_p += alpha_p.transpose() | ||
evals = eigvalsh(alpha_p) | ||
chi = [-2. / val for val in evals[0: Nk - 1]] | ||
return chi | ||
|
||
def spectral_density(self, w): | ||
return 2*self.lam*self.gamma*w/(self.gamma**2 + w**2) | ||
|
||
|
||
class _DrudeLorentzTerminator: | ||
""" A class for calculating the terminator of a Drude-Lorentz bath | ||
|
@@ -662,12 +752,16 @@ def __init__( | |
T=T, | ||
Nk=Nk, | ||
) | ||
self.lam = lam | ||
self.gamma = gamma | ||
self.w0 = w0 | ||
self.T = T | ||
|
||
super().__init__( | ||
Q, ck_real, vk_real, ck_imag, vk_imag, combine=combine, tag=tag, | ||
) | ||
super().__init__(Q, ck_real, vk_real, ck_imag, | ||
vk_imag, combine=combine, tag=tag, T=T) | ||
|
||
def _matsubara_params(self, lam, gamma, w0, T, Nk): | ||
@staticmethod | ||
def _matsubara_params(lam, gamma, w0, T, Nk): | ||
""" Calculate the Matsubara coefficents and frequencies. """ | ||
beta = 1/T | ||
Om = np.sqrt(w0**2 - (gamma/2)**2) | ||
|
@@ -704,6 +798,10 @@ def _matsubara_params(self, lam, gamma, w0, T, Nk): | |
|
||
return ck_real, vk_real, ck_imag, vk_imag | ||
|
||
def spectral_density(self, w): | ||
return self.lam**2 * self.gamma * w / ((w**2 - self.w0**2)**2 | ||
+ (self.gamma*w)**2) | ||
|
||
|
||
class FermionicBath(Bath): | ||
""" | ||
|
@@ -962,8 +1060,8 @@ def _delta(self, i, j): | |
|
||
def _calc_eps(self, Nk): | ||
alpha = np.diag([ | ||
1. / np.sqrt((2 * k + 3) * (2 * k + 1)) | ||
for k in range(2 * Nk - 1) | ||
1. / np.sqrt((2 * k + 3) * (2 * k + 1)) | ||
for k in range(2 * Nk - 1) | ||
], k=1) | ||
alpha += alpha.transpose() | ||
|
||
|
@@ -973,8 +1071,8 @@ def _calc_eps(self, Nk): | |
|
||
def _calc_chi(self, Nk): | ||
alpha_p = np.diag([ | ||
1. / np.sqrt((2 * k + 5) * (2 * k + 3)) | ||
for k in range(2 * Nk - 2) | ||
1. / np.sqrt((2 * k + 5) * (2 * k + 3)) | ||
for k in range(2 * Nk - 2) | ||
], k=1) | ||
alpha_p += alpha_p.transpose() | ||
evals = eigvalsh(alpha_p) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that these got split out into their own module.