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

Feature/install from folder #80

Merged
merged 2 commits into from
May 4, 2021
Merged

Feature/install from folder #80

merged 2 commits into from
May 4, 2021

Conversation

bosonie
Copy link
Collaborator

@bosonie bosonie commented Apr 29, 2021

Fixes #79
Fixes #81

@bosonie
Copy link
Collaborator Author

bosonie commented Apr 29, 2021

I also fixed the CI problem every package had (pinned postgresql version).

@bosonie
Copy link
Collaborator Author

bosonie commented Apr 29, 2021

I'm also noticing now that

aiida-pseudo install family https://legacy-archive.materialscloud.org/file/2018.0001/v4/SSSP_1.0_PBE_efficiency.tar.gz label

that should be tested in tests/cli/test_install.py does actually fail in real life. Not because of a problem in the CLI command, but for failing of the underline family_type.create_from_folder. Is it expected?

@bosonie bosonie requested review from sphuber and mbercx April 29, 2021 16:39
@bosonie
Copy link
Collaborator Author

bosonie commented May 2, 2021

@sphuber @mbercx This is ready for review.

@sphuber
Copy link
Contributor

sphuber commented May 2, 2021

I'm also noticing now that

aiida-pseudo install family https://legacy-archive.materialscloud.org/file/2018.0001/v4/SSSP_1.0_PBE_efficiency.tar.gz label

that should be tested in tests/cli/test_install.py does actually fail in real life. Not because of a problem in the CLI command, but for failing of the underline family_type.create_from_folder. Is it expected?

How is it failing exactly? And is it failing on the master branch or with your patch? Or both?

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks @bosonie . I have given it a first pass. I am wondering if we should reuse the PathOrUrl from aiida-core. It checks whether the remote URL can be fetched but than discards the result. Maybe it would be best to create our own custom type that does everything in one go as well as validation. But I can look at this myself later.

aiida_pseudo/cli/params/options.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/params/options.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/params/options.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/params/types.py Show resolved Hide resolved
aiida_pseudo/cli/params/types.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/install.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/install.py Show resolved Hide resolved
aiida_pseudo/cli/install.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/install.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/install.py Outdated Show resolved Hide resolved
@bosonie
Copy link
Collaborator Author

bosonie commented May 2, 2021

I'm also noticing now that

aiida-pseudo install family https://legacy-archive.materialscloud.org/file/2018.0001/v4/SSSP_1.0_PBE_efficiency.tar.gz label

that should be tested in tests/cli/test_install.py does actually fail in real life. Not because of a problem in the CLI command, but for failing of the underline family_type.create_from_folder. Is it expected?

How is it failing exactly? And is it failing on the master branch or with your patch? Or both?

Info: unpacking archive and parsing pseudos...  [FAILED]
Critical: `<class 'aiida_pseudo.data.pseudo.pseudo.PseudoPotentialData'>` constructor did not define the element and could not parse a valid element symbol from the filename `{filename}` either. It should have the format `ELEMENT.EXTENSION`

Also in master

@sphuber
Copy link
Contributor

sphuber commented May 2, 2021

Also in master

I see, well the problem should actually be solved by your PR. Try to run the following on your branch:

aiida-pseudo install family https://legacy-archive.materialscloud.org/file/2018.0001/v4/SSSP_1.0_PBE_efficiency.tar.gz label -P pseudo.upf

As stated in the docstring, the base family type PseudoPotentialFamily will use the basic PseudoPotentialData for the pseudopotentials. The PseudoPotentialData is a base class for "any" format, but it still needs an element. For now, the way I coded it, it only tries to parse this from the filename, because the file content could be anything and there is no way how to parse it for the element. So we impose a strict naming scheme for the filename {ELEMENT}.extension. If this is not the case, we cannot parse the element and so this error is raised. Apparently the SSSP_1.0_PBE_efficiency.tar.gz archive contains a file that doesn't follow this convention and so the element cannot be parsed, hence the error. I am a bit hesitant to start making the parsing more clever because there will always be edge cases that we won't catch and this CLI command was supposed to be just a last way out. One can always use the API to directly to create a family however they want.

