Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor macros #80

Merged
merged 3 commits into from
Nov 20, 2023
Merged

Refactor macros #80

merged 3 commits into from
Nov 20, 2023

Conversation

liamhuber
Copy link
Member

Old: define a generic macro shared by all atomistics workflows leveraging task generators, then define a set of macros each of which instantiates the task generator node and the generic macro node, then connects them and manually re-maps all the task generator input to be available at the macro level.

New: Create a meta-workflow that takes the task generator node as input and returns a macro class in which all the task generator IO has been dynamically re-mapped to be available at the macro level; instantiate this meta-macro once per task generator to get a set of macros.

There is absolutely nothing wrong with the "old" version, it's a perfectly legitimate and legal way to construct a set of macros! Further, the biggest advantage of the "new" way -- that the task generator input is dynamically remapped -- could also be used right in the "old" way. Using a "meta-macro" is purely stylistic and my personal preference.

@jan-janssen, it's your node package so I think it's fair if you use whatever one you prefer. However, if you chose to stick with the implementation on the base branch, I would still suggest to leverage the same dynamic remapping just to shorten the node definitions.

from pyiron_workflow import Workflow

Workflow.register("macros", "pyiron_workflow.atomistics_library.macronodes")
Workflow.register("calculators", "pyiron_workflow.atomistics_library.calculatornodes")
Workflow.register("tasks", "pyiron_workflow.atomistics_library.tasknodes")

wf = Workflow("ev")
wf.bulk = wf.create.tasks.GetBulk("Al")
wf.calc = wf.create.calculators.GetEmt()
# wf.old_ev_curve = wf.create.macros.GetEnergyVolumeCurve(
#     structure=wf.bulk,
#     calculator=wf.calc,
# )
wf.new_ev_curve = wf.create.macros.EnergyVolumeCurve(
    structure=wf.bulk,
    calculator=wf.calc,
)
out = wf()

# out.old_ev_curve__internal__fit__result_dict["poly_fit"] - out.new_ev_curve__result_dict["poly_fit"]

The commented out stuff works on the first commit of this PR, where both old and new exist at once. The output is just an array of zeros, as expected and desired.

I didn't do the same sort of thorough test for the other two, but I did make sure that they instantiated OK and had nice clean IO:

p = Workflow.create.macros.Phonons()
p.inputs.labels, p.outputs.labels
(['structure',
  'interaction_range',
  'factor',
  'displacement',
  'dos_mesh',
  'primitive_matrix',
  'number_of_snapshots',
  'calculator'],
 ['result_dict'])

and

l = Workflow.create.macros.ElasticMatrix()
l.inputs.labels, l.outputs.labels
(['structure',
  'num_points',
  'fit_type',
  'fit_order',
  'vol_range',
  'axes',
  'strains',
  'calculator'],
 ['internal__fit__result_dict'])

Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_workflow/refactor_macros

@liamhuber liamhuber added the format_black trigger the Black formatting bot label Nov 20, 2023
Base automatically changed from atomistics_library to main November 20, 2023 06:12
Copy link
Member

@jan-janssen jan-janssen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@liamhuber liamhuber merged commit 45737b6 into main Nov 20, 2023
12 of 13 checks passed
@liamhuber liamhuber deleted the refactor_macros branch November 20, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format_black trigger the Black formatting bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants