Apparent off-by-one (or more) timing error in Builder scripts #4828
Labels
🐞 bug
Issue describes a bug (crash or error) or undefined behavior.
🐍 Py Builder outputs
Issues with the way the Python is written by Builder
Builder components can record their
.started
and.stopped
attributes in the datafile, using an absolute time in seconds. In this minimal example, the first text stimulust_0
has a specified onset time of 0 s relative to the start of the trial, with subsequent text stimuli having onsets at 2 and 4 s:Over two separate runs of five trials, subtracting the times of onset between the three stimuli gives the following relative onset times (which should be 2.0, 4.0, and 2.0):
(1) The intervals between the onset of stimuli
t_4
andt_2
(the third column) are effectively exactly 2.0 seconds, as intended.(2) The intervals between the onset of
t_0
and the later stimuli are shorter than intended, by 1, 2 or even more frames.(3) When subtracting the time of onset of
t_4
from its time of onset on the previous trial, it was short by approximately 1 frame. i.e. this is an empirical measure of the total routine duration, including transitions between one routine and the next, and should be 5.0 seconds in this case. The shortened duration means the timing error would tend to accumulate over loop iterations. This might particularly affect fMRI tasks, and other studies which require multiple consecutive trials on a fixed schedule.The error in relative onset times seems to apply only with respect to stimuli appearing at t = 0, as the relative times between the later stimuli are correct. This would be consistent with the onset of the first stimulus being delayed (e.g. a dropped frame). But that wouldn't be consistent with the overall duration of the trial being apparently shortened by a frame.
Because stimuli (and keyboard components) are appearing at times other than intended relative to the start of the routine, this can lead to systematically incorrect measured reaction times.
The issue can be more pronounced in the first iteration of a loop, although given the way Builder stimuli are pre-created before the routine, it isn't obvious why there might be such a start-up cost.
This issue does not just apply to visual stimuli but also sound stimuli, and presumably other components. It was first noted in a regular experiment, but is easily reproducible in a minimal .psyexp file like the one attached, which was used to generate the values above. It occurs both in fullscreen and windowed modes. This has been observed when running local Python scripts: I haven't tested it on Pavlovia.
Example file below. I just calculated the time intervals manually, by opening the .csv files in a spreadsheet and subtracting columns of
.started
attributes from each other.timing_issue.psyexp.zip
The text was updated successfully, but these errors were encountered: