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

Update models according to changes during CECAM 2020 meeting #350

Merged
merged 20 commits into from Jun 19, 2020

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jun 15, 2020

Closes #343.

Added as an optional field, though we need a discussion about which fields are truly optional in the models (as almost everything is optional in the spec).

@CasperWA I can't work on this again until this evening, if you wanted to add other models to this PR then feel free to edit.

Closes #342
Closes #344
Closes #345

@ml-evs ml-evs requested review from CasperWA, fekad and shyamd June 15, 2020 09:39
@codecov
Copy link

codecov bot commented Jun 15, 2020

Codecov Report

Merging #350 into master will increase coverage by 0.32%.
The diff coverage is 98.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
+ Coverage   90.59%   90.92%   +0.32%     
==========================================
  Files          55       54       -1     
  Lines        2276     2336      +60     
==========================================
+ Hits         2062     2124      +62     
+ Misses        214      212       -2     
Flag Coverage Δ
#unittests 90.92% <98.31%> (+0.32%) ⬆️
Impacted Files Coverage Δ
optimade/adapters/structures/pymatgen.py 100.00% <ø> (ø)
optimade/server/routers/info.py 96.15% <ø> (ø)
optimade/models/structures.py 95.18% <96.72%> (+0.78%) ⬆️
optimade/adapters/structures/aiida.py 100.00% <100.00%> (ø)
optimade/adapters/structures/ase.py 100.00% <100.00%> (ø)
optimade/adapters/structures/cif.py 100.00% <100.00%> (ø)
optimade/adapters/structures/jarvis.py 100.00% <100.00%> (ø)
optimade/adapters/structures/proteindatabank.py 100.00% <100.00%> (ø)
optimade/models/entries.py 100.00% <100.00%> (ø)
optimade/models/index_metadb.py 100.00% <100.00%> (+5.55%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c6c84d...5bce8e5. Read the comment docs.

@CasperWA
Copy link
Member

Added as an optional field, though we need a discussion about which fields are truly optional in the models (as almost everything is optional in the spec).

Exactly this is related to the issue #198.

@CasperWA
Copy link
Member

CasperWA commented Jun 15, 2020

Changes to models:

  • nattached and attached OPTIONAL fields to species.
  • Removed possibility for having unknown positions (i.e., null values in a position.
  • Updated structure_features:
    • Remove unknown_positions flag.
    • Add site_attachments and implicit_atoms flags.
  • Add the OPTIONAL properties aggregate and no_aggregate_reason to LinksResource.
    aggregate values MUST be in a specific (literal) set, a validator has been added for this.
  • Add the OPTIONAL field type to properties under EntryInfoResource.
  • New Enum called DataType to list out the OPTIMADE Data types.
    It has also gotten some useful methods:
    • get_values(): Retrieve a sorted list of all values
    • from_python_type(): Return enumeration based on a Python type (pass either a type, object or a string representation of the type).
    • from_json_type(): Return enumeration based on a JSON type or OpenAPI-specific "format" of type.
      In the OpenAPI specification type is mandatory, hence all pydantic model schemas will always return a type. It may be further specified by an additional field format, which could hold values such as date-time, email, etc.
  • Use enumerations for various "literal" values (since Literal cannot be used):
    • aggregate (in LinksResourceAttributes)
    • link_type (in LinksResourceAttributes)
    • key in index meta-database's ´/infoendpointrelationships(inIndexInfoResource`)
    • structure_features (in StructureResourceAttributes)

Changes to code:

  • Removed padding of positions and testing unknown positions for StructureAdapter and related conversion functions.
  • Creating type field in entry listing info endpoints' properties dictionary based on the models' OpenAPI schema properties' format value, falling back on the mandatory type key.
  • Use new enumerations where necessary.

@CasperWA
Copy link
Member

We are currently only testing the validators and validity of the structures models explicitly.
This should be extended to include references and links (at minimum).

@CasperWA CasperWA changed the title Add nperiodic_dimensions field Update models according to changes during CECAM 2020 meeting Jun 15, 2020
@CasperWA CasperWA mentioned this pull request Jun 15, 2020
3 tasks
@classmethod
def from_python_type(cls, python_type: Union[type, str, object]):
"""Get OPTIMADE data type from a Python type"""
mapping = {
Copy link
Member Author

Choose a reason for hiding this comment

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

Could we define these mappings (incl. JSON map below) as properties?
e.g.

@property
def python_to_optimade_type_map(...):

and

@property
json_to_optimade_type_map(...)

Copy link
Member

@CasperWA CasperWA Jun 15, 2020

Choose a reason for hiding this comment

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

Tried to do this, the issue is that then it's not reachable on the class level, i.e., DataType.from_json_type("number") doesn't work anymore.
If they're both instance methods/properties, then you first have to instantiate it, i.e., DataType("float").from_json_type("date-time"), which is quite confusing, since "float" is completely ignored in this process.

Do you have a smart way of doing this? Other than just making it a static method perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm trying to do it with static methods now, but that of course doesn't work since we're utilizing the self referenced enumerations ...
Could I make the mappings enumerations? Or should they simply be outside the Enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, hmm, didn't appreciate this when I left my suggestion. In that case, I would leave it as is for now; I like the classmethod access and this is a clean way of doing it.

I'll profile the manipulation of our models at some point so we can target our optimisations, then we can decide where to put the effort in.

optimade/server/routers/utils.py Show resolved Hide resolved
@ml-evs
Copy link
Member Author

ml-evs commented Jun 15, 2020

We are currently only testing the validators and validity of the structures models explicitly.
This should be extended to include references and links (at minimum).

Agreed, one for #104, I guess...

@CasperWA
Copy link
Member

I've taken care of the merge conflicts with the test structures and found that we weren't actually testing test_more_structures.json, so I updated this, testing it again, and found that some of the both new and old validators were wrong.

I had to change the initialization of species_at_sites and species in order to have species available in the validation of species_at_sites. species does not really care about species_at_sites, so it's fine.

We apparently validated that a species MUST be in species_at_sites as well, which is not a hard MUST. So I removed this validation. It seems we should really go through all of our validators again...

@CasperWA
Copy link
Member

We need to make some more tests - especially for LinksResources.
Hence, I have now restructured tests/models.

It now uses pylint properly and loads and uses the test data via pytest fixtures.

@ml-evs
Copy link
Member Author

ml-evs commented Jun 16, 2020

Is this good to go now?

@ml-evs
Copy link
Member Author

ml-evs commented Jun 19, 2020

Is this good to go now?

I can't review my own PR (unfortunately), but I'm happy with all the changes here now if someone else would like to review it...

ml-evs and others added 11 commits June 19, 2020 16:16
site_attachments is a flag under structure_features.
attached and nattached are fields for a species.
Currently it tests whether a species is represented in species_at_sites,
however, implicit_atoms MUST also be set for some assemblies, this
validation should be added.
It used to be a flag in structure_features, but has been replaced by
implicit_atoms and site_attachments.
Several conversion functions for the StructureAdapter specifically
handled None values in cartesian_site_positions, which is no longer an
option, hence, these extra steps have been removed from the affected
conversion functions.
These are optional properties for a LinksResource.
Using again test_more_structures.json revealed some errors with the new
validators, as well as some updates that needed to be done to existing
validators.

In order to properly validate `species_at_sites` it has to be
instantiated _after_ `species`.
Move to pytest.
Add fixtures for loading test data.
@ml-evs
Copy link
Member Author

ml-evs commented Jun 19, 2020

This is really blocking other PRs now, I think @CasperWA is away at the moment, @shyamd or @fekad could you take a look if you get time?

@shyamd shyamd merged commit b93610b into master Jun 19, 2020
@CasperWA CasperWA deleted the ml-evs/nperiodic_dims branch June 24, 2020 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants