Using of the Control Table¶
The Control table is a critical component in EthoPy that manages experiment execution and setup status. It's part of the lab_experiments
schema and is used primarily when running EthoPy in Service Mode.
Control Table Fields¶
The Control table contains the following important fields:
-
setup
(primary key)- The hostname of the machine running the experiment
- Used to identify different experimental setups
-
status
- Current status of the setup
- Possible values:
- "ready" - Setup is in Welcome gui and ready for a new experiment
- "running" - Experiment is currently running
- "stop" - Request to stop the current experiment
- "exit" - An error has occured and it is in exit
-
last_ping
- Timestamp of the last status update
- Format: "YYYY-MM-DD HH:MM:SS"
- Updated every 5 seconds by default
-
queue_size
- Number of pending operations in the queue
- Indicates the backlog of data waiting to be written to the database
-
trials
- Current trial index in the session
- Tracks progress through the experiment
-
total_liquid
- Total amount of reward delivered in the session
- Used for tracking reward delivery
-
state
- Current state of the experiment
- Reflects which part of the experiment is currently executing (check experiment states)
-
task_idx
- Index of the task to be executed
- Used to determine which experiment configuration to load
How to Use the Control Table¶
1. Service Mode Operation¶
The Control table is automatically updated by the Logger class. You don't need to modify it directly in most cases.
2. Monitoring Experiment Status¶
1 2 3 4 |
|
3. Controlling Experiments¶
The user only change the status of the experiment from running to stop and from ready to running. Also can change the animal_id and the task_id.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Important Notes¶
-
Automatic Updates: The Control table is automatically updated by the Logger class every 5 seconds (default update_period = 5000ms)
-
Status Flow:
- Normal flow: ready -> running
- Stop flow: running -> stop -> ready
- Exit flow: any_status (raised error) -> exit
-
Error Handling:
- If an error occurs during experiment execution, the state field will show "ERROR!"
- Additional error details will be stored in the notes field
-
Monitoring:
- The
last_ping
field can be used to monitor if a setup is active - If a setup hasn't updated its status for a long time, it might indicate issues
- The
-
Thread Safety:
- All Control table operations are thread-safe
- Updates are protected by a thread lock to prevent race conditions
Example Usage in Service Mode¶
1 2 3 4 5 6 7 8 9 10 |
|
Implementation Details¶
The Control table is managed primarily by the Logger class (ethopy.core.logger.Logger
). Key implementation details include:
-
Status Synchronization:
- The
_sync_control_table
method runs in a separate thread - Updates occur every 5 seconds by default
- Uses thread locks to ensure thread-safe operations
- The
-
Setup Information Updates:
1 2 3 4 5 6 7 8
# Example of information updated in each cycle info = { 'last_ping': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'queue_size': self.queue.qsize(), 'trials': self.trial_key['trial_idx'], 'total_liquid': self.total_reward, 'state': self.curr_state, }
-
Error Recovery:
- The system includes automatic error recovery mechanisms
- Failed database operations are retried with increased priority
- Persistent failures trigger system shutdown with error logging
Best Practices¶
-
Status Monitoring:
- Regularly check
last_ping
to ensure setups are active - Monitor
queue_size
to detect potential bottlenecks - Use
state
field to track experiment progress
- Regularly check
-
Error Handling:
- Implement monitoring for "ERROR!" states
- Check notes field for detailed error information
- check ethopy.log to track the issue
-
Resource Management:
- Monitor
total_liquid
to ensure proper reward delivery - Track
trials
to ensure experiment progress - Use
task_idx
to verify correct experiment execution
- Monitor