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

Define output classes based on instances rather than classes #186

Merged
merged 3 commits into from
Jan 9, 2024

Conversation

jan-janssen
Copy link
Member

No description provided.

@jan-janssen jan-janssen requested a review from liamhuber January 9, 2024 06:19
@jan-janssen jan-janssen added the format_black Launch the pyiron/actions black formatting routine label Jan 9, 2024
Copy link
Member

@liamhuber liamhuber left a comment

Choose a reason for hiding this comment

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

I mean, sure, but... why? Please include a description in the PR to clarify your intent.

I suspect this is just for readability? In that case I disagree and like it better the old way, but I don't actually object and if this is the style you prefer I'm A-OK with that. Before and after are both reasonable.

Comment on lines -123 to +129
ASEOutputMolecularDynamics = OutputMolecularDynamics(
**{k: getattr(ASEExecutor, k) for k in OutputMolecularDynamics.keys()}
)
cache = {q: [] for q in output_keys}
for i in range(int(run / thermo)):
dyn.run(thermo)
calc_dict = ASEOutputMolecularDynamics.get(
ASEExecutor(ase_structure=structure, ase_calculator=ase_calculator),
*output_keys,
ase_instance = ASEExecutor(
ase_structure=structure, ase_calculator=ase_calculator
)
calc_dict = OutputMolecularDynamics(
**{k: getattr(ase_instance, k) for k in OutputMolecularDynamics.keys()}
).get(*output_keys)
Copy link
Member

Choose a reason for hiding this comment

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

This change is different, as it actually removes an intermediately defined class. I'm 100% behind this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

But this change requires changing the other calls as well. The important part is the change in output from:

    def get(self, engine, *output: str) -> dict:
        return {q: getattr(self, q)(engine) for q in output}

To:

    def get(self, *output: str) -> dict:
        return {q: getattr(self, q)() for q in output}

By no longer providing the engine as parameter we can simplify the code as illustrated by the ASE example above. But this affects all output classes at the same time, so all output classes need to be updated.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, ok, I had totally failed to grok the change in Output, I apologize. A version of the final sentence there would be perfect as the PR description.

Ok, then I am not sold on introducing variables to hold the XProperties rather than using them in-line, but I also don't object to it. And I like the simplification of the Output initialization/get, that's a nice change.

@jan-janssen jan-janssen merged commit 299796a into main Jan 9, 2024
18 of 19 checks passed
@jan-janssen jan-janssen deleted the output_instance branch January 9, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format_black Launch the pyiron/actions black formatting routine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants