Workflows¶
NomadSection
dataclass
¶
Represents a section within a NOMAD workflow or task.
This class is used to define and manage the properties of a section, which can be a task, a workflow, or a default type within the NOMAD system. It includes attributes to specify the section's name, type, label, snapshot number, run number, and an optional upload ID. Additional properties provide convenience methods to determine if the section is a task or workflow, to generate a log file path, to construct the section's URL, and to convert the section information into a dictionary format.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the section. |
section_type |
SectionType
|
The type of the section, which can be 'task', 'workflow', or 'default'. |
label |
str
|
A label for the section, used in generating paths and URLs. |
snapshot_number |
int
|
The snapshot number associated with this section, defaulting to 0. |
run_number |
int
|
The run number associated with this section, defaulting to 0. |
upload_id |
Optional[str]
|
An optional upload ID for the section, defaulting to None. |
Properties
is_task (bool): Returns True if the section is a task, False otherwise. is_workflow (bool): Returns True if the section is a workflow, False otherwise. log_file (Optional[str]): Returns the log file path if the section is not a task, None otherwise. section (str): Constructs and returns the section's URL based on its properties. upload_prefix (str): Constructs and returns the upload prefix URL for the section.
Methods:
Name | Description |
---|---|
to_dict |
Converts the section's attributes into a dictionary. |
add_job_id |
Job) -> 'NomadSection': Adds a job ID to the section's label if applicable. |
Source code in martignac/nomad/workflows.py
NomadTask
dataclass
¶
Represents a task within a NOMAD workflow.
This class is designed to encapsulate the details of a task in the NOMAD system, including its name, definition, inputs, outputs, and an optional task-specific section. It provides a structured way to manage tasks within workflows, facilitating the creation, manipulation, and serialization of task-related information.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the task, serving as a unique identifier within the workflow. |
m_def |
str
|
The metainfo definition for the task, defaulting to a predefined value. |
inputs |
list[NomadSection]
|
A list of |
outputs |
list[NomadSection]
|
A list of |
task_section |
Optional[NomadSection]
|
An optional |
Methods:
Name | Description |
---|---|
__post_init__ |
A post-initialization method to set default names for inputs and outputs. |
task |
A property that returns the task's URL if it is not a task-specific section. |
to_dict |
Serializes the task's attributes into a dictionary for easy export and manipulation. |
Source code in martignac/nomad/workflows.py
NomadWorkflow
dataclass
¶
Manages the construction and serialization of a NOMAD workflow.
This class is responsible for creating a representation of a workflow within the NOMAD system, which includes tasks, inputs, and outputs as defined by the user's project and job configurations. It utilizes the project's operations and the job's documentation to construct a directed graph representing the workflow, which can then be serialized to a YAML file for use within the NOMAD system.
Attributes:
Name | Type | Description |
---|---|---|
project |
MartiniFlowProject
|
The project instance containing operations and configurations for the workflow. |
job |
Job
|
The job instance containing specific execution details and documentation for the workflow. |
is_top_level |
bool
|
Flag indicating if the workflow is at the top level of the project hierarchy. |
add_job_id |
bool
|
Flag indicating if the job ID should be added to section labels for uniqueness. |
Properties
project_name (str): Returns the name of the project class.
gromacs_logs (dict): Retrieves GROMACS log entries from the job's documentation.
tasks (dict): Retrieves task entries from the job's documentation.
workflows (dict): Retrieves workflow entries from the job's documentation if is_top_level
is True.
all_tasks (dict): Aggregates all tasks, workflows, and GROMACS logs into a single dictionary.
graph (nx.DiGraph): Constructs and returns a directed graph representing the workflow structure.
Methods:
Name | Description |
---|---|
register_section |
str): Registers a section (task, workflow, or default) based on the operation name. |
build_workflow_yaml |
str): Serializes the workflow to a YAML file. |
generate_archive |
Generates a |
_section_type |
str) -> SectionType: Determines the section type (task, workflow, default) for a given operation name. |
Source code in martignac/nomad/workflows.py
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 |
|
NomadWorkflowArchive
dataclass
¶
Represents the archival structure of a NOMAD workflow.
This class encapsulates the structure necessary for representing a complete NOMAD workflow, including its inputs, outputs, and the tasks that comprise the workflow. It provides methods for serializing the workflow to a dictionary and saving it as a YAML file, which can be used for workflow reconstruction or analysis. Additionally, it offers a class method for creating a workflow archive from multiple jobs, allowing for the aggregation of tasks and data across different computational jobs within the same project.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the workflow, used as a key in the serialized output. |
inputs |
list[NomadSection]
|
A list of sections representing the inputs to the workflow. |
outputs |
list[NomadSection]
|
A list of sections representing the outputs from the workflow. |
tasks |
list[NomadTask]
|
A list of tasks that are part of the workflow. |
Methods:
Name | Description |
---|---|
to_dict |
Serializes the workflow archive to a dictionary. |
to_yaml |
str) -> None: Saves the serialized workflow archive as a YAML file to the specified location. |
from_multiple_jobs |
MartiniFlowProject, jobs: list[Job], aggregate_same_task_names: bool = True) -> 'NomadWorkflowArchive': Class method to create a workflow archive from multiple jobs, optionally aggregating tasks with the same name. |
Source code in martignac/nomad/workflows.py
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 |
|
build_nomad_workflow(job, is_top_level=False, add_job_id=False)
¶
Builds and serializes a NOMAD workflow for a given job.
This function initializes a NomadWorkflow
instance with the specified job and configuration flags,
then serializes the constructed workflow into a YAML file. The YAML file is saved in a location determined
by whether the workflow is considered top-level or not. If is_top_level
is True, the workflow is saved
using the nomad_top_level_workflow
path from the project; otherwise, it uses the nomad_workflow
path.
The add_job_id
flag determines whether job IDs should be added to section labels to ensure uniqueness.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job |
Job
|
The job instance for which the workflow is being built. |
required |
is_top_level |
bool
|
Flag indicating if the workflow is at the top level of the project hierarchy. Defaults to False. |
False
|
add_job_id |
bool
|
Flag indicating if the job ID should be added to section labels for uniqueness. Defaults to False. |
False
|
Source code in martignac/nomad/workflows.py
build_nomad_workflow_with_multiple_jobs(project, jobs)
¶
Builds and serializes a NOMAD workflow archive for multiple jobs within a project.
This function aggregates the workflows of multiple jobs into a single NOMAD workflow archive. It utilizes the
NomadWorkflowArchive.from_multiple_jobs
class method to create an archive that represents the combined workflow
of the specified jobs. The resulting workflow archive is then serialized into a YAML file, which is saved using
the nomad_top_level_workflow
path from the project. This allows for the analysis and reconstruction of complex
workflows that span multiple computational jobs within the same project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
MartiniFlowProject
|
The project instance containing operations and configurations for the workflow. |
required |
jobs |
list[Job]
|
A list of job instances to be included in the workflow archive. |
required |