Tasks¶
Tasks in Ethopy define the experimental protocol by combining experiments, behaviors, and stimuli and specifying their parameters. They serve as configuration files of the experiments.
Task Structure¶
A typical task file consists of three main parts:
- Session Parameters: Global settings of the experiment
- Stimulus/Behavior/Experiment Conditions: Parameters of the respective condition tables
- Experiment Configuration: Setup and execution of the experiment
Basic Structure¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
Using of Task Templates in Ethopy¶
Overview¶
The ethopy-create-task command generates a Python template file for an Ethopy experiment. This template includes default parameters and placeholders that you need to customize for your specific experiment.
Generating a Template¶
To create a task template, run the following command in your terminal:
1 | |
You will be prompted to enter the module paths and class names for the experiment, behavior, and stimuli components. The generated file will include all required parameters with placeholders (...) that need to be filled.
Template Generation Process¶
The script follows these steps:
-
Prompt for Module Paths and Class Names
- Enter the paths relative to
ethopyfor:- Experiment module (e.g.,
experiments.match_port) - Behavior module (e.g.,
behaviors.multi_port) - Stimulus module (e.g.,
stimuli.grating)
- Experiment module (e.g.,
- Enter corresponding class names for each module.
- Enter the paths relative to
-
Validate Imports
- The script attempts to import the specified modules and classes.
- If an import fails, an error message is displayed.
-
Extract Default Parameters
- The script retrieves the parameters from the experiment, behavior, and stimulus classes.
-
Generate a Template File
- A Python file is created with structured sections:
- Session Parameters: General experiment settings
- Experiment Setup: Instantiating the experiment
- Trial Conditions: Configuration for experiments, behaviors, and stimuli
- Condition Merging: Combining all conditions for trial generation
- Execution: Running the experiment
- A Python file is created with structured sections:
-
Save the File
- The template is saved with a default filename (
task_<stimulus>_<date>.py) or a user-specified name.
- The template is saved with a default filename (
Next Steps¶
After generating the template:
- Open the generated file in a text editor.
- Fill in missing parameters where indicated by
... - Customize trial conditions to match your experiment's requirements.
- Run the script to execute the experiment.
By following these steps, you can quickly set up an Ethopy experiment with minimal manual configuration.
Task Identification and Database Integration¶
The task_idx System¶
Ethopy uses a task_idx (task index) system to uniquely identify and manage experiment configurations. This index serves as the primary key linking tasks across the Control and Task database tables.
How task_idx Works¶
-
Task Table Storage:
- Each experimental configuration is stored in the
Tasktable with a uniquetask_idx - The
Tasktable contains:task_idx(primary key): Unique identifier for the taskpath: The actual task filedescription: Human-readable description of the tasktimestamp: The timestamp of the task creation
- Each experimental configuration is stored in the
-
Control Table Usage:
- The
Controltable usestask_idxto specify which experiment configuration to run - When you set
task_idxin the Control table, the system loads the corresponding task configuration file
- The
Creating Tasks¶
1. Session Parameters¶
Session parameters control the overall experiment behavior:
1 2 3 4 5 6 7 8 | |
2. Stimulus Conditions¶
Define the parameters for your stimuli:
1 2 3 4 5 6 7 8 9 10 11 | |
3. Creating Conditions¶
Use the experiment's Block class and make_conditions method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Helper Functions¶
Ethopy provides helper functions for task creation:
Get Parameters¶
1 2 3 4 | |
Format Parameters¶
1 2 3 4 | |
Example Tasks¶
1. Grating Test¶
Visual orientation discrimination experiment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
Best Practices¶
-
Parameter Organization:
- Group related parameters together
- Use descriptive variable names
- Document units in comments
-
Error Handling:
- Validate parameters before running
- Use helper functions to get required parameters
- Check for missing or invalid values
-
Documentation:
- Comment complex parameter combinations
- Document dependencies
- Include example usage
-
Testing:
- Test with different parameter combinations
- Verify stimulus timing
- Check reward delivery
Common Issues¶
-
Parameter Errors:
- Missing required parameters
- Incorrect parameter types
- Invalid parameter combinations
-
Timing Issues:
- Incorrect duration values
- Mismatched trial/stimulus timing
- Intertrial interval problems
-
Hardware Configuration:
- Wrong setup_conf_idx
- Uncalibrated rewad ports
- Missing hardware components
Note: In your tasks, the setup_conf_idx parameter defines which hardware configuration your experiment will use. Learn more about configuring different hardware setups in the Setup Configuration Index guide.