clabe.steps ¶
Reusable workflow steps.
Each function here builds a step for Workflow.step. The built step is a plain
function whose parameters wire it to other steps by name — session (a Session),
rig (anything with a data_directory) and the built-in launcher — and which carries sensible default
options (register is a barrier, waterlog only warns when it fails); options given when declaring it win:
wf = Workflow("vr-foraging")
wf.step(steps.session())
... # store, trainer_state, rig, ...
wf.step(steps.review("session", "trainer_state", back_to="session"))
wf.step(steps.preflight(checks.free_space(200e9), checks.exists(SHARE)))
wf.step(steps.register()) # barrier: nothing before it can run again
... # run the task, transfer the data
session ¶
session(
*,
experimenter_validator: Callable[[str], str | None]
| None = validate_username,
use_cache: bool = True,
) -> Callable[[Launcher], Session]
A session step asking who is running and on which animal (see SessionBuilder).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experimenter_validator
|
Callable[[str], str | None] | None
|
Validates each experimenter name; |
validate_username
|
use_cache
|
bool
|
Whether to seed the prompts with previously entered values. |
True
|
Source code in src/clabe/steps.py
review ¶
review(
*names: str,
back_to: str | None = None,
title: str = "Confirm session",
) -> Callable[..., None]
A review step showing the outputs of the steps names and asking whether they are right.
"Looks good" continues; "Go back" goes back to back_to (by default the first reviewed step), which runs
again along with everything depending on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
The steps whose outputs to show, in order. |
()
|
back_to
|
str | None
|
The step to go back to when the user does not confirm. |
None
|
title
|
str
|
Title of the review table. |
'Confirm session'
|
Source code in src/clabe/steps.py
preflight ¶
preflight(
*checks: Callable[..., Any],
name: str = "preflight",
title: str = "Preflight checks",
) -> Callable[..., None]
A step running checks (see clabe.checks) and failing once, listing every failure.
The step takes what its checks take, by name (e.g. rig); Retry runs them all again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*checks
|
Callable[..., Any]
|
The checks, e.g. |
()
|
name
|
str
|
The step's name. |
'preflight'
|
title
|
str
|
The step's title. |
'Preflight checks'
|
Source code in src/clabe/steps.py
free_space ¶
free_space(
minimum_bytes: float,
*,
directory: Callable[[Any], PathLike] | None = None,
) -> Callable[..., None]
A free_space step failing (Retry / Go back / Abort) when the rig's data drive is short of space.
The step form of checks.free_space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minimum_bytes
|
float
|
Free space required. |
required |
directory
|
Callable[[Any], PathLike] | None
|
Where the data goes, from the |
None
|
Source code in src/clabe/steps.py
register ¶
A register step (a barrier) creating the session's data directory; returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Callable[[Any], PathLike] | None
|
Where the data goes, from the |
None
|
Source code in src/clabe/steps.py
curriculum ¶
curriculum(
*,
before: Callable[..., Any] | None = None,
upload: bool | Callable[[], bool] = True,
settings: Mapping[str, Any] | None = None,
title: str = "Curriculum",
) -> Callable[..., Any]
A curriculum step suggesting the animal's next stage from this session's data; returns a
CurriculumOutcome, or None when the animal is not on a curriculum.
It takes launcher, session, store and trainer_state by name, and needs a registered session.
When the trainer state is on a curriculum (is_on_curriculum and a stage), it:
- saves the trainer state the session started from to
<session>/behavior/trainer_state.json(an existing file, e.g. when recovering a session, is kept); - calls
before, if given, e.g. to write the past sessions' metrics a curriculum reads; - runs
CurriculumAppon the session folder, and saves its suggestion to<session>/Behavior/Logs/suggestion.json; - writes the suggested trainer state to the store (
Kind.from_trainer_state), unlessuploadsays not to.
wf.step(steps.curriculum(before=write_past_metrics))
recovery.step(steps.curriculum(upload=lambda: ui.confirm("Upload the suggestion?")))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before
|
Callable[..., Any] | None
|
Called before the curriculum runs, with what it takes of |
None
|
upload
|
bool | Callable[[], bool]
|
Whether to write the suggestion to the store, or a function asked when there is one (e.g. a confirmation). |
True
|
settings
|
Mapping[str, Any] | None
|
Other |
None
|
title
|
str
|
The step's title. |
'Curriculum'
|
Source code in src/clabe/steps.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 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 | |
remote ¶
remote(
computer_name: Callable[..., str],
*,
name: str = "remote",
title: str = "Other computer",
allow_dirty: bool = False,
repository: str | None = None,
data_roots: Mapping[str, str] | None = None,
) -> Callable[..., Any]
A step connecting to another rig PC through its daemon; returns its
RemoteRepository, or None when the computer is this one.
It starts the other PC's daemon if it is down (ensure_running) and checks that its checkout matches this one
(verify). The step takes what computer_name takes, by name (as checks do):
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
computer_name
|
Callable[..., str]
|
Gives the other PC's name from earlier outputs, e.g. a rig's |
required |
name
|
str
|
The step's name. |
'remote'
|
title
|
str
|
The step's title. |
'Other computer'
|
allow_dirty
|
bool
|
Accept uncommitted changes in the other PC's checkout. |
False
|
repository
|
str | None
|
The daemon's name for the checkout (default: this repository's folder name). |
None
|
data_roots
|
Mapping[str, str] | None
|
Maps data folders there to the share that exposes them (see |
None
|
Source code in src/clabe/steps.py
waterlog ¶
A waterlog step logging the water the animal earned (only warns when it fails). Needs aind-services.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
earned_water
|
Callable[[Launcher], float]
|
The water earned (mL), computed from the launcher (e.g. from its session directory). |
required |