8000 Proper inheritance of fields and attributes by lukaspie · Pull Request #621 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Proper inheritance of fields and attributes #621

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

Merged
merged 14 commits into from
Apr 25, 2025
Merged

Conversation

lukaspie
Copy link
Collaborator
@lukaspie lukaspie commented Apr 9, 2025

No description provided.

Comment on lines 233 to 236
if not set(NEXUS_TO_PYTHON_DATA_TYPES[self.dtype]).issubset(NEXUS_TO_PYTHON_DATA_TYPES[elem_type]):
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is for allowing specialization of data types in inheritance, right? Is this something we want? Does NIAC have an opinion here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's basically checking that the inherited concept does not have a mismatch with the concept its supposedly specializing. You need that so that e.g. a field mode(NX_CHAR) in a specialized NXdata doesn't get assigned AXISNAME in its inheritance.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could also check that they are equal, then e.g. NX_FLOAT in an appdef would not match NX_NUMBER in the base class. Not sure what we and/or NIAC want here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What I always understood it is okay to narrow down, e.g. make an NX_INT from the base class and NX_POSINT in the application definition (hence the subset here). None of this is really thought out though, most people in NIAC didn't really consider this inheritance on the fields level at all so far (see also discussion in nexusformat/definitions#1533), so we can more or less make our own conventions.

Comment on lines 246 to 253
if self.items is None:
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

This breaks: AttributeError: 'NexusChoice' object has no attribute 'items'
Also, do we want to allow an inherited concept to completely remove any enumeration?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This happens on ELECTRON_DETECTOR/pixel_shape.
Rather than showing the name, it is recognized also only as NexusChoise object in the debugger:
image
Not sure why

Copy link
Collaborator
@rettigl rettigl Apr 11, 2025

Choose a reason for hiding this comment

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

Ah,I think because choice might not be implemented yet completely?
These don't even show up in the documentation page, see
https://manual.nexusformat.org/classes/base_classes/NXdetector.html
vs.
https://github.com/nexusformat/definitions/blob/2aede967caebc84f3335d50f1344f9b3ed2e8603/base_classes/NXdetector.nxdl.xml#L908

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah,I think because choice might not be implemented yet completely? These don't even show up in the documentation page, see manual.nexusformat.org/classes/base_classes/NXdetector.html vs. nexusformat/definitions@2aede96/base_classes/NXdetector.nxdl.xml#L908

Yeah, docs are only built after NIAC releases, so we sort of have to go with our version to see the latest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NexusChoice isn't really working yet though, here it should really only check for NeXusEntity objects.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That was my thought as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved the compatibility check to NexusEntity now and used the old inheritance for NexusChoice.

Comment on lines 280 to 289
# Should we really be this strict here? Or can appdefs define additional terms?
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe needs discussion. I would say the base classes should contain the possible set of values, and the appdefs restrict them, but I'm not sure how it is handled by NIAC

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From my understanding, from the intital NeXus design, you can also add more enum items if needed, but this really breaks the way typical inheritance works, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we don't have to be too pedantic here, but we should maybe think about if there are cases where this could lead to wrong inheritance assignments. I don't think so, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can also skip the items and dimensions checks for now and only re-activate if we ever see such problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I disabled now that we check that the node's items are a subset of the items of the inherited concept.

One potentially misleading case is NXbeam/TRANSFORMATIONS/DIRECTION-field, which has transformation_type="translation".
In NXxps, we have NXxps/ENTRY/INSTRUMENT/beam_probe/transformations/beam_azimuth_angle-field, which has transformation_type="translation".

Without this check here, beam_azimuth_angle will inherit from DIRECTION because the type and unit are the same. This is however rather a problem of NXbeam, which should just not define a DIRECTION field with nameType="any" IMO.

return False
return True

def _check_dimensions_fit(xml_elem: ET._Element) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want this/is this necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I deactivated this for now, we can see if any dimensions-related problems in the inheritance arise in the future.

@lukaspie lukaspie force-pushed the sibling-inheritance branch from f96fa75 to e0a70cd Compare April 24, 2025 08:07
@@ -33,13 +33,13 @@ jobs:
branch: main
tests_to_run: tests/.
- plugin: pynxtools-mpes
branch: main
branch: entry-identifier
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

revert here and for raman/spm before merging

@lukaspie lukaspie marked this pull request as ready for review April 24, 2025 10:01
@lukaspie
Copy link
Collaborator Author

@rettigl this should work now. You should also be able to write AXISNAME[energy] for a named axis energy. What still doesn't work is if you have keys like

ENTRY[entry]/DATA[data]/energy
ENTRY[entry]/DATA[data]/AXISNAME[energy]/@type

This will log a warning if @type is required. The validator correctly picks up that AXISNAME[energy] and energy are two variants of the same concepts, but then it continues by checking the subtree for _each_variant individually and just doesn't find @type in energy.

So currently, you either need to use AXISNAME[energy] OR energy for all subkeys. But I guess that's okay.

Copy link
Collaborator
@rettigl rettigl left a comment

Choose a reason for hiding this comment

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

Thanks, this mostly seems to work properly now.
Checking of required attributes (@energy_reference etc. in NXmpes_arpes) did not work for me before, for which I added another fix.
This currently requires the notation @AXISNAME_indices[@energy_indices], but I think this is what we agreed on.
Maybe we can add a test for this as well, and maybe we should add some description of this to the documentation.
Otherwise, LGTM

@lukaspie lukaspie merged commit da81bdf into master Apr 25, 2025
17 checks passed
@lukaspie lukaspie deleted the sibling-inheritance branch April 25, 2025 11:01
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

Successfully merging this pull request may close these issues.

3 participants
0