tempoCollaboration / OQuPy

A Python package to efficiently simulate non-Markovian open quantum systems with process tensors.
https://oqupy.readthedocs.io
Apache License 2.0
78 stars 26 forks source link

Large `epsrel` gives unclear errors in `.get_process_tensor` and `.tempo_compute`; also `dkmax=0` #89

Open piperfw opened 1 year ago

piperfw commented 1 year ago

If argument esprel is large e.g. epsrel=1.0 a call to pt.get_process_tensor fails with a long stack trace ending IndexError, and similarly in a call to tempo_compute. We probably want to catch this earlier on and throw a human readable exception.

On a related note setting dkmax=0 (or tcut very small) causes the PT computation to fail in an unclear way (TEMPO is fine). We could ether assert dkmax is greater than 0 for any TempoParameters, or just check this when TempoParameters are used in a PT computation and throw an Error there.

Attached is a snippet (taken from bath_dynamics.ipynb) showing both kinds or failure.

import sys
sys.path.insert(0, '.')
import oqupy

#epsrel = 1e-5; tcut = 2.0 # values from tutorial (fine)
epsrel = 1.0; tcut = 2.0 # IndexError
#epsrel = 1.0; tcut = 1.0e-5 # ValueError

spin_down = oqupy.operators.spin_dm("down")
s_z = 0.5*oqupy.operators.sigma("z")
s_x = 0.5*oqupy.operators.sigma("x")
Omega = 1
alpha = 0.05
w_cutoff = 10 * Omega
epsilon = 2 * Omega
final_t = 20
delta_t = 0.2
initial_state = spin_down
corr = oqupy.PowerLawSD(alpha, 1, w_cutoff, temperature = 1)
pars = oqupy.TempoParameters(delta_t, epsrel, tcut)
system = oqupy.System(Omega*s_x + epsilon*s_z)
bath = oqupy.Bath(s_z, corr)
pt = oqupy.PtTempo(bath, 0.0, final_t, pars)
pt = pt.get_process_tensor(progress_type='bar')

# Large epsrel breaks TEMPO, but small tcut doesn't
#dynamics = oqupy.tempo_compute(system=system,
#                               bath=bath,
#                               initial_state=initial_state,
#                               start_time=0.0,
#                               end_time=15.0,
#                               parameters=pars)