@bosonie
Copy link
Collaborator Author

bosonie commented May 2, 2021

I see, well the problem should actually be solved by your PR. Try to run the following on your branch:

Indeed!

@bosonie bosonie requested a review from sphuber May 2, 2021 19:03
@bosonie
Copy link
Collaborator Author

bosonie commented May 2, 2021

I applied all the changes a part form the one I commented.
I did not created our own custom CLI parameter type so far. @sphuber let me know if you wish me to look into it.
Ideally I would love to merge this soon and have a release as well. I will use this features in aiida-siesta and I'm close to a release there as well.

@sphuber
Copy link
Contributor

sphuber commented May 3, 2021

Ideally I would love to merge this soon and have a release as well. I will use this features in aiida-siesta and I'm close to a release there as well.

Just out of curiosity, since this PR just changes the CLI, why would you need this for aiida-siesta? And there are still a few unaddressed comments. I will comment on those specifically so you know which ones.

@bosonie
Copy link
Collaborator Author

bosonie commented May 3, 2021

Just out of curiosity, since this PR just changes the CLI, why would you need this for aiida-siesta? And there are still a few unaddressed comments. I will comment on those specifically so you know which ones.

Because in the package we deliver also examples and material for a tutorial. They require the creation of pseudo families and I do not want to make the topic more complicated than necessary.

@sphuber
Copy link
Contributor

sphuber commented May 3, 2021

Because in the package we deliver also examples and material for a tutorial. They require the creation of pseudo families and I do not want to make the topic more complicated than necessary.

But you guys use psml right, and pseudos from Pseudo Dojo? So why can't you use aiida-pseudo install pseudo-dojo?

@bosonie
Copy link
Collaborator Author

bosonie commented May 3, 2021

But you guys use psml right, and pseudos from Pseudo Dojo? So why can't you use aiida-pseudo install pseudo-dojo?

No, psml is a new addition and will be the standard in the future. The current "stable" version of siesta still not support psml, only psf.

Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

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

Thanks @bosonie! I tried it out on a folder with pseudos I actually needed for a project, so you saved me the trouble of putting them in an archive! ;)

I just had one comment regarding removing the FAMILY_TYPE input. Although I do understand that if someone wants to install an SsspFamily or PseudoDojoFamily, they can use the corresponding command, I actually just now noticed that the base PseudoPotentialFamily doesn't have the RecommendedCutoffMixin as a parent class. So any pseudos installed with the command currently cannot use this functionality. There is the CutoffsFamily class, which @sphuber added mainly for testing purposes, but I'm thinking that perhaps we should make it possible for users to install this class type with the install family command. Or, is there any reason not to give the base PseudoPotentialFamily class the methods for adding and using recommended cutoffs?

aiida_pseudo/cli/install.py Show resolved Hide resolved
@sphuber
Copy link
Contributor

sphuber commented May 3, 2021

@bosonie I have added a commit that implements our own version of PathOrUrl that makes the behavior of the command more consistent with respect to error handling. I have updated and simplified the implementation of the install family command accordingly and. If you are ok with the change, I can merge this. One more thing I realized while working on this, is that we probably should keep the option to change the family type. Creating an SsspFamily doesn't make sense, but I have added the CutoffsFamily and this will allow one to then add custom recommended cutoffs which may be useful. I will add this now

@sphuber
Copy link
Contributor

sphuber commented May 3, 2021

Haha, guess @mbercx agrees with me on that last part. I am not sure if we should add the RecommendedCutoffMixin to the PseudoPotentialFamily base class. Especially since we already have the CutoffsFamily, which indeed I mainly added for testing purposes, but now with the fully fledged install family command, it starts to make sense for real use. Maybe we should rename it slightly though to CutoffsPseudoPotentialFamily to still make it plainly obvious that it is a pseudopotential family. I would also still check the type and only allow pseudo.family and pseudo.family.cutoffs. I don't think we want to allow creating pseudo-dojo or SSSP families through this command. Those respective commands already do that and if there are problems with internet, they even have the option to install directly from archive on disk.

