Running a study
***************

The steps below take an experiment that already runs locally through
to real data collection and teardown. They assume you have a server
registered with Dallinger (see Setting up a server). Prolific is the
worked example; CINT and Lab Recruiter differ in the recruiter-
specific steps, which are covered in their guides (CINT (Lucid), Lab
Recruiter).


Before launch
=============


Test the experiment
-------------------

Test in the same order the experiment will be deployed:

1. Take the experiment yourself as a participant, checking the
   instructions, the time each part takes, and edge cases:

      psynet debug local

2. Run the automated bot tests (see Testing back-end logic):

      psynet test local

   Add "--n-bots 3 --parallel" to check that several participants can
   run at once.

3. Run the experiment in Docker locally, so that missing dependencies
   show up before you reach the server:

      psynet debug local --docker

4. If the experiment has an audit (see Audits), review it with "psynet
   audit serve --render".

5. Pilot the experiment on your server (see Pilot).


Check the code and dependencies
-------------------------------

* The experiment must be in a Git repository with at least one commit.
  PsyNet records the deployed commit, whether any deployed file had
  uncommitted changes, and the names of up to 20 such files. "psynet
  export" compares them with your checkout later, so commit everything
  before you deploy and push to your remote. "psynet deploy ssh" lists
  any deployed files with uncommitted changes and, in a terminal, asks
  whether to deploy them anyway (the default is no, which cancels the
  deployment). Without a terminal it only warns.

* The PsyNet and Dallinger versions you tested locally must match
  their pins. Each package's exact pin in "requirements.txt" ("==" or
  a Git commit or release tag) takes precedence; otherwise its pin in
  "constraints.txt" is used, which is where Dallinger is usually
  pinned. "psynet deploy ssh", "psynet debug ssh" and "psynet
  performance-test ssh" check both packages and stop if they differ;
  "psynet debug ssh --use-local-psynet" and "--use-local-dallinger"
  skip the check for that package. If you change "requirements.txt",
  regenerate and commit "constraints.txt" with "psynet generate-
  constraints", then reinstall with "psynet setup". Remote deployment
  refuses to start while a generated "constraints.txt" is out of date
  with "requirements.txt". See Managing dependencies.

* Remote deployment refuses to start while the experiment contains "#
  TODO" or "// TODO" comments in ".py", ".html" or ".js" files.
  Resolve them, or set "SKIP_TODO_CHECK=1".

* Heroku deploys with "--docker" push the image to a registry, so
  "docker_image_base_name" must be set in "config.txt" or
  "~/.dallingerconfig" and name a registry or namespace, for example
  "ghcr.io/<github-user>/<experiment>". SSH deploys don't need it (see
  Setting up a server).


Consent
-------

The timeline must contain a consent page, or "NoConsent" if it needs
none; deployment fails without one. Some recruiters require a
particular consent (CINT requires "LucidConsent"). The built-in
consent forms name the institutions they were written for. Unless your
study is covered by one of those approvals, use a consent page with
your own ethics-approved text (see Consent).


Time estimate and payment
-------------------------

Set "wage_per_hour" and give every page a realistic "time_estimate",
then run:

   psynet estimate

   Estimated maximum reward for participant: £5.0.
   Estimated time to complete experiment: 10 min 0 sec.

The estimate follows the longest route through the timeline and
ignores performance rewards. Check it against real timings from your
own run and the pilot. If the real duration differs by more than about
30%, adjust the "time_estimate" values. Use the estimated reward as
"base_payment", or less if some successful routes through the timeline
are shorter, and the estimated duration as the recruiter's completion
time (for Prolific, "prolific_estimated_completion_minutes"). How
PsyNet computes the bonus on top of "base_payment", and the per-
participant and per-experiment payment limits, are described in
Payment. The usual "wage_per_hour" for each recruiter is in its guide;
for Prolific see Prolific.

In a lab: Agree the payment strategy and total budget with your lab
before launching. If the lab shares a Prolific workspace, ask the
administrator to add funds if the balance does not cover the study.


Title and description
---------------------

Set "title" and "description" in "config.txt" or the experiment's
"config" dictionary (see Configuration). The title is limited to 128
characters. Mention the requirements participants must meet before
they start: a Chrome browser, headphones or a microphone if needed,
and the approximate duration. In the description, say briefly what the
task involves and how you pay participants who do not finish, for
example after a failed pre-screening task or a technical error.

   title = Check recorded texts (Chrome browser, headphones required, ~10–15 mins)
   description = In this experiment you will hear spoken sentences and judge
       the quality of their transcript. You are paid in proportion to how far
       you get through the experiment.

