Hi @hoechenberger, I'm not sure if this is psychopy or questplus issue (great pa…ckage BTW!).
The QuestPlusHandler freezes when its `.next()` method is called for the 28'th time. Below is the (almost minimally) reproducible example:
```python
import numpy as np
from psychopy import data
from questplus.psychometric_function import weibull
n_trials = 30
# create an idealized participant (weibull function)
def get_response(intensity):
prop_corr = weibull(intensity=intensity, threshold=0.13,
slope=6.35, lower_asymptote=0.5, lapse_rate=0.02,
scale='linear').item()
dice_roll = np.random.random()
return int(dice_roll <= prop_corr)
# set up intensity domain and parameter space
min_coh, n_dots = 0.02, 200
coherences = np.logspace(np.log10(min_coh), np.log10(1.), num=100)
coh_dots = np.unique(np.round(coherences * n_dots))
coherences = coh_dots / n_dots
thresh = np.logspace(np.log10(0.01), np.log10(1.5), num=50)
slopes = np.logspace(np.log10(0.15), np.log10(20.), num=50)
lapses = np.arange(0., 0.06, 0.01)
# create questplus "staircase"
staircase = data.QuestPlusHandler(
nTrials=n_trials, intensityVals=coherences, thresholdVals=thresh,
slopeVals=slopes, lowerAsymptoteVals=[0.5], lapseRateVals=lapses,
responseVals=[1, 0], startIntensity=coherences[40],
stimScale='linear')
# try to run it for 30 trials
for idx in range(n_trials):
print(f'Trial {idx + 1:02d}')
intensity = staircase.next()
resp = get_response(intensity)
print('instensity:', intensity)
print('response:', resp)
staircase.addResponse(resp)
print('estimated params:', staircase.paramEstimate)
```
The code quickly hangs and I get the following output after killing the process through the psychopy runner.
You can see that it gets to trial 28, but never manages to get the intensity for that trial (I also get multiple divide by zero warnings, but these were expected and shouldn't be a problem):
```
###### Running: C:\src\pyproc_skeleton\example_proc\test_30_trials_bug.py ######
Trial 01
instensity: 0.26
response: 1
estimated params: {'threshold': 0.24325967979948604, 'slope': 4.118723588762454, 'lowerAsymptote': 0.5, 'lapseRate': 0.024756452728366574}
Trial 02
instensity: 0.105
response: 1
estimated params: {'threshold': 0.1920826270598394, 'slope': 4.059172112894446, 'lowerAsymptote': 0.5, 'lapseRate': 0.02451792262570404}
Trial 03
instensity: 0.075
response: 1
estimated params: {'threshold': 0.1516429233738644, 'slope': 4.0659489546703265, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.02426099739770531}
Trial 04
instensity: 0.055
response: 1
estimated params: {'threshold': 0.12044162301705288, 'slope': 4.111697806808681, 'lowerAsymptote': 0.5, 'lapseRate': 0.023993658013140132}
Trial 05
instensity: 0.04
response: 1
estimated params: {'threshold': 0.09689970659983882, 'slope': 4.167597960793967, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.023724278997340986}
Trial 06
instensity: 0.035
response: 1
estimated params: {'threshold': 0.07833717303937134, 'slope': 4.2789020233929485, 'lowerAsymptote': 0.5, 'lapseRate': 0.02344308070951303}
Trial 07
instensity: 0.03
response: 1
estimated params: {'threshold': 0.06404886799831408, 'slope': 4.41247606097386, 'lowerAsymptote': 0.5, 'lapseRate': 0.023158141621992343}
Trial 08
instensity: 0.025
response: 1
estimated params: {'threshold': 0.053270839882204886, 'slope': 4.535418831722452, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.022876825220464487}
Trial 09
instensity: 0.02
response: 0
estimated params: {'threshold': 0.08389166160469042, 'slope': 4.245389019493707, 'lowerAsymptote': 0.5, 'lapseRate': 0.023922770076790983}
Trial 10
instensity: 0.04
response: 0
estimated params: {'threshold': 0.1684266828397635, 'slope': 2.8371938459446135, 'lowerAsymptote': 0.5, 'lapseRate': 0.02528602720028894}
Trial 11
instensity: 0.09
response: 1
estimated params: {'threshold': 0.13955323251294266, 'slope': 2.913824036046837, 'lowerAsymptote': 0.5, 'lapseRate': 0.025174588180916155}
Trial 12
instensity: 0.075
response: 0
estimated params: {'threshold': 0.25716814004185956, 'slope': 2.3198154474680917, 'lowerAsymptote': 0.5, 'lapseRate': 0.025697624667170377}
Trial 13
instensity: 0.17
response: 1
estimated params: {'threshold': 0.21943156977579437, 'slope': 2.296127002621462, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.025618579800640355}
Trial 14
instensity: 0.15
response: 1
estimated params: {'threshold': 0.18861364076633894, 'slope': 2.3336083263814587, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.025536686734659503}
Trial 15
instensity: 0.13
response: 0
estimated params: {'threshold': 0.3200556639707851, 'slope': 1.9527337383223107, 'lowerAsymptote': 0.5, 'lapseRate': 0.02591873768768825}
Trial 16
instensity: 0.28
response: 1
estimated params: {'threshold': 0.28226222015039654, 'slope': 1.9365632773232844, 'lowerAsymptote': 0.5, 'lapseRate': 0.025832389244241243}
Trial 17
instensity: 0.26
response: 1
estimated params: {'threshold': 0.25071583493680655, 'slope': 1.9763479844889336, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.025738137652627148}
Trial 18
instensity: 0.205
response: 1
estimated params: {'threshold': 0.22393273825750792, 'slope': 2.0163732041255766, 'lowerAsymptote': 0.5, 'lapseRate': 0.025676267774632413}
Trial 19
instensity: 0.11
response: 1
estimated params: {'threshold': 0.20378258922368658, 'slope': 1.7784540800799016, 'lowerAsymptote': 0.5, 'lapseRate': 0.025816037155610125}
Trial 20
instensity: 0.11
response: 1
estimated params: {'threshold': 0.18476648975861934, 'slope': 1.6369591574474804, 'lowerAsymptote': 0.5, 'lapseRate': 0.025953956717971658}
Trial 21
instensity: 0.105
response: 1
estimated params: {'threshold': 0.16739718024714784, 'slope': 1.5628320396265338, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.02609920290222789}
Trial 22
instensity: 0.105
response: 1
estimated params: {'threshold': 0.15155402666826762, 'slope': 1.548073002805376, 'lowerAsymptote': 0.5000000000000001, 'lapseRate': 0.026247303851674578}
Trial 23
instensity: 0.06
response: 0
estimated params: {'threshold': 0.18837749612304608, 'slope': 1.9502222314599216, 'lowerAsymptote': 0.5, 'lapseRate': 0.02598972141172485}
Trial 24
instensity: 0.205
response: 1
estimated params: {'threshold': 0.17127502477786716, 'slope': 2.0678556953523524, 'lowerAsymptote': 0.49999999999999994, 'lapseRate': 0.025937223762039677}
Trial 25
instensity: 0.115
response: 1
estimated params: {'threshold': 0.1568711302560141, 'slope': 2.0940766815647276, 'lowerAsymptote': 0.5, 'lapseRate': 0.026082502461273464}
Trial 26
instensity: 0.115
response: 1
estimated params: {'threshold': 0.1438493667485003, 'slope': 2.169597449582416, 'lowerAsymptote': 0.5, 'lapseRate': 0.02622814708623823}
Trial 27
instensity: 0.115
response: 1
estimated params: {'threshold': 0.13222535510600558, 'slope': 2.2815858214634157, 'lowerAsymptote': 0.5, 'lapseRate': 0.026374432116910828}
Trial 28
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
C:\Program Files\PsychoPy\lib\site-packages\xarray\core\computation.py:564: RuntimeWarning: divide by zero encountered in log
result_data = func(*input_data)
##### Experiment ended. #####
```