-
Notifications
You must be signed in to change notification settings - Fork 30
Adds an alternative method to compute eta_function in CustomSD to deal with large memory-lengths #151
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
base: main
Are you sure you want to change the base?
Adds an alternative method to compute eta_function in CustomSD to deal with large memory-lengths #151
Conversation
Adds an alt_integrator parameter to PowerLawSD/CustomSD and to eta_function/correlation_2d_integral that dictates whether or not to use an alternative method to numerically integrate eta_function (splitting the integrals into oscillating terms and using cos/sin weighted integrals instead). Also adds corresponding coverage tests and physics tests comparing exact values of these integrals to both versions of the integrator (asking for at least an IntegrationWarning if the results don't match).
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.
Some comments on docstrings relevant to ongoing Issue discussion
temperature: float | ||
The environment's temperature. | ||
alt_integrator: bool | ||
Whether or not to use a sine/cosine weighted version of the |
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.
Suggest small revision to mention scipy,
"Whether to use an alternative integration scheme leveraging sine/cosine weighted versions of scipy.integrate.quad to handle rapid oscillations. This may improve numerical accuracy and stability, especially for long memory times.
[Blank line]
The integral...
"
assert isinstance(alt_integrator, bool) | ||
self._alt_integrator = alt_integrator | ||
|
||
# create the first_cutoff function and input check for num_oscillations |
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.
Do we want to assert that, if num_oscillations is provided, alt_integrator should be true? Or at least provide a warning that it will be discarded when alt_integrator is False?
Whether or not to use a sine/cosine weighted version of the | ||
integrals that could be better suited if you're encountering | ||
numerical difficulties, especially for long memory times. | ||
The integral computed in `eta_function` is cut in two: one |
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.
Make consistent with above
``'gaussian'``} | ||
temperature: float | ||
The environment's temperature. | ||
alt_integrator: bool |
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.
I think in docstrings other than CustomSD (or whatever you deem the 'parent' one to be) we can either a) copy the entire docstring or b) (probably neater) reference CustomSD, e.g.
Whether to use an alternative integration scheme leveraging sine/cosine weighted versions of scipy.integrate.quad to handle rapid oscillations. See...
Hi @emile-cochin, I am sorry for this massively delayed reply - I simply didn't get round to having a close enough look at your code until now. Thank you very much for this contribution, including the tests that compare the result with exact analytical results. This is very helpful. Currently the logic in the
@emile-cochin @piperfw : Let me know what you think of this! --- Best, Gerald |
Great input on streamlining @gefux, I agree simplifying the logic we have here would be beneficial. Just on your points
A related question, @emile-cochin have you done any performance testing? Not that we prioritise fast code, but it would be interesting to know whether the gain from using the weighted version outweighs the overhead from replacing two calls to
|
Hi @gefux, thank you very much for your inputs and very sorry for the delay, I'm back to working on OQuPy for the beginning of my PhD which started today. Here are my thoughts on these issues: Just to answer @piperfw about performance: the cases where the memory length is low are basically instant in all cases and for long memory lengths, the new code performs a lot faster (sometimes up to x50 speedup) since it doesn't struggle with the oscillations like the previous one. If you want a proper benchmark I can also try to measure it properly, but since the difference was in favor of the new method, I didn't go beyond this.
|
Summary
This adds an
alt_integrator
parameter toPowerLawSD
/CustomSD
and toeta_function
/correlation_2d_integral
that dictates whether or not to use an alternative method to numerically integrateeta_function
(splitting the integrals into oscillating terms and using cos/sin weighted integrals instead as described more precisely in #150). Also adds corresponding coverage tests. It adds a new physics testbath_correlations_test.py
which compares exact values of these 2d integrals (for an Ohmic SD with exponential cutoff at 0 temperature) to both versions of the integrators, and for short and long memory-lengths. More specifically, this test expects either a sufficiently good agreement or at least anIntegrationWarning
being raised if the results don't match. For now it passes in about 2s with the default integrator issuing a warning for long memory-lengths.This is a draft since there are a few choices to discuss before this is potentially publishable. I'm notably thinking about:
omega_tilde
) is best suited for eachtau
). For now the function implemented isomega_tilde = omega_cutoff/int(2+omega_cutoff*tau/10)
which seemed to give convincing results for a large number of spectral densities and parameter choices.It is heuristically motivated since the idea is to have a smaller first interval for larger
alt_integrator
or alternatively rewrite all of this to pass anintegrator_options
dictionary instead).correlation_2d_integral
in thehelpers
submodule and, if so, if it should let the user plot any correlation or specifically the ones as used in theinfluence_matrix
function.Pull Request Check List
This checklist serves as a guide for contributors and maintainers to assess
whether a contribution can be merged into the main branch and thus serves
to guarantee the quality of the package. Please read the
contribution guideline.
Before you submit a pull request, please go through this checklist once
more, as it will decrease the number of unnecessary review cycles.
However, this list is there to help all contributors to produce high
quality code, not to deter you from contributing. If you can't tick some of the
boxes, feel free to submit the pull request anyway and report about it in the
pull request message. Also, some of the boxes might not apply to the specific
type of your contribution.
tox -e py36
(to runpytest
) the code tests.tox -e style
(to runpylint
) the code style tests./docs/pages/modules.rst
has been updated./docs/pages/api.rst
has been updated.