Whether to put the payment in the title depends on the recruiter: do
so on Prolific, not on CINT.


Recruiter settings
------------------

Choose the recruiter (see Choosing a recruiter) and complete its
setup, including credentials in "~/.dallingerconfig", qualifications,
and recruiter-specific configuration keys. For Prolific, see Prolific.


Storage
-------

Experiments with assets need a deployment-ready storage backend: local
storage on the server or S3. "DebugStorage" is only for local
development. See Managing assets.


Translations
------------

If the experiment runs in other languages, set "locale", generate the
translations with "psynet translate", and review the translated
experiment before recruiting. See Internationalization.


Pilot
=====

Pilot the experiment on the server with the "generic" recruiter, which
creates no study on any recruitment platform. Prolific has no sandbox
mode, so this is the way to try the deployed experiment without
recruiting. Set the recruiter in "config.txt":

   [Config]
   recruiter = generic

Shorten the experiment if that makes piloting easier (for example
fewer trials), then launch a debug deployment:

   psynet debug ssh --app my-study-pilot --server your-server.example.org

The experiment is available at "https://my-study-pilot.your-
server.example.org" within a minute or two. The command ends with a
*Ready* summary whose *Participant link* is the single recruitment
link; take the experiment through it yourself and send it to a few
colleagues. Check:

* the median completion time against your estimate;

* that the experiment ends automatically for every route through it;

* that the server stays responsive with several participants at once,
  and that heavy synthesis or analysis steps run fast enough;

* that your analysis scripts work on the pilot data (export it as
  described in Export).

"psynet debug" deployments do not send Slack notifications. Remove the
pilot when you are done:

   psynet destroy ssh --app my-study-pilot --server your-server.example.org


Launch
======

Restore the full version of the experiment if you shortened it, set
the live recruiter, and commit:

   [Config]
   recruiter = prolific

For CINT, "get_lucid_settings()" sets the recruiter; for Lab
Recruiter, use "lab-recruiter".

If your server is only reachable over a VPN, connect to it. Then
deploy from the experiment directory:

   psynet deploy ssh --app my-study --server your-server.example.org

