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

Physical property initliazation #129

Open
ladinesa opened this issue Sep 24, 2024 · 8 comments
Open

Physical property initliazation #129

ladinesa opened this issue Sep 24, 2024 · 8 comments

Comments

@ladinesa
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator Author

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

@JosePizarro3
Copy link
Collaborator

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
Copy link
Collaborator Author

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

@JosePizarro3
Copy link
Collaborator

derived? In which sense? you mean in value?

@ladinesa
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants