nomad-coe / nomad-simulations

A NOMAD plugin containing base sections for simulations.
https://nomad-coe.github.io/nomad-simulations/
Apache License 2.0
5 stars 1 forks source link

Physical property initliazation #129

Closed ladinesa closed 3 weeks ago

ladinesa commented 1 month ago

The initialization of PhysicalProperty objects may require quantities to be defined such as in BaseElectronicEigenvalues, where nbands needs to be specified. This will not work with the mapping parser for we can only set the quantity after creating the section. Is is possible then to either 1. put a default for these required quantities or 2. make the quantities that depend on these required quantites as derived quantites.

@JosePizarro3

JosePizarro3 commented 1 month ago

Yeah, I think this is the weakest point of the dynamical shape.

I guess doing a default could work, can you give me a specific example where this breaks?

ladinesa commented 1 month ago

This does not work:

dct = {'electronic_eigenvalues': [{'n_bands': 3}]}
out = Outputs.m_from_dict(dct)

error

self.rank = [int(kwargs.get('n_bands'))]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
JosePizarro3 commented 1 month ago

I am having a different error with your code:

from nomad_simulations.schema_packages.outputs import Outputs

dct = {'electronic_eigenvalues': [{'n_bands': 3}]}
out = Outputs.m_from_dict(dct)
ValueError: `n_bands` is not defined during initialization of the class.
ladinesa commented 1 month ago

ah yeah I forgot to remove the other fix I put in.

JosePizarro3 commented 1 month ago

While you break it again, I think this is going to be handled different anyways, so I am sure redefining __init__ is not the best programming choice here, but we need a way of handling the static part of the shape of a physical property

ladinesa commented 1 month ago

i am not sure but can we not use the derived quantity decorator?

JosePizarro3 commented 1 month ago

derived? In which sense? you mean in value?

ladinesa commented 1 month ago
def derived(**kwargs):
    def decorator(f) -> Quantity:
        kwargs.setdefault('name', f.__name__)
        kwargs.setdefault(
            'description', f.__doc__.strip() if f.__doc__ is not None else None
        )
        kwargs.setdefault('type', AnyType())

        return Quantity(derived=f, **kwargs)

    return decorator

in metainfo.py

JosePizarro3 commented 3 weeks ago

Closing in favor of #143