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
Code example for alternative ways of passing setting of a relaxation workchain #516
base: develop
Are you sure you want to change the base?
Conversation
This is a code example, not meant to be merged as it is.
Codecov Report
@@ Coverage Diff @@
## develop #516 +/- ##
===========================================
- Coverage 72.74% 67.07% -5.66%
===========================================
Files 57 58 +1
Lines 6612 7171 +559
===========================================
Hits 4809 4809
- Misses 1803 2362 +559
Continue to review full report at Codecov.
|
@zhubonan, I feel the implementation of |
@atztogo I guess you mean the way of using properties for attributes? I think that is a valid pythonic approach and It is probably better to split |
@zhubonan, thanks for your answer. My question may be even more trivial. I see it works from https://docs.python.org/3/library/functions.html#property, but it was difficult for me to see what |
I am not aware of another way of achieving the same functionality, at least without making it more complicated. The key feature is that when one can do:
The The |
I see your point. After some reading about python descriptor (https://docs.python.org/3/howto/descriptor.html#properties), I understood how property works (at a certain level), and some more reading, I understood "property factory" is a known pattern. So I agree your code is well designed. Due to lack of my knowledge, I thought it looked tricky. During the reading, I found, from python3.6, aiida-vasp/aiida_vasp/workchains/alt_relax.py Line 301 in 8660629
An example of the usage is found at the last section of https://realpython.com/python-descriptors/. I feel the descriptor class approach is more intuitive when reading the code. Some discussion about comparison between the property factory and the descriptor class approach is found in the book Fluent Python, too. Considering also the flexibility and extendability, it may be good to consider using the descriptor class approach, which may be encouraged by the fact that minimum python version dependency of aiida-vasp is now python3.6. |
@atztogo I see. Yeah using the |
@atztogo I have updated the code using descriptors. Now the syntax is better with more code reuse. One thing to keep in mind is that we still have to inherit Please try it out. Some examples:
|
Super!
I guess this was information difficult to find... |
This is a code example, not meant to be merged as it is.
Description
This is for continuing the discussion in #510. Perhaps a separate issue should be raised.
This PR serves as an example of an alternative way of passing the settings inputs for
VaspRelaxWorkChain
. Which many other work chains would face the same problem. If there are many settings/flags to be passed for controlling the workflows, it is better to store them in a singleDict
node, rather than individualNode
inside a largePortNamespace
. The latter would create a lot more input nodes for the work chain, which is not space-efficient and would make submitting the work chain very slow.There are some other functionalities that I implemented in this code example, such as bootstrapping a hybrid calculation, modify parameters for the final static run, and additional checks. But the main point is to discuss the design of the input interface.