From 1443ab7b00c32e932c6fb8b727c448a7c2e57113 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Tue, 13 Jun 2023 10:10:31 -0700 Subject: [PATCH 1/6] Refactor: extract method --- .../workflow/node_library/atomistics.py | 96 ++++++++++++------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/pyiron_contrib/workflow/node_library/atomistics.py b/pyiron_contrib/workflow/node_library/atomistics.py index 12663edf1..e8dda8e4d 100644 --- a/pyiron_contrib/workflow/node_library/atomistics.py +++ b/pyiron_contrib/workflow/node_library/atomistics.py @@ -24,42 +24,27 @@ def lammps(structure: Optional[Atoms] = None) -> LammpsJob: return job -@node( - "cells", - "displacements", - "energy_pot", - "energy_tot", - "force_max", - "forces", - "indices", - "positions", - "pressures", - "steps", - "temperature", - "total_displacements", - "unwrapped_positions", - "volume", -) -def calc_md( - job: AtomisticGenericJob, - n_ionic_steps: int = 1000, - n_print: int = 100, - temperature: int | float = 300.0, - pressure: float - | tuple[float, float, float] - | tuple[float, float, float, float, float, float] - | None = None, -): +def _run_and_remove_job(job, modifier: Optional[callable] = None, **modifier_kwargs): + """ + Extracts the commonalities for all the "calc" methods for running a Lammps engine. + Will need to be extended/updated once we support other engines so that more output + can be parsed. Output may wind up more concretely packaged, e.g. as `CalcOutput` or + `MDOutput`, etc., ala Joerg's suggestion later, so for the time being we don't put + too much effort into this. + + Warning: + Jobs are created in a dummy project with a dummy name and are all removed at the + end; this works fine for serial workflows, but will need to be revisited -- + probably with naming based on the parantage of node/workflow labels -- once + other non-serial execution is introduced. + """ job_name = "JUSTAJOBNAME" pr = Project("WORKFLOWNAMEPROJECT") job = job.copy_to(project=pr, new_job_name=job_name, delete_existing_job=True) - job.calc_md( - n_ionic_steps=n_ionic_steps, - n_print=n_print, - temperature=temperature, - pressure=pressure, - ) + if modifier is not None: + job = modifier(job, **modifier_kwargs) job.run() + cells = job.output.cells displacements = job.output.displacements energy_pot = job.output.energy_pot @@ -74,8 +59,10 @@ def calc_md( total_displacements = job.output.total_displacements unwrapped_positions = job.output.unwrapped_positions volume = job.output.volume + job.remove() pr.remove(enable=True) + return ( cells, displacements, @@ -94,6 +81,51 @@ def calc_md( ) +@node( + "cells", + "displacements", + "energy_pot", + "energy_tot", + "force_max", + "forces", + "indices", + "positions", + "pressures", + "steps", + "temperature", + "total_displacements", + "unwrapped_positions", + "volume", +) +def calc_md( + job: AtomisticGenericJob, + n_ionic_steps: int = 1000, + n_print: int = 100, + temperature: int | float = 300.0, + pressure: float + | tuple[float, float, float] + | tuple[float, float, float, float, float, float] + | None = None, +): + def calc_md(job, n_ionic_steps, n_print, temperature, pressure): + job.calc_md( + n_ionic_steps=n_ionic_steps, + n_print=n_print, + temperature=temperature, + pressure=pressure, + ) + return job + + return _run_and_remove_job( + job=job, + modifier=calc_md, + n_ionic_steps=n_ionic_steps, + n_print=n_print, + temperature=temperature, + pressure=pressure + ) + + nodes = [ bulk_structure, calc_md, From b6435faa31537eeba6045bd19f95113118367710 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Tue, 13 Jun 2023 10:15:48 -0700 Subject: [PATCH 2/6] add calc static --- .../workflow/node_library/atomistics.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pyiron_contrib/workflow/node_library/atomistics.py b/pyiron_contrib/workflow/node_library/atomistics.py index e8dda8e4d..12bf492d0 100644 --- a/pyiron_contrib/workflow/node_library/atomistics.py +++ b/pyiron_contrib/workflow/node_library/atomistics.py @@ -81,6 +81,42 @@ def _run_and_remove_job(job, modifier: Optional[callable] = None, **modifier_kwa ) +@node( + "cells", + "displacements", + "energy_pot", + "energy_tot", + "force_max", + "forces", + "indices", + "positions", + "pressures", + "steps", + "temperature", + "total_displacements", + "unwrapped_positions", + "volume", +) +def calc_static( + job: AtomisticGenericJob, + n_ionic_steps: int = 1000, + n_print: int = 100, + temperature: int | float = 300.0, + pressure: float + | tuple[float, float, float] + | tuple[float, float, float, float, float, float] + | None = None, +): + return _run_and_remove_job( + job=job, + modifier=calc_md, + n_ionic_steps=n_ionic_steps, + n_print=n_print, + temperature=temperature, + pressure=pressure + ) + + @node( "cells", "displacements", From 114101169a7ab2f1e150d04065b9442e3c5ab790 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Tue, 13 Jun 2023 10:16:05 -0700 Subject: [PATCH 3/6] Make the node adder return the new node on call --- pyiron_contrib/workflow/workflow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyiron_contrib/workflow/workflow.py b/pyiron_contrib/workflow/workflow.py index ba460416f..b9af9bf63 100644 --- a/pyiron_contrib/workflow/workflow.py +++ b/pyiron_contrib/workflow/workflow.py @@ -31,7 +31,7 @@ def __getattribute__(self, key): return value def __call__(self, node: Node): - self._workflow.add_node(node) + return self._workflow.add_node(node) class _NodeDecoratorAccess: @@ -180,6 +180,7 @@ def add_node(self, node: Node, label: str = None) -> None: self.nodes[label] = node node.label = label node.workflow = self + return node def _ensure_node_belongs_to_at_most_this_workflow(self, node: Node, label: str): if ( From 738e1ab9663917cdc6a1fe1d5e967062db278af5 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Tue, 13 Jun 2023 10:27:52 -0700 Subject: [PATCH 4/6] Include calc_static in the returned library --- pyiron_contrib/workflow/node_library/atomistics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyiron_contrib/workflow/node_library/atomistics.py b/pyiron_contrib/workflow/node_library/atomistics.py index 12bf492d0..5d7cb3e7e 100644 --- a/pyiron_contrib/workflow/node_library/atomistics.py +++ b/pyiron_contrib/workflow/node_library/atomistics.py @@ -165,5 +165,6 @@ def calc_md(job, n_ionic_steps, n_print, temperature, pressure): nodes = [ bulk_structure, calc_md, + calc_static, lammps, ] From 78f109ee519a9aa1a67194d268e009e78f5be43d Mon Sep 17 00:00:00 2001 From: liamhuber Date: Tue, 13 Jun 2023 10:30:41 -0700 Subject: [PATCH 5/6] Fix calc_static signature and function --- .../workflow/node_library/atomistics.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/pyiron_contrib/workflow/node_library/atomistics.py b/pyiron_contrib/workflow/node_library/atomistics.py index 5d7cb3e7e..94ab35878 100644 --- a/pyiron_contrib/workflow/node_library/atomistics.py +++ b/pyiron_contrib/workflow/node_library/atomistics.py @@ -99,22 +99,8 @@ def _run_and_remove_job(job, modifier: Optional[callable] = None, **modifier_kwa ) def calc_static( job: AtomisticGenericJob, - n_ionic_steps: int = 1000, - n_print: int = 100, - temperature: int | float = 300.0, - pressure: float - | tuple[float, float, float] - | tuple[float, float, float, float, float, float] - | None = None, ): - return _run_and_remove_job( - job=job, - modifier=calc_md, - n_ionic_steps=n_ionic_steps, - n_print=n_print, - temperature=temperature, - pressure=pressure - ) + return _run_and_remove_job(job=job) @node( From 661410b1197eb61867993a8d320af949575526e6 Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Mon, 19 Jun 2023 18:21:01 +0000 Subject: [PATCH 6/6] Format black --- pyiron_contrib/workflow/node_library/atomistics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_contrib/workflow/node_library/atomistics.py b/pyiron_contrib/workflow/node_library/atomistics.py index 94ab35878..781d039b4 100644 --- a/pyiron_contrib/workflow/node_library/atomistics.py +++ b/pyiron_contrib/workflow/node_library/atomistics.py @@ -144,7 +144,7 @@ def calc_md(job, n_ionic_steps, n_print, temperature, pressure): n_ionic_steps=n_ionic_steps, n_print=n_print, temperature=temperature, - pressure=pressure + pressure=pressure, )