"--app" becomes the first part of the participant URL ("https://my-
study.your-server.example.org"), so use up to 63 lowercase letters,
digits and hyphens, not starting or ending with a hyphen. If your DNS
record only publishes a fixed list of subdomains, the app name must be
one of them. Several experiments can run on one server with different
app names. Without "--app", PsyNet offers the experiment directory's
name, made lowercase with hyphens, and adds "-2", "-3" and so on if
the server already has an app of that name. Press Enter to accept it
or type another name. When the command isn't run in an interactive
terminal, it uses the suggestion and says so.

"--server" is the name you registered the server under (see Setting up
a server). If you omit it and several servers are registered, PsyNet
asks you to choose.

The command builds the experiment image on the server, starts the
experiment's services, and opens recruitment; see How deployment
works. It prepares the experiment's starting database on your computer
first, in a scratch PostgreSQL database and Redis that are removed
afterwards, so a local experiment can keep running while you deploy.
Because the deploy replaces the experiment directory's generated
files, it doesn't run at the same time as a "psynet debug local" or
test session in the same directory: whichever starts second refuses
to. "psynet debug ssh" does the same. When "psynet deploy ssh"
finishes, it prints a *Ready* summary of the participant link, the
dashboard link and user, where the password is saved, the logs command
and, for apps with classic ingress, the log viewer in the browser.
Without a single participant link, the summary shows the recruiter's
message instead (for Prolific, a link to the new draft study). Save
these. Open the dashboard and check that the experiment is running. If
the command fails or hangs, see Troubleshooting deployments.

To redeploy from an earlier export after fixing a problem, see
Deploying from archive.


Review the draft study on Prolific
----------------------------------

PsyNet creates the study as a draft in the workspace and project set
in "~/.dallingerconfig", filling in the title, description, reward,
completion time, completion codes and any qualifications. Open it from
the link in the terminal and check:

* **Payment**: the reward and completion time match your estimate, and
  the formatting of the description is as intended.

* **Process submissions**: PsyNet registers its completion codes with
  automatic approval and completes submissions itself, so you do not
  approve participants by hand. If the draft offers "Manually review"
  or "Approve and pay", keep **Approve and pay**.

* **Places**: the number of participants, taken from
  "initial_recruitment_size". Start with about 10; much smaller
  numbers can make Prolific deprioritize the study.

* **Audience**: the demographic filters. Prolific shows how many
  active participants match them.

* **Concurrent participants**: leave the limit on simultaneous
  participants unset; recruitment has been very slow when it is set.

* **Cost**: set the places temporarily to the total you plan to
  recruit (plus a few if you pre-screen) to see the total cost,
  including Prolific's fee, in the "Study cost" section, and check
  that the workspace balance covers it.

[image: A PsyNet study in the Prolific drafts list][image][image:
Prolific study cost and workspace balance][image]

Preview the study as a participant from the draft. Anything you do in
the preview is saved as a real participant, so stop before the end or
filter yourself out of the data. When everything is right, click
**Publish study**.

"publish_experiment = true" publishes the study immediately instead of
leaving a draft. This saves time when deploying many similar studies,
but removes the chance to check the study on Prolific first.

In a lab: In a shared Prolific account, set the study's internal name
to "<your name> - <short experiment name>" so lab members can tell
whose study a participant message belongs to. Deploy into a project
named after you (see Prolific).


Recruit
=======

Start with a small batch of 5–10 participants. When they have
finished, check before recruiting more:

* the dashboard and logs for errors (see Monitor);

* the real completion time against the estimate; update
  "time_estimate" values and redeploy if it is more than about 30%
  off;

* on Prolific, that no successful submissions are sitting in
  **Awaiting review**, which would mean PsyNet did not complete them;

* an export of the data (see Export).

Then increase the places in batches. On Prolific, open the study,
choose **Action > Increase places**, and enter the number of
*additional* participants. PsyNet typically copes with about 50
simultaneous participants, depending on how efficient the experiment
code is. Keep the median hourly wage on the Prolific study page above
Prolific's minimum.

[image: Increasing places on a Prolific study][image]


Auto-recruit
------------

With "auto_recruit" on, PsyNet adds a place each time a participant
finishes, so the number of active participants stays constant. The
recommended setting at launch is "auto_recruit = false". You can
switch it on and off from the dashboard's home page while the
experiment runs.

[image: Auto-recruit switch on the experiment dashboard][image]

* Only switch it on after the first batch has finished without errors
  or complaints and the data looks right.

* Switch it off at about 90% of the target and recruit the rest by
  hand. In some designs, late participants have little left to do but
  are still paid in full.

* Stopping the study on Prolific does not switch auto-recruit off.


Payment limits
--------------

Recruitment stops when the amount spent reaches
"soft_max_experiment_payment", and PsyNet emails the experimenter.
This is an experiment variable, not a configuration key: set its
initial value in the experiment class's "variables" dictionary, or
change it on the dashboard's **Monitor > Timeline** page while the
experiment runs. See Payment.


Monitor
=======

Check the experiment regularly while participants are taking part.

**Dashboard.** The dashboard link printed at launch opens the same
dashboard for every recruiter. It shows progress through the timeline,
spending, errors, server resources and individual participants; see
The experiment dashboard for each tab.

**Logs.** On servers with classic ingress, Dozzle shows the live logs
of every container on the server. Its URL is printed at launch
("https://logs.your-server.example.org"); the login is described in
Setting up a server. Servers with Cloudflare ingress, such as lab
computers, have no Dozzle (see Cloudflare tunnels (optional)); run the
log command printed at launch instead. With either ingress you can
read the logs over SSH:

   ssh <user>@your-server.example.org
   cd ~/dallinger/my-study
   docker compose logs web

The experiment's services are "web", "worker_1" to "worker_N",
"clock", "redis" and "pgbouncer"; "docker compose logs" without a
service name shows all of them.

**Errors.** The dashboard's **Monitor > Errors** page lists every
recorded error with its stack trace, and **Monitor > Logger** shows
the live log stream; see Error logging. Fix critical errors
immediately, which may mean pausing recruitment and redeploying.

**Participant messages.** On Prolific, participants message you
through Prolific's messaging system; reply promptly. Look the
participant up by their Prolific ID in the Worker ID field of the
dashboard's **Monitor > Participants** page. The participant page has
a **Link for resuming session** you can send them if they can
continue. CINT participants can't contact you through the platform.
Lab Recruiter participants email the address configured in your Lab
Recruiter setup.

Participants who hit an error, fail a pre-screening task or leave
early are paid automatically: they click **Submit to Prolific**,
PsyNet completes the submission with a screen-out payment and tops it
up to the reward they had earned. Do not ask them to return the
submission or pay them by hand unless they never submitted (for
example they closed the error page) or "prolific_pay_unsuccessful" is
false. The payment rules are in Prolific.

**Slack notifications.** Slack notifications report launches, errors
and recruitment changes, and forward new Prolific messages for the
study. They are worth setting up for long or high-risk studies; see
Setting up Slack notifications.

In a lab: Ask your lab administrator which Slack channel and bot token
to use. If your lab maintains scripts for deploying or destroying many
experiments at once, check each generated configuration before launch,
keep app and server names traceable, and export and check data before
scaling up recruitment.


Export
======

Export the data after the first batch, regularly during data
collection, and once more after the last participant has finished:

   psynet export ssh --app my-study --server your-server.example.org

Run the command in the experiment directory the deployment came from.
The export lands in "exports/latest/". The dashboard's Export tab
downloads the same data as "<deployment ID>__export.zip". See
Exporting data for export options.

Once you destroy the app or the server, "psynet export" no longer
works, so treat data you have not exported as lost.

If async jobs are still running, for example analyses of participants'
recordings, "psynet export ssh" (and "psynet export local") ends with
a warning that the export does not include their results. Wait for
them to finish and export again; see Async jobs. Jobs that were lost
before starting, for example when Redis restarted, are failed about an
hour after they were enqueued and then stop counting as pending.


Tear down
=========

When the target number of participants is reached:

1. Stop the study on the recruiter, so that participants can't start a
   study whose server will no longer exist. PsyNet never closes a
   Prolific study itself; stop it from the study page on Prolific, and
   switch off auto-recruit on the dashboard. Each deployment creates a
   new Prolific study, so this applies to every redeploy; you can
   exclude participants of earlier deployments with Prolific's
   filters.

2. Wait until no participants are still taking part.

3. Review payments. On the dashboard's **Monitor > Participants**
   page, handle anyone listed under **Needs payment review**: PsyNet
   meant to pay them a bonus but could not confirm it, and you can pay
   or dismiss it there. On Prolific, check the **Awaiting review**
   list. Successful and screened-out submissions do not appear there;
   the rest are typically people who stopped without submitting,
   submissions PsyNet could not complete (check the experiment's
   notifications), or codes set to manual review. Talk to the
   participant before rejecting a submission.

   [image: Prolific submissions awaiting review][image]

4. Wait until no async jobs are pending, then export the data one
   final time. "psynet export ssh" warns while jobs are still pending.

5. Remove the experiment from the server:

      psynet destroy ssh --app my-study --server your-server.example.org

   After you confirm, the command wakes the app if it is asleep and
   checks for pending async jobs. If some are still pending, it says
   how many and asks you to confirm again, or refuses when it cannot
   ask (for example in a script, or when destroying several apps at
   once). It then asks whether to delete the experiment's data too
   (see Files on the server); pass "--remove-data" or "--keep-data" to
   answer in advance. Finally it stops the experiment's containers and
   removes its folder from the server. Pass "--discard-pending-jobs"
   only if you accept losing their results. If the app cannot be
   checked, for example because its web container is not running, the
   command says why and does not destroy it: start the container and
   try again, or check in the app's logs that its jobs have finished
   and pass "--discard-pending-jobs". Apps deployed with "psynet debug
   ssh" are the exception: they are destroyed anyway, even if they
   recruit real participants.

If the server was provisioned only for this study, tear it down as
well; see Setting up a server. For an EC2 server created with
"dallinger ec2 provision", teardown also removes its DNS records and
server registrations:

   dallinger ec2 teardown --name my-server --region us-east-1

On a computer other than the one that provisioned the server, after a
provision you finished with the printed "servers add" commands, or for
a server provisioned by an older Dallinger, add the "--dns-host" it
was provisioned with.

Once an EC2 server is terminated, anything on it that was not exported
is lost.

In a lab: Move the finished study into your folder on the lab's
Prolific account, and deposit the final export in the lab's data
repository.


Getting help
============

Read the whole stack trace. The last line names the error, but it is
often a symptom of an earlier one further up. Search for the specific
part of the message first (for example a missing key such as
"show_bonus"), then for the error type together with the failing
function, in the PsyNet issue tracker, the Dallinger issue tracker, or
a web search. Many problems come from a mismatch between your local
PsyNet version and the one in "requirements.txt". Common deployment
problems are listed in Troubleshooting deployments.

If you have been stuck for about an hour, ask in a shared place, such
as a PsyNet issue, so others can find the answer. Include what you
were trying to do, the full stack trace, the PsyNet and Dallinger
versions used locally and in "requirements.txt", whether you run in a
virtual environment or Docker, and if possible a minimal example. When
the problem is solved, post what fixed it in the same thread.

In a lab: Search your lab's chat history first, and ask in the lab's
public support channel rather than in direct messages.

See also:

  The PsyNet Deployment Ops and PsyNet experiment monitoring skills.
