Debug a failed trial
Goal: find out why trials failed and reproduce one in isolation.
See what failed
A failing trial never stops the experiment. It is recorded:
results = experiment.run()
if results.failed.any():
print(results.failed.sum(), "trials failed")
print(set(results.failure_reasons[results.failed]))
3 trials failed
{'bad.gaps exhausted after 3 values'}
Reasons name the input or operation involved, using the canonical path of
the model instance. Outputs of failed trials are nan and are skipped by
summary() and compare().
If any failure should stop you immediately, ask for an exception:
experiment.run(on_failure="raise")
# cimba.experiments.run.TrialsFailed: 3 trials failed: bad.gaps exhausted after 3 values
Reproduce one trial
Every trial is a pure function of its seed and configuration, so you can rerun exactly one:
import numpy as np
point, replication = np.argwhere(results.failed)[0]
index = point * experiment.replications + replication
again = experiment.only(trials=[index]) # workers=1 by default
again.failure_reasons # same reason, same trial
Watch it with logging
Add cb.log calls to the processes involved (they cost nothing while
disabled), enable them, and rerun the single trial:
TRACE = 1
# in the model:
# cb.log(TRACE, "next gap", gap)
cb.set_engine_log_level(TRACE)
try:
experiment.only(trials=[index])
finally:
cb.set_engine_log_level(0)
Each line shows the trial index, simulated time, process name, your message and value.
Typical causes
Symptom |
Likely cause and fix |
|---|---|
|
A trace shorter than the run needs. Use |
|
A resample was extended six times (64× its first length) or reached
its hard limit ( |
|
A missing parameter, source, field value or reference, a reference to a model outside the tree, or a model used twice. The message names the path. |
|
Unsupported code in a compiled method, or a call to a method that
isn’t a |
The run never finishes |
|
Outputs are all |
The |
If the Python process itself crashes (a segmentation fault), run with
python -X faulthandler to see where, and please report it with the model.