Skip to content
Ben Stone edited this page Mar 25, 2020 · 56 revisions

LambdaExpt is a framework for running Psychology Experiments on Amazon Web Services Lambdas. These lambdas allow us to both run experiments cheaply and at scale. This framework has been developed by the Complex Human Data Hub at the University of Melbourne. It can be used to run individual experiments, experiments on Mechanical Turk, and Research For Experience (REP) experiments.

Getting the LambdaExpt code

To get started download the code from github. You can download the code as a zip file: https://github.com/complex-human-data-hub/LambdaExpt/archive/master.zip

Or install the git program (instructions here) and use it to download the LambdaExpt code: https://github.com/complex-human-data-hub/LambdaExpt.git

Setting up you computer to run the LambdaExpt code

To get the code running on your system will vary slight between different operating systems (Windows, Mac, Linux). In general these are the steps that you will need to follow:

  1. In the LambdaExpt directory (folder) you will need to install a Python3 virtual environment:

    On Windows:

    py -3 -m venv

    On Mac or Linux:

    python3 -m venv venv

NOTE: You will need to have Python3 installed to complete this step, instructions here.

A virtual environment is just a copy of the Python 3 program and the files need to run it, that live a directory that you specify, in this case LambdaExpt/venv. Using a Python3 virtual environment means that we do not mess with your operating systems version of python (that other programs use too).

  1. Next you need to activate the virtual environment.

    On Windows:

    venv\Scripts\activate

    On Mac or Linux:

    source venv/bin/activate

  2. Install the extra python requirements (supporting code) that LambdaExpt needs. You can do this easily with Python's pip package installer. You should be in the LambdaExpt directory and have activated the python3 virtual environment (step 2 above). Then use pip to install the extra requirements:

    pip install -r requirements.txt

Running an experiment on your computer

When creating a LambdaExpt you can run it locally on your computer. This is means you can get things setup and running the way you want them to before publishing it online for the world to see.

LambdaExpt comes with a demo experiment loaded already. So, you should be able to run that straight away.

To run the demo (or any other experiment) locally do the following:

  1. Make sure your Python3 virtual environment is active (as described above)

  2. Issue the following command to run the experiment locally:

    FLASK_APP=experiment.py flask run

  3. You should now be able to access you experiment using the browser on this URL:

    http://localhost:5000/unique-expt

How to create your own experiment

LambdaExpt uses a python library called Flask to create a server that can run your experiment both locally on your computer and online. That is, Flask will serve your html and javascript (jsPsych) code to your browser. That is why we use this flask command to run your experiment locally:

`FLASK_APP=experiment.py flask run`

There are two main files that you can edit to get your own experiment up and running.

1. templates/exp.html

This is where you will put your jsPsych code.

Importing jsPsych plugins

jsPsych uses various plugins to create items on your experiments timeline. You need to link this to your experiment. At the top of templates/exp.html you'll see some jinja2 code that creates these links in your exp.html file. These files that contain these jsPsych plugins are stored in static files directory: LambdaExpt/static/jspsych/plugins

If you need the jsPsych html-keyboard-response plugin, then you need to add it to the top of the templates/exp.html file:

<script src="{{url_for('static', filename='jspsych/plugins/jspsych-html-keyboard-response.js')}}" type="text/javascript"></script>

NOTE: The code between the curly brackets ({{ ... }}) is the jinja2 code. It is telling python to write the url for the static directory, and to add the filename 'jspsych/plugins/jspsych-html-keyboard-response.js' to that static directory, which will create the link: http://localhost:5000/static/jspsych/plugins/jspsych-html-keyboard-response.js

jsPsych code You will add your jsPsych code to run the experiment in the browser between the script tags in the templates/exp.html code:

<script> ... </script>

2. expt_config.py

In this file you can define a function called get_data() to provide your javascript code with any experimental stimuli you might want to load. For example, maybe you will pass it words from a word-list file, or the ordering of your experimental conditions.

Clone this wiki locally