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
- References a specific task configuration path stored in the Task table at lab_experiment
- The system automatically loads the corresponding task configuration when the session starts
-
start_time- Scheduled start time for the experiment session
- Format: "HH:MM:SS" (e.g., "09:00:00")
- Default: "00:00:00" (midnight)
- Used to control when experiments can begin running
-
stop_time- Scheduled stop time for the experiment session
- Format: "HH:MM:SS" (e.g., "17:00:00")
- Default: "23:59:00" (11:59 PM)
- Used to control when experiments should go to stop/sleep
- Must be defined if
start_timeis specified
How to Use the Control Table¶
The Control table is automatically updated by the Logger class. You don't need to modify it directly in most cases.
The user only change the status of the experiment from running to stop and from ready to running. The user can aslo change the animal_id, the task_id, start_time and stop_time.
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_pingfield 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
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_tablemethod 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_pingto ensure setups are active - Monitor
queue_sizeto detect potential bottlenecks - Use
statefield 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_liquidto ensure proper reward delivery - Track
trialsto ensure experiment progress - Use
task_idxto verify correct experiment execution
- Monitor