-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Motivation
I'm opening this issue following a discussion about potential problems encountered when computing process tensors with large memory lengths. The problem would arise from the numerical integration in CustomSD.eta_function
due to the default integrator of scipy.integrate.quad
not being able to deal with the fast oscillations of the integrand. Most of the times, oqupy
manages to issue a warning to inform that there are potential errors in the computations but in niche cases, the errors are uncaught. I think this is because the influence functional computations using correlation_2d_integral
involve (discrete) second order differences of eta_function
which are very sensitive to tiny errors in eta_function
.
The reason why I open this issue is to possibly contribute by adding an alternative to the current integrator to choose from if the current method doesn't yield satisfying results. It would rely on the weighted sin/cos integrators of scipy.integrate.quad
.
Also, in order to diagnose problems with numerical integration, I believe that there is the helpers
function plot_correlations_with_parameters
for now. Unfortunately, sometimes the errors in the results of correlation_2d_integral
don't quite appear from the bare correlations because of the sensitivity of the first/second order differences. It could maybe be useful to also add a function to plot the results for the 2d correlations as well.
Idea for the implementation
Just a quick remark first, I'm not sure that the documentation for eta_function
is consistent with what it's computing. Shouldn't it be something like:
The current way this is computed is by splitting the integration interval into
- Further cut the first interval into
$[0, \tilde{\omega}]$ and$[\tilde{\omega}, \omega_c]$ - Perform usual integration on the first interval
$[0, \tilde{\omega}]$ because isolating the$\cos$ and$\sin$ parts of the integral isn't possible due to the integrands being divergent on their own. The choice of$\tilde{\omega}$ should be made such that there aren't too many oscillations in this interval/or at least that the default integrator is still able to integrate this part without error. - For the two other intervals
$[\tilde{\omega}, \omega_c]$ and$[\omega_c, +\infty]$ , is it possible to split the integral into 4 parts:
The first two can be computed with the 'cos'/'sin' weighted integrals of quad
. The other two aren't oscillating so they are computed with the default integrator. They also don't necessarily need to be recomputed if one doesn't change
Preliminary results
Here are a few examples for a some common spectral densities (which were chosen with an exponential cutoff which is where the usual integrator struggles most). The log-scale is a bit misleading but in most of these cases, there are still a few places where the errors are large enough to have an impact on the process tensor computations. Just as a side note, for the Ohmic case and the particular choice of parameters, the integration warning didn't trigger on the first large peak.
By a few days I'll commit the cleaned code. Let me know if you think this could be interesting to add, and if you have ideas of how to deal with choosing the ideal
Best,