command_executor
This module provides the MaestroCommandExecutor class, a Python interface for managing
Maestro workflow executions via command-line interactions. Maestro is a workflow
management tool used to define, execute, and monitor computational workflows
described in YAML specification files.
The MaestroCommandExecutor class wraps common Maestro CLI commands, allowing users to:
- Run workflows from YAML specification files
- Query the status of running or completed workflows
- Cancel running workflows
- Update configuration parameters (such as throttle, rlimit, and sleeptime) for active workflows
All Maestro operations are executed in subprocesses, and the results (including success status and output messages) are returned for further handling in Python.
MaestroCommandExecutor
Class to execute Maestro commands.
This class essentially acts as a wrapper to Maestro CLI commands.
Methods:
| Name | Description |
|---|---|
execute_command |
Executes a given command in a subprocess. |
run_workflow |
Run a Maestro workflow YAML spec. |
get_statuses |
Given a list of workflows, retrieve their statuses. |
cancel_workflows |
Given a list of workflows, cancel them all. |
update_workflows |
Given a list of workflows, update their configurations. |
Source code in src/mada_tools/workflow/weave/maestro/command_executor.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 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 298 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 | |
cancel_workflows(workflow_dirs)
Cancel one or more running Maestro workflows.
This method will run a subprocess to execute the maestro cancel command.
This command will take in a list of output directories where the output of
currently running workflows are located, shut down any running jobs for these
workflows, and stop any future jobs associated with these workflows from running.
Cancelling a study is not instantaneous. The background conductor is a daemon which spins up periodically, so cancellation occurs the next time the conductor returns from sleeping and sees that a cancel has been triggered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_dirs
|
List[str | Path]
|
A list of paths to Maestro workflow output directories. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple[bool, str]: A tuple containing a success flag and a message. |
Example:
```python
command_executor = MaestroCommandExecutor()
workflows_to_cancel = ["/path/to/workflow/dir", "/path/to/another_workflow/dir"]
success, msg = command_executor.cancel_workflows(workflows_to_cancel)
if success:
print(f"Workflows cancelled successfully: {msg}")
else:
print(f"Failed to cancel workflows: {msg}")
```
Source code in src/mada_tools/workflow/weave/maestro/command_executor.py
execute_command(command, confirm=None)
Given a command, run it as a subprocess and return a tuple indicating success and the output or error message.
This should be how each Maestro command is executed. The try/except clause helps prevent errors from arising and taking down a chat session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
List[str]
|
List of strings representing the command and its arguments to be executed. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple[bool, str]: A tuple containing a success flag and the command output or error message. |
Source code in src/mada_tools/workflow/weave/maestro/command_executor.py
get_statuses(workflow_dirs, layout='flat', disable_theme=False)
Get the statuses of currently running Maestro workflows.
This tool will run a subprocess to execute the maestro status command.
This command will take in a list of output directories where the output of
currently running workflows are located and return their statuses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_dirs
|
List[str | Path]
|
A list of paths to Maestro workflow output directories. |
required |
layout
|
str
|
The layout of the status table. Options are "flat", "legacy", and "narrow". Default "flat". |
'flat'
|
disable_theme
|
bool
|
Turn off styling for the status layout. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple[bool, str]: A tuple containing a success flag and a message. |
Example:
```python
command_executor = MaestroCommandExecutor()
workflows_to_check = ["/path/to/workflow/dir", "/path/to/another_workflow/dir"]
success, msg = command_executor.get_workflow_status(workflows_to_check)
if success:
print(f"Workflow statuses retrieved successfully: {msg}")
else:
print(f"Failed to retrieve workflow statuses: {msg}")
```
Source code in src/mada_tools/workflow/weave/maestro/command_executor.py
run_workflow(workflow_yaml, attempts=1, rlimit=1, throttle=0, sleeptime=60, output_path=None, pgen=None, pargs=None, dry=False, foreground=False, hash_ws=False, use_tmp=False)
Given a workflow YAML file, run the workflow using Maestro.
This method will execute the maestro run command with the provided workflow YAML file in
a subprocess. Behind the scenes of this command, Maestro will convert the workflow YAML into
a DAG, expand parameters/variables throughout the spec file, and excecute the DAG by converting
steps into shell scripts that get executed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_yaml
|
str | Path
|
Path to the Maestro workflow YAML file. |
required |
attempts
|
int
|
Maximum number of submission attempts before a step is marked as failed. Default 1. |
1
|
rlimit
|
int
|
Maximum number of restarts allowed when steps specify a restart command (0 denotes no limit). Default 1. |
1
|
throttle
|
int
|
Maximum number of inflight jobs allowed to execute simultaneously (0 denotes not throttling). Default 0. |
0
|
sleeptime
|
int
|
Amount of time (in seconds) for the manager to wait between job status checks. Default 60. |
60
|
output_path
|
str | Path
|
Output path to place study in (NOTE: overrides OUTPUT_PATH in the specified specification). Default None. |
None
|
pgen
|
str | Path
|
Path to a Python file that defines a custom Maestro ParameterGenerator.
Passed through to |
None
|
pargs
|
List[str] | None
|
Optional arguments to pass to the custom parameter generation
function. Passed through as one or more |
None
|
dry
|
bool
|
Generate the directory structure and scripts for a study but do not launch it. Default False. |
False
|
foreground
|
bool
|
Runs the backend conductor in the foreground instead of using nohup. Default False. |
False
|
hash_ws
|
bool
|
Enable hashing of subdirectories in parameterized studies (NOTE: breaks commands that use parameter labels to search directories). Default False. |
False
|
use_tmp
|
bool
|
make use of a temporary directory for dumping scripts and other Maestro-related files. Default False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple[bool, str]: A tuple containing a success flag and a message. |
Example:
```python
command_executor = MaestroCommandExecutor()
success, msg = command_executor.run_workflow("path/to/workflow.yaml")
if success:
print(f"Workflow running successfully: {msg}")
else:
print(f"Failed to run workflow: {msg}")
```
Source code in src/mada_tools/workflow/weave/maestro/command_executor.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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
update_workflows(workflow_dirs, rlimit=None, throttle=None, sleeptime=None)
Update the configs of running studies (throttle, rlimit, and/or sleep).
This method will run a subprocess to execute the maestro update command.
This command will take in a list of output directories where the output of
currently running workflows are located and rlimit, throttle, and/or sleeptime
settings. It will then update the configurations of any workflow provided
with the new settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_dirs
|
List[str | Path]
|
A list of paths to Maestro workflow output directories. |
required |
rlimit
|
int
|
Maximum number of restarts allowed when steps specify a restart command (0 denotes no limit). Default 1. |
None
|
throttle
|
int
|
Maximum number of inflight jobs allowed to execute simultaneously (0 denotes not throttling). Default 0. |
None
|
sleeptime
|
int
|
Amount of time (in seconds) for the manager to wait between job status checks. Default 60. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple[bool, str]: A tuple containing a success flag and a message. |
Example:
```python
command_executor = MaestroCommandExecutor()
workflows_to_update = ["/path/to/workflow/dir", "/path/to/another_workflow/dir"]
success, msg = command_executor.cancel_workflows(workflows_to_update, rlimit=0, throttle=10, sleeptime=120)
if success:
print(f"Workflows updated successfully: {msg}")
else:
print(f"Failed to update workflows: {msg}")
```