@sphuber
Copy link
Contributor

sphuber commented May 3, 2021

@bosonie and @mbercx added the implementation for the family type. Please have a look

@mbercx
Copy link
Member

mbercx commented May 3, 2021

Haha, guess @mbercx agrees with me on that last part.

😁

I am not sure if we should add the RecommendedCutoffMixin to the PseudoPotentialFamily base class.

Sure, I do appreciate the cleanliness of a mixin class. I'm just wondering if there is a use case for a pseudo family without recommended cutoffs. There probably is, I'm just too in ❤️ with the get_builder_from_protocol method.

Especially since we already have the CutoffsFamily, which indeed I mainly added for testing purposes, but now with the fully fledged install family command, it starts to make sense for real use. Maybe we should rename it slightly though to CutoffsPseudoPotentialFamily to still make it plainly obvious that it is a pseudopotential family.

Fully agree 👍

I would also still check the type and only allow pseudo.family and pseudo.family.cutoffs. I don't think we want to allow creating pseudo-dojo or SSSP families through this command. Those respective commands already do that and if there are problems with internet, they even have the option to install directly from archive on disk.

Although I do agree, I did have a use case for installing a different version of the SSSP today, since there is a small issue with the header of the lanthanide SSSP files and I wanted to test the fixed versions. To circumvent the restriction on the label, I installed the fixed version as SSSP/1.0/efficiency 😬 . Anyways, this is a rare developer use case, and can be easily accomplished by installing a CutoffsPseudoPotentialFamily in the future.

mbercx
mbercx previously approved these changes May 3, 2021
Copy link
Member

@mbercx mbercx 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, thanks @sphuber! Just a small comment that we should perhaps help the user to the right command if they want to install sssp or pseudo_dojo families.

Also: Maybe we should immediately adapt the docstring of CutoffsFamily now that it is a proper class with use cases beyond testing? :)

aiida_pseudo/cli/params/types.py Show resolved Hide resolved
@sphuber
Copy link
Contributor

sphuber commented May 3, 2021

OK, we are starting to cram a bit much into a single PR. I am going to factor out the recent additions and then rebase this so it includes mostly the original idea of fixing install family.

@sphuber sphuber force-pushed the feature/install_from_folder branch from 0831dcb to a41d738 Compare May 3, 2021 22:12
@bosonie
Copy link
Collaborator Author

bosonie commented May 3, 2021

All good from my side! Unlike @mbercx, I was always familiar with families without recommended cutoffs. The good side of a collaborative effort!
Thanks a million!

Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

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

Thanks @sphuber! Just gave the PR a final pass, and have left some minor comments. Merge at your discretion!

Unlike @mbercx, I was always familiar with families without recommended cutoffs.

I guess I'm a little spoiled. 😅

aiida_pseudo/cli/install.py Show resolved Hide resolved
aiida_pseudo/cli/install.py Outdated Show resolved Hide resolved
aiida_pseudo/cli/install.py Outdated Show resolved Hide resolved

family.description = description
echo.echo_success(f'installed `{label}` containing {family.count()} pseudo potentials')
echo.echo_success(f'installed `{label}` containing {family.count()} pseudopotentials')
Copy link
Member

Choose a reason for hiding this comment

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

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I learn from the best

Uptil now, the `install family` command only accepted (compressed)
archives of a directory containing the pseudopotential files. Often,
however, a user may already have an unpacked directory on local disk and
it would be ridiculous to force them to archive it first before being
able to use it with the CLI.

The parameter type of the `archive` argument is changed to use the
`PathOrUrl` type of `aiida-core`. This type will treat the value as a
URL and fetch its content if the value is not a valid filepath on the
local file system. This type is not ideal since its error handling is
different from the rest of the `aiida-pseudo` CLI so its a bit
inhomogeneous, but this will be improved later.

