Running code on pavlovia

URL of experiment: https://run.pavlovia.org/arielm123/beat_fit_str

Description of the problem:
Hi everyone,

I’ve been writing an experiment that asks for the user to rate a certain audio stimulus on a scale of 1 to 7. I’ve been writing it in python and have been using the psychopy coder to run it locally where it executes perfectly. I then translated the code into JS and pushed the files onto GitLab in order to run it on pavlovia, however, whenever I pilot the experiment it gets stuck on a white screen that only says: “initializing the experiment…”. I’m not quite sure why this is happening? Any advice would help :slight_smile:

Your error is:

Uncaught TypeError: Failed to resolve module specifier "@future_". Relative references must start with either "/", "./", or "../".

I can see a similar error from March 2020 here Failed to resolve module specifier "scipy/stats"

I would recommend that you recreate your experiment in Builder or at least look at the JS and index.html files for similar experiments created in Builder.

I see. Is there no way to create a pavlovia experiment without the builder? As there are some tasks where I would like to have more customization than what is currently available on the builder. Specifically in terms of how I would like to randomize my trials.

While you can code in jsPsych, it’s much easier to add code components to Builder experiments.

For example, have a look at my Independent Randomisation demo

I created a method that splits a list of audio stimuli into a set number of groups, it then shuffles between what group to choose first, and then again shuffles between the audio files within that group. Afterwards, the experiment runs through the previously shuffled list of audio files, sequentially.

This is the code for method that randomizes the audio files:

def trial_randomizer(trials_list, num_groups):
    grouped_trials=array_split(trials_list, num_groups) 
    shuffle(grouped_trials) 
    for group in grouped_trials:
        shuffle(group) 
    return np.concatenate(grouped_trials).ravel().tolist()

and this is how it is implemented in the experiment:

trials_beat_strength = data.TrialHandler(nReps=1, method='sequential', 
    extraInfo=expInfo, originPath=-1,
    trialList=trial_randomizer(data.importConditions('beat_str.csv'), 2),
    seed=None, name='trials_beat_strength')

How would I implement this method in the builder?

I’ve thought of a few way to do this. However, I think the easiest would be to have one list called useRows which is preset. If necessary it could be created dynamically, however for now I’ll assume that you know the number of rows.

useRows = [‘0:12’,’12:24’]
shuffle(useRows)
Idx = -1

Then have concentric loops around the trial routine. In the inner loop set selected rows to useRows[Idx] and a routine with Idx+=1 in Begin Routine inside the outer loop.

Sorry, but I’m pretty new to psychopy so you’ll need to be more descriptive. Where in the psychopy builder would I write the code that you are recommending?

Something like this
userows.psyexp (5.6 KB)

Thanks for the response, but when I tried this I got this error:

NameError: name 'idx' is not defined

even though I did define it like you did in the example.

Have you used idx in one location and Idx in another?

Yes I was, but I fixed that and it worked well for a few runs but now I am getting another NameError:

NameError: name 'music_sounds' is not defined

music_sounds is the name of the parameter in the conditions file. I’ve double-checked that there are no typos, and I don’t believe that it is an ordering problem as the conditions file is only called upon when the relevant loop begins and not before. It’s also quite odd as sometimes the program works fine, and then randomly I get this NameError.

Do you ever try to edit music_sounds or just read it from the spreadsheet?

No, music_sounds should just be read from the spreadsheet, and then randomized as I’ve explained above.

At the moment I can’t test it at all. I’m getting the following error at your run link

Uncaught TypeError: Failed to resolve module specifier “@future_”. Relative references must start with either “/”, “./”, or “…/”

I was able to get it to work, thanks for all the help!