ODE Solver errors (convergence, nsteps, excess work) #300
Unanswered
sebgrijalva
asked this question in
Ideas
Replies: 2 comments
-
Just one small note on this matter: I'm still getting inconsistent behaviour when running unit tests locally. It's not frequent, but it does happen that a test fails due to an ODE Error. Here is a transcript of a time this happened: __________________________________________ test_noise __________________________________________
def test_noise():
sim2 = Simulation(
seq, sampling_rate=0.01, config=SimConfig(noise=("SPAM"), eta=0.4)
)
> sim2.run()
pulser/tests/test_simulation.py:529:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pulser/simulation/simulation.py:962: in run
cleanres_noisyseq = _run_solver()
pulser/simulation/simulation.py:902: in _run_solver
result = qutip.sesolve(
../../../opt/miniconda3/envs/pulser-dev/lib/python3.8/site-packages/qutip/sesolve.py:169: in sesolve
res = _generic_ode_solve(func, ode_args, psi0, tlist, e_ops, options,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
func = <built-in method mul_vec of qutip.cy.cqobjevo.CQobjEvoTd object at 0x7f8e5528ce40>
ode_args = ()
psi0 = Quantum object: dims = [[3, 3, 3], [1, 1, 1]], shape = (27, 1), type = ket
Qobj data =
[[0.]
[0.]
[0.]
[0.]
[0.]
...[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[1.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]
[0.]]
tlist = array([0. , 0.101, 0.202, 0.303, 0.404, 0.505, 0.606, 0.707, 0.808,
0.91 , 1.011, 1.112, 1.213, 1.314, 1.415,...7.684, 7.785, 7.886, 7.987, 8.088,
8.19 , 8.291, 8.392, 8.493, 8.594, 8.695, 8.796, 8.897, 8.999,
9. ])
e_ops = [], opt = <qutip.solver.Options object at 0x7f8e5692bbb0>
progress_bar = <qutip.ui.progressbar.BaseProgressBar object at 0x7f8e565186a0>
dims = [[3, 3, 3], [1, 1, 1]]
def _generic_ode_solve(func, ode_args, psi0, tlist, e_ops, opt,
progress_bar, dims=None):
"""
Internal function for solving ODEs.
"""
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# This function is made similar to mesolve's one for futur merging in a
# solver class
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# prepare output array
n_tsteps = len(tlist)
output = Result()
output.solver = "sesolve"
output.times = tlist
if psi0.isunitary:
initial_vector = psi0.full().ravel('F')
oper_evo = True
size = psi0.shape[0]
# oper_n = dims[0][0]
# norm_dim_factor = np.sqrt(oper_n)
elif psi0.isket:
initial_vector = psi0.full().ravel()
oper_evo = False
# norm_dim_factor = 1.0
r = scipy.integrate.ode(func)
r.set_integrator('zvode', method=opt.method, order=opt.order,
atol=opt.atol, rtol=opt.rtol, nsteps=opt.nsteps,
first_step=opt.first_step, min_step=opt.min_step,
max_step=opt.max_step)
if ode_args:
r.set_f_params(*ode_args)
r.set_initial_value(initial_vector, tlist[0])
e_ops_data = []
output.expect = []
if callable(e_ops):
n_expt_op = 0
expt_callback = True
output.num_expect = 1
elif isinstance(e_ops, list):
n_expt_op = len(e_ops)
expt_callback = False
output.num_expect = n_expt_op
if n_expt_op == 0:
# fallback on storing states
opt.store_states = True
else:
for op in e_ops:
if op.isherm:
output.expect.append(np.zeros(n_tsteps))
else:
output.expect.append(np.zeros(n_tsteps, dtype=complex))
if oper_evo:
for e in e_ops:
e_ops_data.append(e.dag().data)
else:
for e in e_ops:
e_ops_data.append(e.data)
else:
raise TypeError("Expectation parameter must be a list or a function")
if opt.store_states:
output.states = []
if oper_evo:
def get_curr_state_data(r):
return vec2mat(r.y)
else:
def get_curr_state_data(r):
return r.y
#
# start evolution
#
dt = np.diff(tlist)
cdata = None
progress_bar.start(n_tsteps)
for t_idx, t in enumerate(tlist):
progress_bar.update(t_idx)
if not r.successful():
> raise Exception("ODE integration error: Try to increase "
"the allowed number of substeps by increasing "
"the nsteps parameter in the Options class.")
E Exception: ODE integration error: Try to increase the allowed number of substeps by increasing the nsteps parameter in the Options class.
../../../opt/miniconda3/envs/pulser-dev/lib/python3.8/site-packages/qutip/sesolve.py:348: Exception |
Beta Was this translation helpful? Give feedback.
0 replies
-
I am also experiencing these errors inconsistently when building the docs. LogNotebook error:
CellExecutionError in tutorials/simulating.nblink:
------------------
results = sim.run(progress_bar=True)
------------------
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Input In [5], in <module>
----> 1 results = sim.run(progress_bar=True)
File ~/Desktop/pulser/pulser/simulation/simulation.py:918, in Simulation.run(self, progress_bar, **options)
915 if set(self.config.noise).issubset({"dephasing", "SPAM"}):
916 # If there is "SPAM", the preparation errors must be zero
917 if "SPAM" not in self.config.noise or self.config.eta == 0:
--> 918 return _run_solver()
920 else:
921 # Stores the different initial configurations and frequency
922 initial_configs = Counter(
923 "".join(
924 (
(...)
931 for _ in range(self.config.runs)
932 ).most_common()
File ~/Desktop/pulser/pulser/simulation/simulation.py:898, in Simulation.run.<locals>._run_solver()
890 result = qutip.mesolve(
891 liouvillian,
892 self.initial_state,
(...)
895 options=solv_ops,
896 )
897 else:
--> 898 result = qutip.sesolve(
899 self._hamiltonian,
900 self.initial_state,
901 self._eval_times_array,
902 progress_bar=p_bar,
903 options=solv_ops,
904 )
905 return CoherentResults(
906 result.states,
907 self._size,
(...)
911 meas_errors,
912 )
File /opt/homebrew/anaconda3/envs/pulser_dev/lib/python3.9/site-packages/qutip/sesolve.py:163, in sesolve(H, psi0, tlist, e_ops, args, options, progress_bar, _safe_mode)
160 v = psi0.full().ravel('F')
161 func(0., v, *ode_args) + v
--> 163 res = _generic_ode_solve(func, ode_args, psi0, tlist, e_ops, options,
164 progress_bar, dims=psi0.dims)
165 if e_ops_dict:
166 res.expect = {e: res.expect[n]
167 for n, e in enumerate(e_ops_dict.keys())}
File /opt/homebrew/anaconda3/envs/pulser_dev/lib/python3.9/site-packages/qutip/sesolve.py:342, in _generic_ode_solve(func, ode_args, psi0, tlist, e_ops, opt, progress_bar, dims)
340 progress_bar.update(t_idx)
341 if not r.successful():
--> 342 raise Exception("ODE integration error: Try to increase "
343 "the allowed number of substeps by increasing "
344 "the nsteps parameter in the Options class.")
345 # get the current state / oper data if needed
346 if opt.store_states or opt.normalize_output or n_expt_op > 0 or expt_callback:
Exception: ODE integration error: Try to increase the allowed number of substeps by increasing the nsteps parameter in the Options class.
Exception: ODE integration error: Try to increase the allowed number of substeps by increasing the nsteps parameter in the Options class.
You can ignore this error by setting the following in conf.py:
nbsphinx_allow_errors = True
make: *** [html] Error 2 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sometimes when performing simulations the solver method from QuTiP returns these kinds of messages, which are related to the way the ode integrator object in scipy handles convergence.
As a brief summary, the
nsteps
parameter determines how many iterations are attempted before the convergence algorithm stops. If the threshold (fromatol
andrtol
) is not met, a catch-all error is thrown by QuTiP's ode solver advising to increasensteps
.It's my impression that we began observing more errors of this kind from v0.4 when the
evaluation_times
changed to accomodate for an extra final time step outside the time list corresponding to the coefficients; as well as the change in the interaction coefficient.However, in most cases, these errors only appear when using very small sampling rates on long sequences or with high values in the Hamiltonian. The following "recipe" seems to be robust enough to these parameters:
If you run these lines, even for large max interactions in the Hamiltonian (so small spacing, many atoms) and large duration of pulse, everything seems to run smoothly.
I will continue forcing this minimal model, and to see what is the least amount of resources that can guarantee good performance, especially from the point of view of the tutorials.
Then this could evolve into an issue to have default values in the Simulation
run()
method.Beta Was this translation helpful? Give feedback.
All reactions