Additionally, the `--pseudo-type` option was added. Historically, the
command only exposed the `--family-type` option since in the beginning
of `aiida-pseudo` each family type defined its own hardcoded pseudo type
so it was implied. Since then, families can define their pseudo type per
instance and so now the `--pseudo-type` option has become necessary to
let the user specify which pseudopotential data class should be used.
sphuber added a commit that referenced this pull request May 4, 2021
Instead of using the `PathOrUrl` parameter type from `aiida-core` we
add our own implementation that uses the `requests` library instead of
`urllib`, but most importantly, it attempts to retrieve the URL in the
`attempt` context manager that will catch any exceptions and properly
display the error and exit the command, just like other important parts
of the command that can fail.

In addition, the `PseudoPotentialFamilyParamType` is updated to take an
`exclude` list at construction time to signify a list of values that are
considered to be invalid. We use this in the `install family` command to
blacklist the `pseudo.family.sssp` and `pseudo.family.pseudo_dojo` since
they have their own dedicated install commands that should be used
instead.

Finally, the `-F/--archive-format` option is changed to use `-f` for the
shorthand instead, such that it allows `-F` for the `--family-type`
which makes more sense there given that we have `-P/--pseudo-type`. The
option was only in use by `install family` which was a broken command
currently anyway, so the breaking change shouldn't affect any users.
@sphuber sphuber force-pushed the feature/install_from_folder branch from a41d738 to c53d623 Compare May 4, 2021 07:04
Instead of using the `PathOrUrl` parameter type from `aiida-core` we
add our own implementation that uses the `requests` library instead of
`urllib`, but most importantly, it attempts to retrieve the URL in the
`attempt` context manager that will catch any exceptions and properly
display the error and exit the command, just like other important parts
of the command that can fail.

In addition, the `PseudoPotentialFamilyParamType` is updated to take an
`exclude` list at construction time to signify a list of values that are
considered to be invalid. We use this in the `install family` command to
blacklist the `pseudo.family.sssp` and `pseudo.family.pseudo_dojo` since
they have their own dedicated install commands that should be used
instead.

Finally, the `-F/--archive-format` option is changed to use `-f` for the
shorthand instead, such that it allows `-F` for the `--family-type`
which makes more sense there given that we have `-P/--pseudo-type`. The
option was only in use by `install family` which was a broken command
currently anyway, so the breaking change shouldn't affect any users.
@sphuber sphuber force-pushed the feature/install_from_folder branch from c53d623 to cadec98 Compare May 4, 2021 07:08
@sphuber
Copy link
Contributor

sphuber commented May 4, 2021

Thanks a lot @bosonie !

@sphuber sphuber merged commit b18c6cb into master May 4, 2021
@sphuber sphuber deleted the feature/install_from_folder branch May 4, 2021 07:11
sphuber pushed a commit that referenced this pull request May 4, 2021
Uptil now, the `install family` command only accepted (compressed)
archives of a directory containing the pseudopotential files. Often,
however, a user may already have an unpacked directory on local disk and
it would be ridiculous to force them to archive it first before being
able to use it with the CLI.

The parameter type of the `archive` argument is changed to use the
`PathOrUrl` type of `aiida-core`. This type will treat the value as a
URL and fetch its content if the value is not a valid filepath on the
local file system. This type is not ideal since its error handling is
different from the rest of the `aiida-pseudo` CLI so its a bit
inhomogeneous, but this will be improved later.

Additionally, the `--pseudo-type` option was added. Historically, the
command only exposed the `--family-type` option since in the beginning
of `aiida-pseudo` each family type defined its own hardcoded pseudo type
so it was implied. Since then, families can define their pseudo type per
instance and so now the `--pseudo-type` option has become necessary to
let the user specify which pseudopotential data class should be used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants