-
Notifications
You must be signed in to change notification settings - Fork 51
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
[WIP] Use JSON/TOML template for defining openPMD metadata in a config file #1277
Open
franzpoeschel
wants to merge
35
commits into
openPMD:dev
Choose a base branch
from
franzpoeschel:topic-json-template
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
224a0af
Add openPMD 2.0 standard setting
franzpoeschel 2ef798c
Fix clang-tidy warning
franzpoeschel c2f6e30
Introduce getStandardMaximum(), deprecate getStandard()
franzpoeschel fe5c1b7
Add warning: openPMD 2.0 still under development
franzpoeschel 5525a94
Introduce dataset template mode to JSON backend
franzpoeschel c65b091
Write used mode to JSON file
franzpoeschel de877d3
Use Attribute::getOptional for snapshot attribute
franzpoeschel a62841e
Introduce attribute mode
franzpoeschel 8a8e794
Add example 14_toml_template.cpp
franzpoeschel f24ae79
Use Datatype::UNDEFINED to indicate no dataset definition in template
franzpoeschel 59c93c9
Extend example
franzpoeschel 5a7ed2e
Test short attribute mode
franzpoeschel c25743f
Copy datatypeToString to JSON implementation
franzpoeschel c8dd534
Fix after rebase: Init JSON config in parallel mode
franzpoeschel baf1bdc
Fix after rebase: Don't erase JSON datasets when writing
franzpoeschel 0721e6e
openpmd-pipe: use short modes for test
franzpoeschel fd4a00a
Less intrusive warnings, allow disabling them
franzpoeschel c35c2e4
TOML: Use short modes by default
franzpoeschel e2fa15e
Python formatting
franzpoeschel deba1e9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bd357fe
Documentation
franzpoeschel a75060e
Short mode in default in openPMD >= 2.
franzpoeschel 3f95d77
Short value by default in TOML
franzpoeschel 1e948b2
Store the openPMD version information in the IOHandler
franzpoeschel dcb16d0
Fixes
franzpoeschel a4a0771
Adapt test to recent rebase
franzpoeschel 20d6502
toml11 4.0 compatibility
franzpoeschel 94a8b9f
Initialize Series attributes and datasets from template
franzpoeschel 21a7158
Further testing (@todo: cleanup)
franzpoeschel 1d9257c
Extend example
franzpoeschel aeea63c
Only opt-into tests for TOML
franzpoeschel d5b437d
Adapt this to changed SCALAR API
franzpoeschel c1e2110
Avoid CI warnings
franzpoeschel b8e0537
Fix after rebasing
franzpoeschel 074a93d
Ensure that E.z is there
franzpoeschel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"json": { | ||
"dataset": { | ||
"mode": "template" | ||
}, | ||
"attribute": { | ||
"mode": "short" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#include <openPMD/auxiliary/TemplateFile.hpp> | ||
#include <openPMD/openPMD.hpp> | ||
|
||
std::string backendEnding() | ||
{ | ||
auto extensions = openPMD::getFileExtensions(); | ||
if (auto it = std::find(extensions.begin(), extensions.end(), "toml"); | ||
it != extensions.end()) | ||
{ | ||
return *it; | ||
} | ||
else | ||
{ | ||
// Fallback for buggy old NVidia compiler | ||
return "json"; | ||
} | ||
} | ||
|
||
void write() | ||
{ | ||
std::string config = R"( | ||
{ | ||
"iteration_encoding": "variable_based", | ||
"json": { | ||
"dataset": {"mode": "template"}, | ||
"attribute": {"mode": "short"} | ||
}, | ||
"toml": { | ||
"dataset": {"mode": "template"}, | ||
"attribute": {"mode": "short"} | ||
} | ||
} | ||
)"; | ||
|
||
openPMD::Series writeTemplate( | ||
"../samples/tomlTemplate." + backendEnding(), | ||
openPMD::Access::CREATE, | ||
config); | ||
auto iteration = writeTemplate.writeIterations()[0]; | ||
|
||
openPMD::Dataset ds{openPMD::Datatype::FLOAT, {5, 5}}; | ||
|
||
auto temperature = | ||
iteration.meshes["temperature"][openPMD::RecordComponent::SCALAR]; | ||
temperature.resetDataset(ds); | ||
|
||
auto E = iteration.meshes["E"]; | ||
E["x"].resetDataset(ds); | ||
E["y"].resetDataset(ds); | ||
/* | ||
* Don't specify datatype and extent for this one to indicate that this | ||
* information is not yet known. | ||
*/ | ||
E["z"].resetDataset({openPMD::Datatype::UNDEFINED}); | ||
|
||
ds.extent = {10}; | ||
|
||
auto electrons = iteration.particles["e"]; | ||
electrons["position"]["x"].resetDataset(ds); | ||
electrons["position"]["y"].resetDataset(ds); | ||
electrons["position"]["z"].resetDataset(ds); | ||
|
||
electrons["positionOffset"]["x"].resetDataset(ds); | ||
electrons["positionOffset"]["y"].resetDataset(ds); | ||
electrons["positionOffset"]["z"].resetDataset(ds); | ||
electrons["positionOffset"]["x"].makeConstant(3.14); | ||
electrons["positionOffset"]["y"].makeConstant(3.14); | ||
electrons["positionOffset"]["z"].makeConstant(3.14); | ||
|
||
ds.dtype = openPMD::determineDatatype<uint64_t>(); | ||
electrons.particlePatches["numParticles"][openPMD::RecordComponent::SCALAR] | ||
.resetDataset(ds); | ||
electrons | ||
.particlePatches["numParticlesOffset"][openPMD::RecordComponent::SCALAR] | ||
.resetDataset(ds); | ||
electrons.particlePatches["offset"]["x"].resetDataset(ds); | ||
electrons.particlePatches["offset"]["y"].resetDataset(ds); | ||
electrons.particlePatches["offset"]["z"].resetDataset(ds); | ||
electrons.particlePatches["extent"]["x"].resetDataset(ds); | ||
electrons.particlePatches["extent"]["y"].resetDataset(ds); | ||
electrons.particlePatches["extent"]["z"].resetDataset(ds); | ||
} | ||
|
||
void read() | ||
{ | ||
/* | ||
* The config is entirely optional, these things are also detected | ||
* automatically when reading | ||
*/ | ||
|
||
// std::string config = R"( | ||
// { | ||
// "iteration_encoding": "variable_based", | ||
// "toml": { | ||
// "dataset": {"mode": "template"}, | ||
// "attribute": {"mode": "short"} | ||
// } | ||
// } | ||
// )"; | ||
|
||
openPMD::Series read( | ||
"../samples/tomlTemplate." + backendEnding(), | ||
openPMD::Access::READ_LINEAR); | ||
read.readIterations(); // @todo change to read.parseBase() | ||
|
||
std::string jsonConfig = R"( | ||
{ | ||
"iteration_encoding": "variable_based", | ||
"json": { | ||
"dataset": {"mode": "template"}, | ||
"attribute": {"mode": "short"} | ||
} | ||
} | ||
)"; | ||
openPMD::Series cloned( | ||
"../samples/jsonTemplate.json", openPMD::Access::CREATE, jsonConfig); | ||
openPMD::auxiliary::initializeFromTemplate(cloned, read, 0); | ||
// Have to define the dataset for E/z as it is not defined in the template | ||
// @todo check that the dataset is defined only upon destruction, not at | ||
// flushing already | ||
cloned.writeIterations()[0].meshes["E"].at("z").resetDataset( | ||
{openPMD::Datatype::INT}); | ||
} | ||
|
||
int main() | ||
{ | ||
write(); | ||
read(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Commented-out code Note