Mapping guide doc#131
Conversation
|
I will just for now give a review solely on the docs. Can do one later the rest of the parser, if necessary. |
yes please 🤝 i have just quickly pushed the doc from a random branch of mine, the rest is indeed not relevant |
ndaelman-hu
left a comment
There was a problem hiding this comment.
Thank you for adding this. Most of the feedback below comes down to specific phrases.
More importantly, how should we combine this with the docs in nomad-docs?
I would keep both in the same repo, don't have strong feelings which one.
|
|
||
| ## What a mapping annotation is | ||
|
|
||
| - A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.* |
There was a problem hiding this comment.
| - A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.* | |
| - A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and place it in the archive under the path leading to the annotated schema field.* |
There was a problem hiding this comment.
this is what i initially wanted to avoid actually, as this internal document is trying to have a casual and simple approach
|
|
||
| - A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.* | ||
| - Stored on any section/quantity: `m_annotations['mapping'][<KEY>] = MapperAnnotation(mapper=...)`. | ||
| - `<KEY>` names the source (e.g., `OUT_KEY`, `HDF5_KEY`, `INFO_KEY`, `BAND_KEY`). |
There was a problem hiding this comment.
I would add "why we there may be multiple keys". If there was only one, that field would not be necessary.
There was a problem hiding this comment.
this part is focusing on what, and not why. we should avoid giving out too many details at once
There was a problem hiding this comment.
sure, then maybe add the "why" above
|
|
||
| - A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.* | ||
| - Stored on any section/quantity: `m_annotations['mapping'][<KEY>] = MapperAnnotation(mapper=...)`. | ||
| - `<KEY>` names the source (e.g., `OUT_KEY`, `HDF5_KEY`, `INFO_KEY`, `BAND_KEY`). |
There was a problem hiding this comment.
Minor nitpick: it doesn't "name" the source per se (as in it does not define the source file).
It just defines a particular source format / mapping.
| - A small note on a schema field that says: *for source `<KEY>`, read value at `<PATH>` and put it here.* | ||
| - Stored on any section/quantity: `m_annotations['mapping'][<KEY>] = MapperAnnotation(mapper=...)`. | ||
| - `<KEY>` names the source (e.g., `OUT_KEY`, `HDF5_KEY`, `INFO_KEY`, `BAND_KEY`). | ||
| - Paths use JMESPath style. Relative paths start with `.` (from the parent’s mapped node). `@` anchors at the source root. |
There was a problem hiding this comment.
| - Paths use JMESPath style. Relative paths start with `.` (from the parent’s mapped node). `@` anchors at the source root. | |
| - Paths use [JMESPath](https://jmespath.org/) style. Relative paths start with `.` (from the parent’s mapped node). `@` anchors at the source root. |
|
|
||
| 1) A source parser (`XMLParser`, `HDF5Parser`, `TextParser`, etc.) reads a file into a Python dict. | ||
| 2) Set `annotation_key` on a `MetainfoParser` to the `<KEY>` that matches the annotations. | ||
| 3) Call `convert(source_parser, target_parser)`. One key → one `convert`. Multiple keys/sources → run `convert` once per key after switching `annotation_key` each time. |
There was a problem hiding this comment.
One key → one
convert.
Lol, sounds oddly religious.
| add_mapping_annotation(general.Simulation.m_def, OUT_KEY, '@') | ||
| ``` | ||
|
|
||
| ### 2) Nested quantities |
There was a problem hiding this comment.
| ### 2) Nested quantities | |
| ### 2) Quantities |
Quantities can never be at the root.
| add_mapping_annotation(general.Program.version, OUT_KEY, '.program_version') | ||
| ``` | ||
|
|
||
| ### 3) Single nested subsection |
There was a problem hiding this comment.
| ### 3) Single nested subsection | |
| ### 3) Single subsection |
Tautology: the prefix "sub" already clarifies that is "nested" as you refer to it. Moreover, "nested" obtains a very different meaning when talking about serialization and querying. Would avoid it to prevent confusion.
| add_mapping_annotation(model_method.DFT.m_def, OUT_KEY, '.dft') | ||
| ``` | ||
|
|
||
| ### 4) Repeating subsections (lists) |
There was a problem hiding this comment.
| ### 4) Repeating subsections (lists) | |
| ### 4) Repeating subsections & Array-like Quantities |
| ### 5) Multiple sources into the same schema | ||
| Use different keys; run `convert` once per key. | ||
| ```python | ||
| # Octopus uses OUT_KEY + INFO_KEY + EIGENVALUES_KEY on the same schema | ||
| # Exciting uses INFO_KEY, INPUT_XML_KEY, EIGVAL_KEY, BANDSTRUCTURE_XML_KEY, DOS_XML_KEY | ||
| # Wannier90 uses WOUT_KEY, WIN_KEY, BAND_KEY, WHR_KEY, DOS_KEY | ||
| ``` | ||
| Set `annotation_key = <KEY>` before each `convert`. |
There was a problem hiding this comment.
Can you add an example, pls?
From memory, I'd say that convert is called at the parser-level instead of the annotations, but might be fuzzy on that one.
| Set `annotation_key = <KEY>` before each `convert`. | ||
|
|
||
| ### 6) Transformations (reshape, filter, apply units) | ||
| Use a tuple `(function_name, [paths], {kwargs})` and implement the function on the parser. |
There was a problem hiding this comment.
| Use a tuple `(function_name, [paths], {kwargs})` and implement the function on the parser. | |
| Use a tuple `(function_name, [paths], {kwargs})` and implement the function at the parser level. |
Maybe you should introduce the 2 levels.
| - Absolute from root: `field.subfield` (no leading dot) | ||
| - Root anchor: `@` | ||
| - Filter: `.items[?"@name"=="version"] | [0].__value` | ||
| - Attributes (XML/HDF5): keys often prefixed with `@`; values with `__value` |
There was a problem hiding this comment.
Does "often" here mean that this is a convention, but it would theoretically also be possible, to, e.g., prefix a value with @?
|
I will tackle this as part of my documentation work: FAIRmat-NFDI/nomad-simulations#311 |
here is a PR to work together on a practical guide on mapping annotation