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

Breaking: Unify previous directory Maker API #593

Merged
merged 4 commits into from
Oct 30, 2023
Merged

Breaking: Unify previous directory Maker API #593

merged 4 commits into from
Oct 30, 2023

Conversation

janosh
Copy link
Member

@janosh janosh commented Oct 27, 2023

As discussed in today's atomate2 maintainer meeting, it would be great to unify the API between Makers for different codes and forcefields to more easily swap, say, a PBEsol pre-relax maker for a forcefield pre-relax maker and not have to worry about the flow that stitches the makers together passing in an unrecognized keyword like prev_vasp_dir into the forcefield maker.

@janosh janosh added enhancement Improvements to existing features discussion API design discussions breaking Breaking changes labels Oct 27, 2023
@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

Merging #593 (3d25536) into main (d464012) will decrease coverage by 0.01%.
Report is 11 commits behind head on main.
The diff coverage is 71.57%.

❗ Current head 3d25536 differs from pull request most recent head 47f564c. Consider uploading reports for the commit 47f564c to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #593      +/-   ##
==========================================
- Coverage   75.57%   75.57%   -0.01%     
==========================================
  Files          83       84       +1     
  Lines        6793     6804      +11     
  Branches     1001     1002       +1     
==========================================
+ Hits         5134     5142       +8     
- Misses       1348     1350       +2     
- Partials      311      312       +1     
Files Coverage Δ
src/atomate2/common/flows/defect.py 81.57% <ø> (ø)
src/atomate2/common/flows/elastic.py 77.55% <ø> (ø)
src/atomate2/common/jobs/defect.py 80.95% <100.00%> (ø)
src/atomate2/common/jobs/phonons.py 84.70% <100.00%> (ø)
src/atomate2/common/utils.py 78.94% <ø> (ø)
src/atomate2/forcefields/flows/relax.py 63.33% <100.00%> (+1.26%) ⬆️
src/atomate2/forcefields/jobs.py 92.37% <100.00%> (ø)
src/atomate2/vasp/flows/elastic.py 91.66% <100.00%> (ø)
src/atomate2/vasp/flows/lobster.py 86.95% <100.00%> (ø)
src/atomate2/vasp/flows/matpes.py 83.33% <100.00%> (ø)
... and 15 more

@JaGeo
Copy link
Member

JaGeo commented Oct 27, 2023

Sounds like a good change. Do the forcefield makers need a prev_dir? No files are currently written (should we write some logs?)

In addition:
Should we include a tight-binding based approach to cheaply generate electronic structres?

@janosh
Copy link
Member Author

janosh commented Oct 27, 2023

3d25536 shows we could even go a step further and define a class BaseMaker(Maker, ABC) that inherits from jobflow.Maker and which all other Maker subclasses inherit from to enforce a consistent def make() method signature.

That way, it's not up to the PR reviewer to notice violations. mypy will automatically flag if a Maker has a signature that's incompatible with other makers.

@janosh
Copy link
Member Author

janosh commented Oct 27, 2023

I think we may want to hold off on the abstract BaseMaker to enforce method signature since abstractmethods are covariant, i.e. restrict subclass methods to be more generic than the parent method which is not what we want. We want subclass Maker.make to be able to have additional arguments not defined in the parent class. We just want to ensure the arguments structure and prev_dir are always present. Not sure if there's a good static analysis way of doing this in Python and enforcing it at runtime seems less useful.

@utf Would be great to get your take here.

@janosh
Copy link
Member Author

janosh commented Oct 27, 2023

Either way, here's a one-liner to migrate atomate2 Flows outside this code base to the new prev_dir keyword:

find ./some/directory -type f -name "*.py" -exec sed -i'' -E 's/prev_(vasp|cp2k|amset)_dir/prev_dir/g' {} +

Or to replace any prev_????_dir:

find ./some/directory -type f -name "*.py" -exec sed -i'' -E 's/prev_.+_dir/prev_dir/g' {} +

@janosh janosh changed the title Unify previous directory Maker API Breaking: Unify previous directory Maker API Oct 30, 2023
@janosh janosh enabled auto-merge (squash) October 30, 2023 17:17
@janosh janosh merged commit 472116e into main Oct 30, 2023
12 of 13 checks passed
@janosh janosh deleted the rename-prev-dir branch October 30, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking changes discussion API design discussions enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants