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

Bosonic fitting #2260

Draft
wants to merge 107 commits into
base: master
Choose a base branch
from
Draft

Bosonic fitting #2260

wants to merge 107 commits into from

Conversation

gsuarezr
Copy link
Contributor

@gsuarezr gsuarezr commented Nov 9, 2023

Description

The aim of this project is to enhance the capabilities of qutip's HEOM implementation by introducing a set of tools that offer the option to simulate arbitrary spectral densities or correlation functions.

To achieve this the main idea is to fit our wanted spectral density by a set of underdamped Drude-Lorentz spectral densities or correlation functions. The idea is that the user will supply his desired spectral density or correlation function and the tools will automatically do the fit and construct the corresponding HEOM bath. Guesses ffor the fit and the number of terms will be decided automatically if the user does not specify them. To decided on the number of terms, we will used the normalized root mean square error as a measure of the goodness of the fit.

I also added functions to bosonic bath to quickly obtain the correlation function, power spectrum and spectral density for the existing bosonic baths

Note

Those tests fail because mpmath is not in the requirements, it is needed because the scipy version of the Rienmann zeta function doesn't take complex arguments (scipy/scipy#9182).

Related issues or PRs

The Qutip tutorial notebooks are updated to show this new functionality in (qutip/qutip-tutorials#72)

@gsuarezr
Copy link
Contributor Author

gsuarezr commented Feb 4, 2024

Sorry for the delay on the docstrings and so on, I think all suggestions should be incorporated now. However, thanks to Paul's suggestion of adapting the tutorial 1e. I realized that I made a "mistake from the very beggining", namely the function used to fit the correlation function is only good if the imaginary part of the spectral density is 0 at t=0, because I'm using

$C(t)=\sum_{k}a_{k}e^{-b_{k} t}e^{i c_{k} t}$

so

$C_{R}(t)=\sum_{k}a_{k}e^{-b_{k} t}cos(c_{k} t)$

$C_{I}(t)=\sum_{k}a_{k}e^{-b_{k} t}sin(c_{k} t)$

No matter how many terms I take $C_{I}(0)=0$. I should have realized before but this can be bypassed by excluding $t=0$ from the fit, and starting at a small t, you get a decent fit, as long as you don't look at C(0), and I never check for these situations before. The results of doing this are pretty decent, but updating tutorial 1e I realized it required higher calculation times for the HEOMSolver when compared to using another ansatz for the correlation function, since solving is the expensive bit then I changed the code use another function for fitting

$C(t)=\sum_{k}(a_{k}+i d_{k})e^{-b_{k} t}e^{i c_{k} t}$

The downside is that since this function has 4 parameters, it required changing other functions as well, luckily only functions starting with _, hopefully this won't delay the PR too much. I updated the tutorials with this as well, and added a bit so that passing the parameters for the fitting is easier (after this comment), if the change is not desirable we can just go back to the commit before this comment

qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
@@ -0,0 +1,37 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not commit this file to the repo.

qutip/solver/heom/bofin_baths.py Outdated Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
qutip/solver/heom/bofin_fit.py Outdated Show resolved Hide resolved
Comment on lines 149 to 155
Note: If one of lower, upper, sigma, guesses is None, all are discarded

Returns
-------
- A Bosonic Bath created with the fit parameters for the original
spectral density function (that was provided or interpolated)
- A dictionary containing the following information about the fit:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output of this looks a bit broken (unsure how to get it right, though)

Comment on lines 395 to 401
Note: If one of lower, upper, sigma, guesses is None, all are discarded

Returns
-------
- A Bosonic Bath created with the fit parameters from the original
correlation function (that was provided or interpolated).
- A dictionary containing the following information about the fit:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same formatting thing here

@pmenczel
Copy link
Member

Somehow vscode published those review comments above before I was done reviewing. Only one more comment though: in the tests, you ignore some RuntimeWarnings here and there; it would be good to add a comment explaining why. Thank you for adding a good amount of tests!

If these last minor points get addressed, this looks good to me. Only those utility functions in the bofin_fit module are a bit of a mess - if we ever want to add more fitting methods, it will require some work. But it is non-public api and it seems to do the job for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants