-
Notifications
You must be signed in to change notification settings - Fork 82
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
ProtocolMixin
: increase flexibility and usability for other packages
#678
Conversation
ProtocolMixin
construct .yaml
file from class pathProtocolMixin
construct .yaml
filepath from class module path
Or you could use importlib.resources 😉 |
Nice, wasn't aware of this module 👌. Will have a closer look tomorrow. |
15a5e02
to
038fba3
Compare
I am wondering if we want to really make this utility more reusable by other plugins, why not make it more flexible still. The changes are still making quite some assumptions about where protocol files are supposed to be stored. I remember that we were also thinking of passing a completely custom protocol file on call of |
One design question here: Do we add another input argument (e.g. clean_workdir: True
max_meta_convergence_iterations: 5
meta_convergence: True
volume_convergence: 0.02
base:
pw:
parameters:
CELL:
press_conv_thr: 0.5
base_final_scf:
pw:
parameters:
CELL:
press_conv_thr: 0.5 I'm leaning towards the latter option, since some who wants to use their own protocol probably isn't looking to define multiple (or can just use multiple files), and it means they only have to replace one input and not consider an extra one. |
There is also the question whether a custom protocol file that is passed completely replaces existing protocols, or simply adds to it, i.e. the final protocol is the union of the default and custom files taken together. I think that would maybe give the highest flexibility. In that case, I would also not repurpose the
|
I'm not sure if I fully agree. If the user wants to override some settings of an already existing protocol, the
I think these two inputs cover all use cases, e.g. by repurposing the |
038fba3
to
a04a055
Compare
After working on this a bit, I've come to the conclusion that allowing the We could add another
and then having to select the A couple of notes:
|
ProtocolMixin
construct .yaml
filepath from class module pathProtocolMixin
: increase flexibility and usability for other packages
a04a055
to
2b49b01
Compare
Ok, let's try to separate the various requests in action here. If I understand the current code in this PR, it mostly makes the Then there is the question how the existing protocol files that ship with the package, can be (partially) modified at runtime. I think the use case here is that a user of the |
To me, what you are describing as slightly modifying is exactly the overrides.
Yes, but our protocol files are a little mixed. On the one hand it specifies defaults for the top-level inputs, and then overrides for the lower-level inputs. Moreover, it is even more complex, since each protocol file also defines two more protocols that again override the values that are defined by the
Again, this is exactly what the Let me try and crystallise the difference between a protocol and the overrides somewhat more:
The What the user can't do yet, is easily define a pure protocol (which I tried to do by passing a When I first looked at how the protocol files were set up, I was a little confused. I was expecting 1 Sorry for the long-winded explanation. I hope I wasn't being redundant. 😅 |
2b49b01
to
3d22468
Compare
@sphuber the changes have been separated in two commits as discussed, and the PR is ready for review! |
The `load_protocol_file` method in the protocol utils.py module uses the path of the module file to obtain the path to the .yaml file that described the protocols. However, this fails in case the `ProtocolMixin` class is used by other packages, since the protocol files of the package's work chains will be stored in that package. Here we adapt the `ProtocolMixin` class as follows: * Add a `get_protocol_filepath()` class method that needs to be implemented by the work chain classes that use the `ProtocolMixin`. * Move the `load_protocol_file` method into the `ProtocolMixin` class as a hidden method that relies on the `get_protocol_filepath` method. Moreover, the `Path` to the hardcoded protocols that ship with the package are now also obtained using `importlib_resources`. It is added as a dependency as this was backported from Python 3.9.
Currently the user can only adapt the protocol by specifying `overrides` as a dictionary, or adapting the builder afterwards. Here the `get_protocol_inputs` method is made more flexible by accepting a `pathlib.Path` for the `overrides` input. This allows the user to define protocol overrides in a `.yaml` file.
3d22468
to
dd30172
Compare
noticed that you said "allow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good (except for the fumble in one of the commit message, but you have been forgiven) thanks @mbercx
Working on |
Fixes #677
The load_protocol_file method in the protocol utils.py
module uses the path of the module file to obtain the path to the .yaml
file that described the protocols. However, this fails in case the
ProtocolMixin
class is used by other packages, since the protocol filesof the package's work chains will be stored in that package.
Moreover, the user can only adapt the protocol by specifying
overrides
as a dictionary, or adapting the builder afterwards.Here we adapt the
ProtocolMixin
class as follows:get_protocol_filepath()
class method that needs to beimplemented by the work chain classes that use the
ProtocolMixin
.load_protocol_file
method into theProtocolMixin
class asa hidden method that relies on the
get_protocol_filepath
method.get_protocol_inputs
method is made more flexible by acceptinga
pathlib.Path
for theoverrides
input. This allows the user todefine protocol overrides in a
.yaml
file.The
Path
to the hardcoded protocols that ship with the package are nowalso obtained using
importlib_resources
.