API Reference
sdag.
commands
CLI commands.
Commands executed through the CLI. It's the point of contact between the Python API and the Rust core.
compile_and_return_dag(path, extra_metadata, input_kwargs)
Compile a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Pipeline name or import string. |
required |
extra_metadata
|
Any
|
Extra metadata that will be attached to the pipeline. |
required |
input_kwargs
|
dict[str, Any]
|
Pipeline input kwargs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DAG |
DAG
|
Compiled graph. |
Source code in python/sdag/commands.py
compile_pipeline(args, extras)
Compile a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra args turned into input kwargs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path where the compiled JSON has been saved. |
Source code in python/sdag/commands.py
describe_pipeline(args, extras)
Describe a pipeline arguments, caching, and artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra arguments used for compiling. |
required |
Source code in python/sdag/commands.py
get_task(name, pipeline_name)
Import a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Task name. |
required |
pipeline_name
|
str
|
Name of the pipeline using the task. |
required |
Raises:
| Type | Description |
|---|---|
DAGNotFoundError
|
The task cannot be found. |
Returns:
| Name | Type | Description |
|---|---|---|
Task |
Task
|
Task. |
Source code in python/sdag/commands.py
kill_pipeline(args, extras)
Kill a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra args (not allowed). |
required |
Raises:
| Type | Description |
|---|---|
ExtraCLIArgsError
|
Extra argument used. |
Source code in python/sdag/commands.py
list_pipelines(args, extras)
List pipelines and runs.
By default, pipelines are listed. If the pipeline name is specified, then run hashes are listed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra arguments (not allowed) |
required |
Raises:
| Type | Description |
|---|---|
ExtraCLIArgsError
|
Extra argument used. |
Source code in python/sdag/commands.py
print_status(args, extras)
Describe a pipeline arguments, caching, and artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra arguments used for compiling. |
required |
Source code in python/sdag/commands.py
prune_cache(args, extras)
Prune the cache of tasks or pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra args (not allowed). |
required |
Raises:
| Type | Description |
|---|---|
ExtraCLIArgsError
|
Extra argument used. |
Source code in python/sdag/commands.py
restart_run(args, extras)
Restart a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra args (not allowed). |
required |
Raises:
| Type | Description |
|---|---|
ExtraCLIArgsError
|
Extra argument used. |
Source code in python/sdag/commands.py
retry_run(args, extras)
Retry a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra args (not allowed). |
required |
Raises:
| Type | Description |
|---|---|
ExtraCLIArgsError
|
Extra argument used. |
Source code in python/sdag/commands.py
run_pipeline(args, extras)
Run a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed arguments. |
required |
extras
|
dict[str, Any]
|
Extra arguments only used if the pipeline must be compiled. |
required |
Source code in python/sdag/commands.py
run_task(args, extras)
Run a single task without starting the scheduler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra arguments used for compilation. |
required |
Source code in python/sdag/commands.py
view_pipeline(args, extras)
Visualize a pipeline in the terminal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed args. |
required |
extras
|
dict[str, Any]
|
Extra arguments only used if the pipeline is not read from JSON. |
required |
Source code in python/sdag/commands.py
compiler
Compiler.
It relies on two global objects everyone has access to, so it is not thread safe.
compiler = DAGCompiler()
module-attribute
Compiler.
master = SDAG()
module-attribute
Keeps track of imported pipelines and tasks.
DAGCompiler
Compiler.
It does most of the magic, keeps track of the graph and updates it when tasks are executed.
Attributes:
| Name | Type | Description |
|---|---|---|
outer |
list[CompiledDAG]
|
Pipelines being compiled. |
active |
CompiledDAG | None
|
Active pipeline compiled. |
_uid |
int
|
Used to assign monotonically increasing uids. |
Source code in python/sdag/compiler.py
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 | |
current_scope
property
TraceScope currently active in the pipeline being traced.
Raises:
| Type | Description |
|---|---|
DAGNotSetError
|
No pipelines are being compiled. |
Returns:
| Name | Type | Description |
|---|---|---|
TraceScope |
TraceScope
|
Current scope. |
__init__()
close_clause(branch_uid, next_edge_value, terminal=False)
Record a closed branch for the next Elif/Else.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch_uid
|
int
|
Uid of the BranchNode the clause evaluated. |
required |
next_edge_value
|
bool
|
Branch edge value a following Elif/Else must depend on. |
required |
terminal
|
bool
|
True if this clause was an Else, closing the chain to further Elif/Else. |
False
|
Source code in python/sdag/compiler.py
get_dag()
Detach a dag from the compiler.
Raises:
| Type | Description |
|---|---|
DAGNotSetError
|
No DAGs are set. |
Returns:
| Type | Description |
|---|---|
tuple[DAG, RootNode, EndNode]
|
tuple[DAG, RootNode, EndNode]: Graph, root, and endnode. |
Source code in python/sdag/compiler.py
get_uid()
pop_scope()
Exit the current lexical scope, restoring its parent.
Raises:
| Type | Description |
|---|---|
DAGNotSetError
|
No pipelines are being compiled, or attempting to pop the pipeline's root scope. |
Returns:
| Name | Type | Description |
|---|---|---|
TraceScope |
TraceScope
|
The scope that was just closed. |
Source code in python/sdag/compiler.py
push_scope(anchor)
Enter a new lexical scope, e.g. an If/Elif/Else body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anchor
|
tuple[int, bool] | None
|
(branch_uid, branch_value) stamped on every node registered in the new scope. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TraceScope |
TraceScope
|
The newly active scope. |
Source code in python/sdag/compiler.py
register(node)
Register a node in the graph.
If a branch scope is currently active, the node is given a branch edge to it, tying it to that branch's true/false path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
NodeUnion
|
Node. |
required |
Raises:
| Type | Description |
|---|---|
DAGNotSetError
|
Attempting to register a node but no pipelines are being compiled. |
Source code in python/sdag/compiler.py
reset()
set_dag(root, import_path=None)
Set a new dag.
Every time a new pipeline is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
RootNode
|
Pipeline root node. |
required |
import_path
|
str | None
|
Pipeline import path. If null, it defaults to the pipeline name. Defaults to None. |
None
|
Source code in python/sdag/compiler.py
SDAG
Master.
Keeps track of the imported pipelines and tasks. An error is raised is two tasks with the same name are imported.
Attributes:
| Name | Type | Description |
|---|---|---|
tasks |
dict[str, Task]
|
Imported (global) tasks. |
pipelines |
dict[str, Pipeline]
|
Imported pipelines. |
Source code in python/sdag/compiler.py
__init__()
add_pipeline(pipeline)
Add a pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline
|
Pipeline
|
Pipeline imported. |
required |
add_task(task)
Add a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
Add a task. |
required |
Raises:
| Type | Description |
|---|---|
TaskNotUniqueError
|
The task is not unique. |
Source code in python/sdag/compiler.py
constants
POSIX_ENV_VARIABLES = ['ARFLAGS', 'IFS', 'MAILPATH', 'PS1', 'CC', 'LANG', 'MAILRC', 'PS2', 'CDPATH', 'LC_ALL', 'MAKEFLAGS', 'PS3', 'CFLAGS', 'LC_COLLATE', 'MAKESHELL', 'PS4', 'CHARSET', 'LC_CTYPE', 'MANPATH', 'PWD', 'COLUMNS', 'LC_MESSAGES', 'MBOX', 'RANDOM', 'DATEMSK', 'LC_MONETARY', 'MORE', 'SECONDS', 'DEAD', 'LC_NUMERIC', 'MSGVERB', 'SHELL', 'EDITOR', 'LC_TIME', 'NLSPATH', 'TERM', 'ENV', 'LDFLAGS', 'NPROC', 'TERMCAP', 'EXINIT', 'LEX', 'OLDPWD', 'TERMINFO', 'FC', 'LFLAGS', 'OPTARG', 'TMPDIR', 'FCEDIT', 'LINENO', 'OPTERR', 'TZ', 'FFLAGS', 'LINES', 'OPTIND', 'USER', 'GET', 'LISTER', 'PAGER', 'VISUAL', 'GFLAGS', 'LOGNAME', 'PATH', 'YACC', 'HISTFILE', 'LPDEST', 'PPID', 'YFLAGS', 'HISTORY', 'MAIL', 'PRINTER', 'HISTSIZE', 'MAILCHECK', 'PROCLANG', 'HOME', 'MAILER', 'PROJECTDIR']
module-attribute
POSIX environment variables, taken from: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html.
It would be dangerous to override these variables with user-defined input arguments. So, if any of these variables is used as input for an external task, an exception is thrown.
core
__all__ = ['run', 'restart_run', 'kill_run', 'prune_cache', 'view_pipeline', 'run_single_task', 'print_pipeline_list', 'print_runs', 'describe_pipeline', 'print_status']
module-attribute
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
__doc__ = ''
module-attribute
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__file__ = '/leonardo_scratch/fast/BOOST_EUROPA/arognoni/tests/sdag/python/sdag/core.abi3.so'
module-attribute
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__name__ = 'python.sdag.core'
module-attribute
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__package__ = 'python.sdag'
module-attribute
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
detach
Job detaching.
detach_command()
Detach an sdag command.
Source code in python/sdag/detach.py
discovery
Pipeline discovery and lazy import.
Pipelines are discovered via AST parsing, so we don't have to explicitely import files.
add_cwd_to_path()
find_all_pipelines()
Find all importable pipelines.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
dict[str, str]: Pipeline names and paths. |
Source code in python/sdag/discovery.py
find_pipeline_by_name(name)
Import a pipeline from its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
If the name is provided, the
pipeline is discovered and imported. If the
input path in the form |
required |
Raises:
| Type | Description |
|---|---|
DAGNotFoundError
|
The DAG is not found in the path. |
Returns:
| Name | Type | Description |
|---|---|---|
Pipeline |
Pipeline
|
Imported pipeline. |
Source code in python/sdag/discovery.py
get_importable_module_path(path)
Turn a module path into its import string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Module path. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Import string. |
Source code in python/sdag/discovery.py
entrypoints
sdag entrypoints.
cli()
CLI entrypoint.
Source code in python/sdag/entrypoints.py
sdag_execute(configure_logger=True)
Task entry point.
This is the function called by script to run wrapping tasks.
It is also possible to use the sdag-execute command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configure_logger
|
bool
|
Whether to configure the default logger. Defaults to True. |
True
|
Source code in python/sdag/entrypoints.py
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 | |
exceptions
Custom exceptions.
CLIError
DAGNotFoundError
DAGNotSetError
DynamicArtifactError
Bases: SDAGError
Dynamic artifacts are not allowed.
Source code in python/sdag/exceptions.py
__init__(key)
Raise the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Input key not found. |
required |
ExtraCLIArgsError
Bases: SDAGError
Extra CLI arguments are not allowed.
Source code in python/sdag/exceptions.py
__init__(extra_kwargs)
Raise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extra_kwargs
|
dict[str, Any]
|
Extra args used. |
required |
Source code in python/sdag/exceptions.py
InconsistentArraySettingsError
Bases: SDAGError
Job array settings are not consistent.
Shard path and task id must be either both None or set to a valid value.
Source code in python/sdag/exceptions.py
__init__(shard_path, task_id, each)
Raise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shard_path
|
Path | None
|
Shard input path. |
required |
task_id
|
int | None
|
Slurm array task id. |
required |
each
|
str | None
|
Sharded key. |
required |
Source code in python/sdag/exceptions.py
IncorrectElifError
IncorrectElseError
KwargNotFoundError
Bases: SDAGError
Task input kwarg not found.
Source code in python/sdag/exceptions.py
__init__(key)
Raise the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Input key not found. |
required |
MultipleEachError
Bases: SDAGError
Job arrays across multiple axes is not supported.
Source code in python/sdag/exceptions.py
__init__(key, old_key)
Raise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
New key of the job array. |
required |
old_key
|
str
|
Old key of the job array. |
required |
Source code in python/sdag/exceptions.py
POSIXOverrideError
Bases: SDAGError
External tasks have variables conflicting with POSX.
Source code in python/sdag/exceptions.py
__init__(task_name, key)
Raise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
Task violating the check. |
required |
key
|
str
|
Forbidden key used. |
required |
Source code in python/sdag/exceptions.py
SDAGError
TaskNotUniqueError
Bases: SDAGError
Task name is not unique.
Source code in python/sdag/exceptions.py
__init__(name)
Raise the error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Not unique task name. |
required |
io
Task I/O management.
IOHandler
Manage I/O.
Attributes:
| Name | Type | Description |
|---|---|---|
uid |
int
|
Task uid. |
_pipeline_fname |
DAG filename. |
|
_output_fname |
Node output filename as specified in the scheduler. |
|
_input_fname |
Node output filename as specified in the scheduler. |
|
_shard_fname |
Sharded input filename as specified in the scheduler. |
Source code in python/sdag/io.py
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 | |
__init__(uid, pipeline_dir, shard_path, task_id, each_key)
Initialize the I/O handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uid
|
int
|
Task unique UID. |
required |
pipeline_dir
|
Path
|
Pipeline working directory. |
required |
shard_path
|
Path | None
|
Shard path. |
required |
task_id
|
int | None
|
Array task id. |
required |
each_key
|
str | None
|
Sharded field in the array. |
required |
Source code in python/sdag/io.py
cast_values(sig, input_kwargs)
Automatically cast to Path if required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sig
|
Signature
|
Task signature. |
required |
input_kwargs
|
dict[str, Any]
|
Input arguments. |
required |
Source code in python/sdag/io.py
get_array_input(sig)
Read the array shard input data.
It's written by the scheduler in the node directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shard_path
|
Path
|
Shard base path. |
required |
task_id
|
int
|
ID of the task in the array. |
required |
each_key
|
str
|
Sharded key. |
required |
sig
|
Signature
|
Task signature used to validate the input values. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Task input kwargs. |
Source code in python/sdag/io.py
get_artifacts(sig, input_kwargs)
Build artifacts for execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sig
|
Signature
|
Task function signature. |
required |
input_kwargs
|
dict[str, Any]
|
Input data. Those corresponding to artifacts will be turned into paths. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ArtifactEdge]
|
dict[str, ArtifactEdge]: Artifact keys and artifacts. They will be merged with the input_kwargs. |
Source code in python/sdag/io.py
get_input(sig)
Read the input data.
It's written by the scheduler in the node directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sig
|
Signature
|
Task signature used to validate the input values. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Task input kwargs. |
Source code in python/sdag/io.py
serialize_array_output(output, artifacts)
Serialize a shard of output as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Any
|
Node output. |
required |
artifacts
|
dict[str, ArtifactEdge]
|
Output artifacts. |
required |
Source code in python/sdag/io.py
serialize_artifacts(artifacts)
Serialize artifacts as string for logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artifacts
|
dict[str, ArtifactEdge]
|
Artifacts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Serialized artifacts. |
Source code in python/sdag/io.py
serialize_output(output, artifacts)
Serialize the output as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Any
|
Node output. |
required |
artifacts
|
dict[str, ArtifactEdge]
|
Output artifacts. |
required |
Source code in python/sdag/io.py
find_and_import_task(task_name, pipeline_name, subpipeline_name, import_path, input_kwargs)
Sufficiently clever way to import tasks.
- Check if the pipeline/task is already imported
- import the pipeline with the import path
- Try to import the subpipeline from its name
- Compile the pipeline to import the subtask
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_name
|
str
|
Task name. |
required |
pipeline_name
|
str
|
Pipeline name. |
required |
subpipeline_name
|
str
|
Subpipeline name. |
required |
import_path
|
str
|
Pipeline import path. |
required |
input_kwargs
|
str
|
Input kwargs used to compile the pipeline serialized as a JSON string. Useful to recompile the pipeline. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Task |
Task
|
Imported task. |
Source code in python/sdag/io.py
mod_hashing
ModuleHasher
Hash modules.
Attributes:
| Name | Type | Description |
|---|---|---|
_excluded |
list[Path]
|
Paths that must be excluded. They include stuff like builtins, third-party libraries etc. |
_cwd |
Path
|
Current working directory. |
Source code in python/sdag/mod_hashing.py
13 14 15 16 17 18 19 20 21 22 23 24 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 | |
__init__()
hash_modules()
Hash internal modules.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Computed hash. If no modules are found, an empty string is returned. |
Source code in python/sdag/mod_hashing.py
models
sdag models.
Artifact = Annotated[T, ArtifactSig]
module-attribute
Artifact.
Artifacts are used to signal that some assets are being written. It is possible to use either Artifact[str] or Artifact[Path], they are automatically cast.
NodeUnion = Annotated[TaskNode | RootNode | EndNode | BranchNode | OneOfNode, Field(discriminator='kind')]
module-attribute
Node union.
ParentKindUnion = Annotated[LogicalParent | OutputParent | ArtifactParent | BranchParent, Field(discriminator='kind')]
module-attribute
Parent types.
ScriptUnion = Annotated[ScriptContent | ScriptPath, Field(discriminator='kind')]
module-attribute
Script content or path.
ArtifactContainer
Artifact wrapper.
Hack to pass the node to the child alongside artifacts.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
Artifact key. |
path |
str
|
Artifact path. |
node |
Node
|
Parent node. |
Source code in python/sdag/models.py
__init__(key, path, node)
Initialize the artifact container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Artifact key. |
required |
path
|
str
|
Artifact path. |
required |
node
|
Node
|
Parent node. |
required |
Source code in python/sdag/models.py
ArtifactEdge
Bases: BaseModel
Artifact edge.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Artifact name. |
path |
Path
|
Artifact path. |
Source code in python/sdag/models.py
ArtifactParent
Bases: BaseModel
Artifact edge.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['artifact']
|
Artifact kind. |
key |
str
|
Artifact key. |
name |
str
|
Artifact name. |
path |
str
|
Artifact path. |
Source code in python/sdag/models.py
ArtifactSig
BaseNode
Bases: BaseModel
Node base class.
Attributes:
| Name | Type | Description |
|---|---|---|
parents |
list[Parent]
|
Parents. |
uid |
int
|
Unique id. |
root_uid |
int
|
Pipeline root unique id (added during compilation. Defaults to -1. |
pipeline_name |
str
|
Pipeline name, added during compilation. Defaults to ''. |
Source code in python/sdag/models.py
add_branch_edge(parent_uid, branch)
Add a child -> parent branch edge.
The child depends on one of the branches of an IfNode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_uid
|
int
|
Parent uid. |
required |
branch
|
bool
|
Branch the child depends on. |
required |
Source code in python/sdag/models.py
add_logical_edge(parent_uid)
Add a child->parent logical edge.
It is a logical dependence, no data exchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_uid
|
int
|
Parent uid. |
required |
Source code in python/sdag/models.py
BranchNode
BranchParent
Bases: BaseModel
Branch edge.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['branch']
|
Kind. |
branch |
bool
|
Branch. |
Source code in python/sdag/models.py
CacheableTask
Bases: BaseModel
Cacheable task.
Info about tasks with caching enabled.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Task name. |
pipeline |
str
|
Pipeline name. |
scope |
Scope
|
Task scope. |
Source code in python/sdag/models.py
ClosedClause
dataclass
A closed If/Elif/Else clause, kept so the next Elif/Else can chain.
Attributes:
| Name | Type | Description |
|---|---|---|
branch_uid |
int
|
Uid of the BranchNode this clause evaluated. |
next_edge_value |
bool
|
Branch edge value a following Elif/Else must depend on to run. |
terminal |
bool
|
True once an Else has closed the chain, so no further Elif/Else may follow. |
Source code in python/sdag/models.py
CompiledDAG
Bases: BaseModel
Pipeline being compiled.
Attributes:
| Name | Type | Description |
|---|---|---|
dag |
DAG
|
DAG. |
root |
RootNode
|
Root node. |
end |
EndNode
|
End node. |
scope |
TraceScope
|
Lexical scope currently active while tracing this pipeline's body. |
Source code in python/sdag/models.py
DAG
DAGMeta
Bases: BaseModel
DAG metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
pipeline_name |
str
|
Pipeline name. |
timestamp |
str
|
Timestamp. |
import_path |
str
|
Import path. |
code_hash |
str
|
Hash of all modules imported. It is added after pipeline compilation. |
kwargs |
dict[str, Any]
|
Pipeline input kwargs. |
extra |
str
|
Extra metadata. |
Source code in python/sdag/models.py
set_path_to_pipeline_name_if_missing()
Set the import path to the pipeline name if null.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Metadata. |
Source code in python/sdag/models.py
Each
Signal job arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
collection |
list[Any] | TaskNode
|
Inner keyword argument. |
Source code in python/sdag/models.py
__init__(collection)
Initialize the array collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
list[Any] | TaskNode
|
Inner collection. It can be either a static or dynamic list. |
required |
EndNode
Bases: BaseNode
End node.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['end']
|
Kind. |
_artifact_container |
dict[str, dict[str, ArtifactContainer]]
|
Used to make artifact edges. |
Source code in python/sdag/models.py
artifacts
property
Artifacts.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, ArtifactContainer]]
|
dict[str, dict[str, ArtifactContainer]]: Artifacts. |
Kwarg
LogicalParent
Bases: BaseModel
Logical parent kind.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['logical']
|
Kind. |
Source code in python/sdag/models.py
OneOfNode
Bases: BaseNode
OneOf node.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['one_of']
|
Kind. |
name |
str
|
Node name. |
output_artifacts |
list[ArtifactEdge]
|
Artifact edge. |
_artifact_containers |
dict[str, ArtifactContainer]
|
Used to make artifact edges. |
Source code in python/sdag/models.py
artifacts
property
Get the artifacts.
Returns:
| Type | Description |
|---|---|
dict[str, ArtifactContainer]
|
dict[str, ArtifactContainer]: Artifacts. |
add_logical_edge(parent_uid)
Add a child->parent logical edge.
It is a logical dependence, no data exchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_uid
|
int
|
Parent uid. |
required |
Source code in python/sdag/models.py
OutputParent
Bases: BaseModel
Output edge.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['outout']
|
Kind. |
key |
str
|
Field name. |
Source code in python/sdag/models.py
Parent
Bases: BaseModel
Edge in the graph.
Attributes:
| Name | Type | Description |
|---|---|---|
uid |
int
|
Parent type. |
kind |
str
|
Edge type. |
Source code in python/sdag/models.py
RootNode
Bases: BaseNode
Root node.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['root']
|
Kind. |
root_uid |
int
|
Same as uid. |
Source code in python/sdag/models.py
ScriptContent
Bases: BaseModel
Script embedded in the pipeline definition.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['script']
|
Script kind. |
content |
str
|
Script content. |
Source code in python/sdag/models.py
ScriptPath
Bases: BaseModel
Script path.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['script_path']
|
Script path. |
path |
Path
|
Path. |
Source code in python/sdag/models.py
SlurmOverride
Bases: BaseModel
Override Slurm arguments.
They must be set following the Slurm conventions.
Attributes:
| Name | Type | Description |
|---|---|---|
job_name |
str | None
|
(str | None): Job name. Defaults to None. |
nodes |
NonNegativeInt | None
|
(int | None): Number of nodes. Defaults to None. |
partition |
str | None
|
(str | None): Partition. Defaults to None. |
qos |
str | None
|
(str | None) = qos. Defaults to None. |
gpus_per_node |
NonNegativeInt | None
|
(int | None): GPUs per node. Defaults to None. |
ntasks_per_node |
NonNegativeInt | None
|
(int | None): Tasks per node. Defaults to None. |
output |
str | None
|
(str | None): stdout. Defaults to None. |
error |
str | None
|
(str | None): stderr. Defaults to None. |
account |
str | None
|
(str | None): Account. Defaults to None. |
cpus_per_task |
int | None
|
CPUs per task. Defaults to None. |
mem |
str | None
|
(str | None): Memory. Defaults to None. |
time |
str | None
|
(str | None): Wall time. Defaults to None. |
Source code in python/sdag/models.py
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 329 330 331 332 | |
override_from(other)
Override slurm configs from another set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Self
|
Slurm configurations overriding the current ones in place. |
required |
Source code in python/sdag/models.py
TaskNode
Bases: BaseNode
Task.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['task']
|
Kind. |
parents |
list[Parent]
|
Edges. |
fn_name |
str
|
Function name. |
scope |
Scope
|
Task scope. |
name |
str
|
Task name, linked to caching. |
cache |
CacheOptions
|
Caching options. |
cache_ignore |
list[str]
|
list of fields ignored during cache validation. |
cache_size |
int
|
Cache size. Ignore if caching is disabled. set to 0 to allow for infinite cache size. Defaults to 1. |
code_hash |
str
|
Task source code hash. |
mode |
ExecMode
|
Wrap a Python function or an external script. |
cmd |
Commands
|
Command used to launch the script. |
retries |
int
|
Retries. |
each |
str | None
|
If not null, it's the key of the array field. Defaults to None. |
njobs |
int
|
Number of jobs if it defines an array. Defaults to 1. |
script |
ScriptUnion
|
Script path or content. |
tags |
list[str]
|
Task tags. |
kwargs |
list[Kwarg]
|
Input kwargs. |
envs |
dict[str, Any]
|
Environment variables. They will be set in the task as strings. |
slurm |
SlurmOverride
|
Override Slurm resources. |
output_artifacts |
list[ArtifactEdge]
|
Artifacts. |
_artifact_containers |
dict[str, ArtifactContainer]
|
Used to add edges to the graph. |
Source code in python/sdag/models.py
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 364 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 407 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 448 449 450 451 452 453 454 455 456 457 458 | |
artifacts
property
Get the artifacts.
Returns:
| Type | Description |
|---|---|
dict[str, ArtifactContainer]
|
dict[str, ArtifactContainer]: Artifacts. |
add_artifact_edge(parent_uid, key, name, path)
Add a child->parent artifact edge.
The child will use an artifact produced by the parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_uid
|
int
|
Parent uid. |
required |
key
|
str
|
Artifact key in the child input kwargs. |
required |
name
|
str
|
Artifact name. |
required |
path
|
Path
|
Artifact path. |
required |
Source code in python/sdag/models.py
add_kwarg(kwarg)
Add a static kwarg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwarg
|
Kwarg
|
Kwarg to be added. |
required |
Raises:
| Type | Description |
|---|---|
POSIXOverrideError
|
Task is external and variable is a common POSIX variable. |
Source code in python/sdag/models.py
add_output_edge(parent_uid, key)
Add a child->parent output edge.
Child will read the parent output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_uid
|
int
|
Parent uid. |
required |
key
|
str
|
parent output key in the child input kwargs. |
required |
Source code in python/sdag/models.py
register_artifact(key, path)
Register an artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Artifact key. |
required |
path
|
Path
|
Artifact path. |
required |
Source code in python/sdag/models.py
TaskOutput
Bases: BaseModel
Output of a task.
Attributes:
| Name | Type | Description |
|---|---|---|
output |
Any
|
Task output. |
artifacts |
list[ArtifactEdge]
|
Output artifacts. |
Source code in python/sdag/models.py
TraceScope
dataclass
Branch scope.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Self | None
|
Enclosing scope. None for the pipeline's root scope. Defaults to None. |
anchor |
tuple[int, bool] | None
|
(branch_uid, branch_value) branch edge on every node registered while active. None outside of branches. Defaults to None. |
last_clause |
ClosedClause | None
|
Last branch closed directly in this scope, used by the next Elif/Else to chain onto it. Defaults to None. |
Source code in python/sdag/models.py
parser
sdag parser.
ExtraArgumentParser
Parse the CLI extra arguments.
These arguments will become the pipline input kwargs. The
parse_known_args method doesn't handle --key=value and
--key value automatically, so some care must be taken.
Keep in mind that values are casted with json.
Source code in python/sdag/parser.py
parse(extras)
Parse extra arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extras
|
list[str]
|
Extra arguments. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Parsed extra arguments. |
Source code in python/sdag/parser.py
ParserBuilder
Build the parser.
Attributes:
| Name | Type | Description |
|---|---|---|
_parser |
ArgumentParser
|
Main parser. |
_subparsers |
_SubParsersAction[ArgumentParser]
|
Subparsers for the different commands. |
Source code in python/sdag/parser.py
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 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 364 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 407 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 448 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 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
__init__()
add_compile_subparser()
Add the compile command.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser builder. |
Source code in python/sdag/parser.py
add_describe_subparser()
Add the describe parser.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser. |
Source code in python/sdag/parser.py
add_kill_subparser()
Add the pipeline kill command.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser builder. |
Source code in python/sdag/parser.py
add_list_subparser()
Add Parser to list pipelines.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser. |
Source code in python/sdag/parser.py
add_prune_subparser()
Add the cache prune command.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser builder. |
Source code in python/sdag/parser.py
add_restart_subparser()
Add the restart subparser.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser. |
Source code in python/sdag/parser.py
add_retry_subparser()
Add the retry subparser.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser. |
Source code in python/sdag/parser.py
add_run_subparser()
Add the run command.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser builder. |
Source code in python/sdag/parser.py
add_runtask_subparser()
Add subparser to run tasks.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser. |
Source code in python/sdag/parser.py
add_status_subparser()
Add the status parser.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser. |
Source code in python/sdag/parser.py
add_version()
Add versions.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser builder. |
add_view_subparser()
Add the view command.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Parser builder. |
Source code in python/sdag/parser.py
pyproj
Settings.
DetachOptions
Bases: SlurmOverride
Detached sdag command options.
Attributes:
| Name | Type | Description |
|---|---|---|
job_name |
str | None
|
Slurm job name. Defaults to 'sdag'. |
nodes |
str | None
|
Number of nodes. Defaults to 1. |
ntasks_per_node |
str | None
|
Number of tasks per node. Defaults to 1. |
cpus_per_task |
str | None
|
Number of CPUs per task. Defaults to 1. |
output |
str | None
|
Slurm stdout. Defaults to 'logs/sdag/sdag_%x.%j.out'. |
error |
str | None
|
Slurm stderr. Defaults to 'logs/sdag/sdag_%x.%j.err'. |
Source code in python/sdag/pyproj.py
get_detached_args()
Get the slurm detach args.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Args used by sbatch to submit the detached job. |
Source code in python/sdag/pyproj.py
Pyproj
Bases: SlurmOverride
pyproject.toml configs.
Attributes:
| Name | Type | Description |
|---|---|---|
dag_dir |
str
|
DAG directory. |
compiled_dag_dir |
str
|
Compiled DAG directory. |
prepend_compiled_dag_dir |
bool
|
Add the compiled pipeline dir automatically if the directory has not been specified. |
time_between_polls |
int
|
Time between successive Slurm polls in seconds. Defaults to 5. |
commands |
Commands | None
|
Commands to execute tasks. If set, it overrides all pipeline commands. |
log_level |
Literal['debug', 'info', 'warning', 'error']
|
Logging level. |
max_concurrency |
int
|
Maximum number of tasks executed at the same time. |
slurm_grace_period |
int
|
Number of turns a task can be missing from the response without being considered as failed. Defaults to 60. |
detach |
DetachOptions
|
Detached command options. They are ignored if the command is not detached. |
fail_fast |
bool
|
Kill the scheduler and all running tasks if any of them fails. |
envs |
dict[str, str]
|
Environment variables added to all tasks. They have higher priority with respect to the ones set inside pipelines. |
Source code in python/sdag/pyproj.py
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 | |
join_args_into_detach()
Override detach args with the pyproj ones.
account, partition, qos, and time are overwritten with the default values in the pyproj.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
pyproj. |
Source code in python/sdag/pyproj.py
join_cli_args(args)
Join the user preferences into the pyproject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Parsed CLI args. |
required |
Source code in python/sdag/pyproj.py
SDAGTag
Bases: SlurmOverride
Tag configurations.
User are allowed to override slurm variables, command, and script path.
Attributes:
| Name | Type | Description |
|---|---|---|
tag |
str
|
Tag name. |
cmd |
Commands | None
|
Command. Defaults to None. |
script_path |
Path | None
|
Script path. |
envs |
dict[str, str]
|
Environment variables added to all relevant tasks. |
Source code in python/sdag/pyproj.py
apply_pyproj_configs(dag, pyproj)
Apply pyproject settings to all tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
DAG
|
Compiled DAG. |
required |
pyproj
|
Pyproj
|
Parsed pyproject.toml. |
required |
Source code in python/sdag/pyproj.py
apply_pyproj_to_task(task, pyproj)
Apply pyproject settings to a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
TaskNode
|
Task node. |
required |
pyproj
|
Pyproj
|
Parsed pyproject. |
required |
Source code in python/sdag/pyproj.py
get_pyproj(pyproj_path='pyproject.toml', sdag_toml_path='.sdag.toml')
cached
Get configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproj_path
|
str
|
pyproject.toml path. Defaults to "pyproject.toml". |
'pyproject.toml'
|
sdag_toml_path
|
str
|
sdag.toml path. Defaults to ".sdag.toml". |
'.sdag.toml'
|
Returns:
| Name | Type | Description |
|---|---|---|
Pyproj |
Pyproj
|
Parsed configurations. User settings have not been added. |
Source code in python/sdag/pyproj.py
settings
Settings.
CompileSettings
Bases: BaseSettings
Compilation environment variables.
Attributes:
| Name | Type | Description |
|---|---|---|
sdag_base_path |
Path | None
|
Base path. Defaults to None. |
Source code in python/sdag/settings.py
EnvLoggerFormatter
Bases: Formatter
Formatter mimicking env_logger.
Attributes:
| Name | Type | Description |
|---|---|---|
_crop |
dict[str, str]
|
Used to crop log levels as env_logger does. |
_colors |
dict[str, str]
|
Logging level colors. |
Source code in python/sdag/settings.py
__init__()
Initialize the log formatter.
Source code in python/sdag/settings.py
format(record)
Format a record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
Raw record. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formatted record. |
Source code in python/sdag/settings.py
LogColor
Settings
Bases: BaseSettings
Env variables set by the scheduler.
Attributes:
| Name | Type | Description |
|---|---|---|
sdag_pipeline_dir |
str
|
Pipeline directory. |
sdag_pipeline_name |
str
|
Pipeline name. |
sdag_subpipeline_name |
str
|
Task pipeline name. If there are no nested pipeline, it is equal to the pipeline name. |
sdag_import_path |
str
|
Import path used to compile the pipeline. |
sdag_input_kwargs |
str
|
Pipeline input kwargs JSON string. Useful to recompile the pipeline. |
sdag_uid |
str
|
Node unique id. |
sdag_task_fn |
str
|
Task function name. |
sdag_task_name |
str
|
Task name, by default it's equal to the task name. |
sdag_each_key |
str | None
|
If set, it's the sharded key in job arrays. |
sdag_shard_path |
str | None
|
If set, it's the shard path in job arrays. |
slurm_array_task_id |
str | None
|
If set, it's the task id in job arrays. |
sdag_try_num |
int
|
Number of times the task has been executed. |
Source code in python/sdag/settings.py
is_job_array()
Check if the job is part of an array.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the job is part of a job array. |
Source code in python/sdag/settings.py
shard_paths_and_task_id_must_be_consistent()
Both must be either set or null.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Settings. |
Source code in python/sdag/settings.py
configure_logging(log_level)
Simple logging configuration.
Everything is streamed to the stderr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_level
|
str
|
Logging level. |
required |
Source code in python/sdag/settings.py
get_cached_settings()
cached
Get the SDAG environment variables.
Returns:
| Name | Type | Description |
|---|---|---|
Settings |
Settings
|
Parsed environment variables. |
get_compile_settings()
cached
Get cached compilation settings.
Returns:
| Name | Type | Description |
|---|---|---|
CompileSettings |
CompileSettings
|
Cached compilation settings. |
types
Types.
CacheOptions = Literal['none', 'output', 'io', 'task', 'project']
module-attribute
Cache options.
Commands = Literal['bash', 'sbatch']
module-attribute
Available commands.
ExecMode = Literal['wrap', 'ext']
module-attribute
Available execution modes.
Scope = Literal['local', 'global']
module-attribute
Task scopes.
visualization
Visualization utils.
For notebook visualizations it is required to install neo4j_viz.
DAGViewer
DAG viewer.
Attributes:
| Name | Type | Description |
|---|---|---|
squeeze |
bool
|
Collapse all inner pipelines into a unique node. |
task_size |
int
|
Task node size. |
task_color |
str
|
Task color. |
root_size |
int
|
Root node size. |
root_color |
str
|
Root color. |
end_size |
int
|
End node size. |
end_color |
str
|
End color. |
if_size |
int
|
If node size. |
if_color |
str
|
If color. |
oneof_size |
int
|
OneOf node size. |
oneof_color |
str
|
OneOf color. |
pipeline_size |
int
|
Pipeline node size. |
pipeline_color |
str
|
Pipeline color. |
caption_size |
Literal[1, 2, 3]
|
Caption size. |
Source code in python/sdag/visualization.py
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 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 364 365 366 367 368 369 370 371 372 373 | |
__init__(squeeze=False, task_size=50, task_color='#3E7B7C', root_size=15, root_color='#F5F7FA', end_size=15, end_color='#F5F7FA', if_size=30, if_color='#D4A5A5', oneof_size=30, oneof_color='#D4A5A5', pipeline_size=50, pipeline_color='#F0D48D', caption_size=2)
Initialize the viewer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
squeeze
|
bool
|
Collapse subpipelines into a unique node. Defaults to False. |
False
|
task_size
|
int
|
Task node size. Defaults to 50. |
50
|
task_color
|
str
|
Task color. Defaults to "#3E7B7C". |
'#3E7B7C'
|
root_size
|
int
|
Root node size. Defaults to 15. |
15
|
root_color
|
str
|
Root color. Defaults to "#F5F7FA". |
'#F5F7FA'
|
end_size
|
int
|
End node size. Defaults to 15. |
15
|
end_color
|
str
|
End color. Defaults to "#F5F7FA". |
'#F5F7FA'
|
if_size
|
int
|
If node size. Defaults to 30. |
30
|
if_color
|
str
|
If color. Defaults to "#D4A5A5". |
'#D4A5A5'
|
oneof_size
|
int
|
OneOf node size. Defaults to 30. |
30
|
oneof_color
|
str
|
OneOf color. Defaults to "#D4A5A5". |
'#D4A5A5'
|
pipeline_size
|
int
|
Pipeline size (only usable if squeeze is enabled). Defaults to 50. |
50
|
pipeline_color
|
str
|
Pipeline color (only usable if squeeze is enabled). Defaults to "#F0D48D". |
'#F0D48D'
|
caption_size
|
Literal[1, 2, 3]
|
Caption size. Defaults to 2. |
2
|
Source code in python/sdag/visualization.py
view(path, input_kwargs=None)
View the DAG graph in a notebook cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Compiled pipeline path. |
required |
input_kwargs
|
dict[str, Any] | None
|
Pipeline input kwargs, only used if the pipeline is compiled. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
HTML |
HTML
|
IPython HTML graph. |
Source code in python/sdag/visualization.py
MermaidGenerator
Generate a mermaid string of the DAG.
Attributes:
| Name | Type | Description |
|---|---|---|
squeeze |
bool
|
Collapse all inner pipelines into a unique node. |
Source code in python/sdag/visualization.py
19 20 21 22 23 24 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 | |
__init__(squeeze)
Initialize the mermaid generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
squeeze
|
bool
|
Collapse all inner pipelines into a unique node. |
required |
generate_mermaid_string(dag)
Generate the mermaid string out of the dag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
DAG
|
DAG. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Mermaid string. |
Source code in python/sdag/visualization.py
wrappers
Wrappers.
Elif
Elif Wrapper.
Must follow an upstream If or Elif clause in the same scope, with nothing but plain task calls in between.
Attributes:
| Name | Type | Description |
|---|---|---|
_expr |
TaskNode | OneOfNode
|
Task returning a bool output. |
branch |
BranchNode
|
Branch. |
Source code in python/sdag/wrappers.py
__enter__()
Enter the positive branch.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
This task. |
__exit__(type, value, traceback)
__init__(expr)
Initialize the Elif wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
TaskNode | OneOfNode
|
Task returning a bool output. |
required |
Raises:
| Type | Description |
|---|---|
IncorrectElifError
|
Not immediately preceded by an If or Elif clause in the same scope. |
Source code in python/sdag/wrappers.py
Else
Else wrapper.
Must follow an upstream If or Elif clause in the same scope, with nothing but plain task calls in between.
Source code in python/sdag/wrappers.py
__enter__()
Enter the else context.
Raises:
| Type | Description |
|---|---|
IncorrectElseError
|
Not immediately preceded by an If or Elif clause in the same scope. |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
Else. |
Source code in python/sdag/wrappers.py
If
Branch wrapper.
Attributes:
| Name | Type | Description |
|---|---|---|
branch |
BranchNode
|
Branch. |
Source code in python/sdag/wrappers.py
__enter__()
Enter the positive branch.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
This task. |
__exit__(type, value, traceback)
__init__(expr)
Initialize the branch wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
TaskNode | OneOfNode
|
Task returning a bool output. |
required |
Source code in python/sdag/wrappers.py
Pipeline
Pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
fn |
Callable[..., Any]
|
Pipeline function. |
tasks |
dict[str, Task]
|
dict[str, Task]: Pipeline local tasks. |
Source code in python/sdag/wrappers.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
__call__(*args, **input_kwargs)
Call the pipeline function to compile it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Node
|
Parent nodes. |
()
|
input_kwargs
|
Any
|
Pipeline input kwargs. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Node |
EndNode
|
End node of the pipeline. |
Source code in python/sdag/wrappers.py
__init__(fn)
Initialize the pipeline wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
Pipeline function. |
required |
add_task(task)
Add a local task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
Task local to the pipeline. |
required |
Raises:
| Type | Description |
|---|---|
TaskNotUniqueError
|
A task with the same name already exists. |
Source code in python/sdag/wrappers.py
compile(import_path=None, **kwargs)
Call the pipeline function to compile it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
import_path
|
str | None
|
Pipeline import path. If null, it will be set to the pipeline function name. Defaults to None. |
None
|
kwargs
|
Any
|
Pipeline input kwargs. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Node |
DAG
|
End node of the pipeline. |
Source code in python/sdag/wrappers.py
compute_code_hash()
Compute the hash of all internal imported modules.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Computed hash, it's an empty string if no modules are found. |
task(script, name=None, cmd='sbatch', mode='wrap', cache='none', cache_ignore=None, cache_size=1, njobs=1, retries=0, tags=None)
Local task decorator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
str | Path | Script
|
Launch script. It can be either or a sdag.Script instance. |
required |
name
|
str | None
|
Task name. If null, it will default to the function name. Defaults to None. |
None
|
cmd
|
Commands
|
Command to execute the script. Defaults to "sbatch". |
'sbatch'
|
mode
|
ExecMode
|
Use wrap to call the Python function or ext to call an external script. Defaults to "wrap". |
'wrap'
|
cache
|
CacheOptions
|
Local caching options. 'none': No caching. 'output': All output artifacts must exist. 'io': Input values must match and all output artifacts exist. 'task': Same as 'io' but the task function code is also checked. 'project': Same as 'io' but the code of all internal modules imported when the pipeline is compiled must also match. Defaults to 'none'. |
'none'
|
cache_ignore
|
list[str] | None
|
List of input arguments ignored during cache validation. Ignored if cache is set to 'none' or 'output'. Defaults to None. |
None
|
cache_size
|
int
|
Cache size. Ignore if caching is disabled. set to 0 to allow for infinite cache size. |
1
|
njobs
|
int
|
When spreading a collection over multiple jobs with each(), njobs represents the number of jobs in the array. It is ignored if the task is not an array. Defaults to 1. |
1
|
retries
|
int
|
(int): Number of retries. Defaults to 0. |
0
|
tags
|
list[str] | None
|
Task tags, they can be used to configure sets of tasks globally. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable], Task]
|
Callable[[Callable], Task]: Task wrapper. |
Source code in python/sdag/wrappers.py
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
Script
Script content.
It can be used to embed the script content in the pipeline definition.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Script content. |
Source code in python/sdag/wrappers.py
__init__(content)
Task
Task wrapper.
Attributes:
| Name | Type | Description |
|---|---|---|
fn |
Callable[..., Any]
|
Task function. |
name |
str
|
Task name. |
cmd |
Commands
|
Task command. |
mode |
ExecMode
|
Task mode. |
scope |
Scope
|
(Scope): Task scope. Use 'global' for tasks decorated with the @task decorator, 'local' for tasks decorated with @pipeline.task. |
cache |
bool
|
Enable caching. |
cache_ignore |
list[str]
|
list of fields ignored during cache validation. |
cache_size |
int
|
Cache size. Ignore if caching is disabled. set to 0 to allow for infinite cache size. |
njobs |
int
|
Number of jobs in the array. |
retries |
int
|
Number of retries. |
script |
ScriptUnion
|
Submission script. |
Source code in python/sdag/wrappers.py
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 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 364 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 407 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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
code_hash
cached
property
Compute and cache the source code hash.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Hash of the task function source code. |
__call__(*args, **kwargs)
Call the task to get a node in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
NodeUnion
|
Logical dependencies. |
()
|
kwargs
|
Any
|
Kwargs, outputs, and artifacts. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
TaskNode |
TaskNode
|
Task node. |
Source code in python/sdag/wrappers.py
__init__(fn, name, cmd, mode, scope, cache, cache_ignore, cache_size, njobs, retries, script, tags)
Initialize the task wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
Task function. |
required |
name
|
str
|
Task name. |
required |
cmd
|
Commands
|
Task command. |
required |
mode
|
ExecMode
|
Task mode. |
required |
scope
|
Scope
|
(Scope): Task scope. Use 'global' for tasks decorated with the @task decorator, 'local' for tasks decorated with @pipeline.task. |
required |
cache
|
CacheOptions
|
Caching options. |
required |
cache_ignore
|
list[str] | None
|
list of fields ignored during cache validation. |
required |
cache_size
|
int
|
Cache size. Ignore if caching is disabled. set to 0 to allow for infinite cache size. |
required |
njobs
|
int
|
When spreading a collection over multiple jobs with each(), njobs represents the number of jobs in the array. Defaults to 1. |
required |
retries
|
int
|
Number of retries. |
required |
script
|
ScriptUnion
|
Submission script. |
required |
tags
|
list[str]
|
Tags. |
required |
Source code in python/sdag/wrappers.py
each(collection)
Job array collection.
Used to spread a collection over an array of jobs. The input can be either a compile-time, static list or a list coming as the output of a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
list[Any] | TaskNode
|
Collection that will be spread across jobs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Each |
Each
|
Collection wrapper. |
Source code in python/sdag/wrappers.py
is_artifact(param)
Check if a type hint is actually an artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
Parameter | None
|
Parameter. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if it's an artifact. |
Source code in python/sdag/wrappers.py
oneof(*args, name='one_of')
OneOf node.
It has two major use cases: 1. Selecting nodes from mutually excluded branches. 2. Selecting The first successfully completed parent.
Returns:
| Type | Description |
|---|---|
OneOfNode
|
Node[OneOfNode]: OneOf node. |
Source code in python/sdag/wrappers.py
pipeline(fn)
Pipeline decorator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
Pipeline function. |
required |
Raises:
| Type | Description |
|---|---|
TaskNotUniqueError
|
Another pipeline with the same name has already bee imported. |
Returns:
| Name | Type | Description |
|---|---|---|
Pipeline |
Pipeline
|
Pipeline. |
Source code in python/sdag/wrappers.py
task(script, name=None, cmd='sbatch', mode='wrap', cache='none', cache_ignore=None, cache_size=1, njobs=1, retries=0, tags=None)
Local task decorator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
str | Path | Script
|
Launch script. It can be either or a sdag.Script instance. |
required |
name
|
str | None
|
Task name. If null, it will default to the function name. Defaults to None. |
None
|
cmd
|
Commands
|
Command to execute the script. Defaults to "sbatch". |
'sbatch'
|
mode
|
ExecMode
|
Use wrap to call the Python function or ext to call an external script. Defaults to "wrap". |
'wrap'
|
cache
|
CacheOptions
|
Global caching options. 'none': No caching. 'output': All output artifacts must exist. 'io': Input values must match and all output artifacts exist. 'task': Same as 'io' but the task function code is also checked. 'project': Same as 'io' but the code of all internal modules imported when the pipeline is compiled must also match. Defaults to 'none'. |
'none'
|
cache_ignore
|
list[str] | None
|
List of input arguments ignored during cache validation. Ignored if cache is set to 'none' or 'output'. Defaults to None. |
None
|
cache_size
|
int
|
Cache size. Ignore if caching is disabled. set to 0 to allow for infinite cache size. |
1
|
njobs
|
int
|
When spreading a collection over multiple jobs with each(), njobs represents the number of jobs in the array. It is ignored if the task is not an array. Defaults to 1. |
1
|
retries
|
int
|
(int): Number of retries. Defaults to 0. |
0
|
tags
|
list[str] | None
|
Task tags, they can be used to configure sets of tasks globally. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable], Task]
|
Callable[[Callable], Task]: Task wrapper. |
Source code in python/sdag/wrappers.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | |
validate_kwargs(sig, kwargs)
Validate kwarg consistency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sig
|
Signature
|
Function signature. |
required |
kwargs
|
dict[str, Any]
|
Input kwargs. |
required |
Raises:
| Type | Description |
|---|---|
KwargNotFoundError
|
Keyword argument not found in the input values. |