Skip to content

Commit

Permalink
Merge pull request #1677 from pyiron/list_length
Browse files Browse the repository at this point in the history
decorator: Set list length only at function call
  • Loading branch information
jan-janssen authored Oct 22, 2024
2 parents 0163935 + 83f398f commit 2a76014
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pyiron_base/project/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def pyiron_job(
new_hdf: bool = True,
output_file_lst: list = [],
output_key_lst: list = [],
list_length: Optional[int] = None,
):
"""
Decorator to create a pyiron job object from any python function
Expand Down Expand Up @@ -63,6 +62,7 @@ def get_delayed_object(
python_function: callable,
pyiron_resource_dict: dict,
resource_default_dict: dict,
list_length: Optional[int] = None,
**kwargs,
):
for k, v in resource_default_dict.items():
Expand All @@ -86,7 +86,11 @@ def get_delayed_object(
# This is the actual decorator function that applies to the decorated function
def pyiron_job_function(f) -> callable:
def function(
*args, pyiron_project: Project, pyiron_resource_dict: dict = {}, **kwargs
*args,
pyiron_project: Project,
pyiron_resource_dict: dict = {},
list_length: Optional[int] = None,
**kwargs,
):
resource_default_dict = {
"host": host,
Expand All @@ -103,6 +107,7 @@ def function(
pyiron_project=pyiron_project,
pyiron_resource_dict=pyiron_resource_dict,
resource_default_dict=resource_default_dict,
list_length=list_length,
**kwargs,
)

Expand All @@ -119,6 +124,7 @@ def function(
*args,
pyiron_project: Project,
pyiron_resource_dict: dict = {},
list_length: Optional[int] = None,
**kwargs,
):
resource_default_dict = {
Expand All @@ -130,6 +136,7 @@ def function(
pyiron_project=pyiron_project,
pyiron_resource_dict=pyiron_resource_dict,
resource_default_dict=resource_default_dict,
list_length=list_length,
**kwargs,
)

Expand Down
3 changes: 2 additions & 1 deletion tests/usecases/ADIS/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
"outputs": [],
"source": [
"@pyiron_job(list_length=5)\n",
"@pyiron_job\n",
"def generate_structures(structure, strain_lst):\n",
" structure_lst = []\n",
" for strain in strain_lst:\n",
Expand Down Expand Up @@ -230,6 +230,7 @@
" structure=calc_mini.output.structure,\n",
" strain_lst=np.linspace(0.9, 1.1, number_of_strains),\n",
" pyiron_project=pr,\n",
" list_length=number_of_strains,\n",
")"
]
},
Expand Down

0 comments on commit 2a76014

Please sign in to comment.