pickers.default_behavior¶
DefaultBehaviorPickerSettings ¶
Bases: ServiceSettings
Settings for the default behavior picker.
Attributes:
| Name | Type | Description |
|---|---|---|
config_library_dir |
PathLike
|
The directory where configuration files are stored. |
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: Type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> Tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
Type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
Tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |
Source code in src/clabe/services.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
DefaultBehaviorPicker ¶
DefaultBehaviorPicker(
settings: DefaultBehaviorPickerSettings,
launcher: Launcher,
ui_helper: Optional[IUiHelper] = None,
experimenter_validator: Optional[
Callable[[str], bool]
] = validate_username,
rig_validator: Optional[
Callable[[Rig], Rig]
] = validate_rig_computer_name,
use_cache: bool = True,
)
A picker class for selecting rig, session, and task configurations.
Provides methods to initialize directories, pick configurations, and prompt user inputs for various components of the experiment setup. Manages the configuration library structure and user interactions for selecting experiment parameters.
Properties
ui_helper: Helper for user interface interactions trainer_state: The current trainer state config_library_dir: Path to the configuration library directory rig_dir: Path to the rig configurations directory subject_dir: Path to the subject configurations directory task_dir: Path to the task configurations directory
Methods:
| Name | Description |
|---|---|
pick_rig |
Picks the rig configuration |
pick_session |
Picks the session configuration |
pick_task |
Picks the task configuration |
pick_trainer_state |
Picks the trainer state configuration |
choose_subject |
Allows the user to choose a subject |
prompt_experimenter |
Prompts for experimenter information |
dump_model |
Saves a Pydantic model to a file |
Initializes the DefaultBehaviorPicker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
DefaultBehaviorPickerSettings
|
Settings containing configuration including config_library_dir. By default, attempts to rely on DefaultBehaviorPickerSettings to automatic loading from yaml files |
required |
launcher
|
Launcher
|
The launcher instance for managing experiment execution |
required |
ui_helper
|
Optional[IUiHelper]
|
Helper for user interface interactions. If None, uses launcher's ui_helper. Defaults to None |
None
|
experimenter_validator
|
Optional[Callable[[str], bool]]
|
Function to validate the experimenter's username. If None, no validation is performed. Defaults to validate_username |
validate_username
|
rig_validator
|
Optional[Callable[[Rig], Rig]]
|
Function to validate the rig configuration. If None, no validation is performed. Defaults to validate_rig_computer_name |
validate_rig_computer_name
|
use_cache
|
bool
|
Whether to use caching for selections. Defaults to True |
True
|
Source code in src/clabe/pickers/default_behavior.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
ui_helper
property
¶
ui_helper: IUiHelper
Retrieves the registered UI helper.
Returns:
| Name | Type | Description |
|---|---|---|
UiHelper |
IUiHelper
|
The registered UI helper |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no UI helper is registered |
trainer_state
property
¶
trainer_state: TrainerState
Returns the current trainer state.
Returns:
| Name | Type | Description |
|---|---|---|
TrainerState |
TrainerState
|
The current trainer state |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the trainer state is not set |
session_directory
property
¶
session_directory: Path
Returns the directory path for the current session.
config_library_dir
property
¶
config_library_dir: Path
Returns the path to the configuration library directory.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The configuration library directory |
rig_dir
property
¶
rig_dir: Path
Returns the path to the rig configuration directory.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The rig configuration directory |
subject_dir
property
¶
subject_dir: Path
Returns the path to the subject configuration directory.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The subject configuration directory |
task_dir
property
¶
task_dir: Path
Returns the path to the task configuration directory.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The task configuration directory |
pick_rig ¶
pick_rig(model: Type[TRig]) -> TRig
Prompts the user to select a rig configuration file.
Searches for available rig configuration files and either automatically selects a single file or prompts the user to choose from multiple options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Type[TRig]
|
The rig model type to validate against |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TRig |
TRig
|
The selected rig configuration |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rig configuration files are found or an invalid choice is made |
Source code in src/clabe/pickers/default_behavior.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
pick_session ¶
pick_session(model: Type[TSession] = Session) -> TSession
Prompts the user to select or create a session configuration.
Collects experimenter information, subject selection, and session notes to create a new session configuration with appropriate metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Type[TSession]
|
The session model type to instantiate. Defaults to Session |
Session
|
Returns:
| Name | Type | Description |
|---|---|---|
TSession |
TSession
|
The created or selected session configuration |
Source code in src/clabe/pickers/default_behavior.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
pick_task ¶
pick_task(model: Type[TTask]) -> TTask
Prompts the user to select or create a task configuration.
Attempts to load task in the following order: 1. From CLI if already set 2. From subject-specific folder 3. From user selection in task library
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Type[TTask]
|
The task model type to validate against |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TTask |
TTask
|
The created or selected task configuration |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid task file is found |
Source code in src/clabe/pickers/default_behavior.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
pick_trainer_state ¶
Prompts the user to select or create a trainer state configuration.
Attempts to load trainer state in the following order: 1. If task already exists in launcher, will return an empty TrainerState 2. From subject-specific folder
It will launcher.set_task if the deserialized TrainerState is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_model
|
Type[TTask]
|
The task model type to validate against |
required |
Returns:
| Type | Description |
|---|---|
tuple[TrainerState, TTask]
|
tuple[TrainerState, TTask]: The deserialized TrainerState object and validated task |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid task file is found or session is not set |
Source code in src/clabe/pickers/default_behavior.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
choose_subject ¶
Prompts the user to select or manually enter a subject name.
Allows the user to either type a new subject name or select from existing subject directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | PathLike
|
Path to the directory containing subject folders |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The selected or entered subject name. |
Example
# Choose a subject from the subjects directory
subject = picker.choose_subject("Subjects")
Source code in src/clabe/pickers/default_behavior.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
prompt_experimenter ¶
Prompts the user to enter the experimenter's name(s).
Accepts multiple experimenter names separated by commas or spaces. Validates names using the configured validator function if provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strict
|
bool
|
Whether to enforce non-empty input. Defaults to True |
True
|
Returns:
| Type | Description |
|---|---|
Optional[List[str]]
|
Optional[List[str]]: List of experimenter names |
Example
# Prompt for experimenter with validation
names = picker.prompt_experimenter(strict=True)
print("Experimenters:", names)
Source code in src/clabe/pickers/default_behavior.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
dump_model ¶
Saves the provided model to the appropriate configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Union[Rig, Task, TrainerState]
|
The model instance to save |
required |
Returns:
| Type | Description |
|---|---|
Optional[Path]
|
Optional[Path]: The path to the saved model file, or None if not saved |
Source code in src/clabe/pickers/default_behavior.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |