Skip to content

Adding an alternative integrator to deal with fast oscillations in long memory-length numerical integrations for CustomSD #150

@emile-cochin

Description

@emile-cochin

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:

$$\eta(\tau) = \displaystyle\int_0^\infty \frac{J(\omega)}{\omega^2} \left[ (\cos(\omega\tau)-1)\coth\left(\frac{\omega}{2T}\right) - i(\sin(\omega\tau) - \omega\tau) \right]\mathrm{d}\omega$$

The current way this is computed is by splitting the integration interval into $[0, \omega_c]$ and $[\omega_c, +\infty]$ (for soft cutoffs). The method I tried which seemed to give convincing results when $\tau$ is larger than a few $1/\omega_c$ (if $\tau$ is too small, the integrand doesn't oscillate and using a weighted integrator doesn't work well) is the following:

  • 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:
$$\eta(\tau) = \displaystyle\int_a^b \frac{J(\omega)}{\omega^2}\coth\left(\frac{\omega}{2T}\right) \cos(\omega\tau)\mathrm{d}\omega - i \displaystyle\int_a^b \frac{J(\omega)}{\omega^2} \sin(\omega\tau)\mathrm{d}\omega - \displaystyle\int_a^b \frac{J(\omega)}{\omega^2} \coth\left(\frac{\omega}{2T}\right)\mathrm{d}\omega + i\tau\displaystyle\int_a^b \frac{J(\omega)}{\omega}\mathrm{d}\omega$$

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 $\tilde{\omega}$ since they are independent of $\tau$. Right now, I'm not completely sure whether $\tilde{\omega}$ should be fixed by the user or estimated for each $\tau$ as something like $c/\tau$ where $c$ would be a fixed constant. For now, just fixing it at $\omega_c/2$ seemed to work for most of the spectral densities that I've tested but I don't know if it is desirable to have random constants sitting in the code like this.

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.

Image

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 $\tilde{\omega}$.

Best,

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions