Skip to content

Commit fc8849d

Browse files
Improve type safety and documentation in powerups modules (#1332)
* typevar, docstring and wrong type annotations? * revert back to `name` in f-string * pipes to 'or' and add metadata info in docstrings --------- Co-authored-by: Aaron Kaplan <[email protected]>
1 parent ccdf013 commit fc8849d

File tree

2 files changed

+237
-168
lines changed

2 files changed

+237
-168
lines changed

src/atomate2/common/powerups.py

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,43 @@
55
from typing import TYPE_CHECKING
66

77
if TYPE_CHECKING:
8-
from jobflow import Flow, Maker
8+
from jobflow.core.flow import Flow
9+
from jobflow.core.maker import Maker
910

1011

1112
def add_metadata_to_flow(
12-
flow: Flow, additional_fields: dict, class_filter: Maker
13+
flow: Flow, additional_fields: dict, class_filter: type[Maker]
1314
) -> Flow:
1415
"""
15-
Return the flow with additional field(metadata) to the task doc.
16+
Add additional metadata fields to task documents in a flow.
1617
17-
This allows adding metadata to the task-docs, could be useful
18-
to query results from DB.
18+
This function updates the task document kwargs for jobs in the flow,
19+
allowing metadata to be added for easier querying of results from a database.
20+
21+
This function does not add metadata to the job themselves, only to the output
22+
generated upon job completion.
1923
2024
Parameters
2125
----------
22-
flow:
26+
flow : Flow
27+
The jobflow Flow object to modify.
2328
additional_fields : dict
24-
A dict with metadata.
25-
class_filter: .Maker
26-
The Maker to which additional metadata needs to be added
29+
Dictionary containing metadata fields and their values to add to task documents.
30+
class_filter : type[Maker]
31+
The Maker class type to which additional metadata should be added.
32+
Only jobs created by this Maker type will be modified.
2733
2834
Returns
2935
-------
3036
Flow
31-
Flow with added metadata to the task-doc.
37+
The modified flow with added metadata in the task documents.
38+
39+
Examples
40+
--------
41+
>>> from atomate2.vasp.flows.core import RelaxBandStructureMaker
42+
>>> flow = RelaxBandStructureMaker().make(structure)
43+
>>> metadata = {"project": "battery_materials", "version": "2.0"}
44+
>>> flow = add_metadata_to_flow(flow, metadata, RelaxBandStructureMaker)
3245
"""
3346
flow.update_maker_kwargs(
3447
{
@@ -45,28 +58,40 @@ def add_metadata_to_flow(
4558

4659

4760
def update_custodian_handlers(
48-
flow: Flow, custom_handlers: tuple, class_filter: Maker
61+
flow: Flow, custom_handlers: tuple, class_filter: type[Maker]
4962
) -> Flow:
5063
"""
51-
Return the flow with custom custodian handlers for VASP jobs.
64+
Update custodian error handlers for VASP jobs in a flow.
5265
53-
This allows user to selectively set error correcting handlers for VASP jobs
54-
or completely unset error handlers.
66+
This function allows selective configuration of error-correcting handlers
67+
for VASP jobs or complete removal of error handlers.
5568
5669
Parameters
5770
----------
58-
flow:
71+
flow : Flow
72+
The jobflow Flow object to modify.
5973
custom_handlers : tuple
60-
A tuple with custodian handlers.
61-
class_filter: .Maker
62-
The Maker to which custom custodian handler needs to be added
74+
Tuple of custodian handler objects to use for error correction.
75+
Pass an empty tuple to disable all error handlers.
76+
class_filter : type[Maker]
77+
The Maker class type to which custom custodian handlers should be applied.
78+
Only jobs created by this Maker type will be modified.
6379
6480
Returns
6581
-------
6682
Flow
67-
Flow with modified custodian handlers.
83+
The modified flow with updated custodian handlers.
84+
85+
Examples
86+
--------
87+
>>> from custodian.vasp.handlers import VaspErrorHandler, MeshSymmetryErrorHandler
88+
>>> from atomate2.vasp.flows.core import RelaxBandStructureMaker
89+
>>> flow = RelaxBandStructureMaker().make(structure)
90+
>>> handlers = (VaspErrorHandler(), MeshSymmetryErrorHandler())
91+
>>> flow = update_custodian_handlers(flow, handlers, RelaxBandStructureMaker)
6892
"""
6993
code = class_filter.name.split(" ")[1]
94+
7095
flow.update_maker_kwargs(
7196
{"_set": {f"run_{code}_kwargs->handlers": custom_handlers}},
7297
dict_mod=True,

0 commit comments

Comments
 (0)