-
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
JSON/TOML backend: introduce abbreviated IO modes #1493
Merged
franzpoeschel
merged 28 commits into
openPMD:dev
from
franzpoeschel:topic-json-short-modes
Dec 16, 2024
+1,560
−160
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3b06c09
Introduce dataset template mode to JSON backend
franzpoeschel 0258000
Write used mode to JSON file
franzpoeschel a48e92e
Use Attribute::getOptional for snapshot attribute
franzpoeschel e6e5357
Introduce attribute mode
franzpoeschel 0f2d33f
Add example 14_toml_template.cpp
franzpoeschel 52e518d
Use Datatype::UNDEFINED to indicate no dataset definition in template
franzpoeschel e03d21d
Extend example
franzpoeschel ce3aab4
Test short attribute mode
franzpoeschel 06d7ec1
Copy datatypeToString to JSON implementation
franzpoeschel b29d64d
Fix after rebase: Init JSON config in parallel mode
franzpoeschel 76f2421
Fix after rebase: Don't erase JSON datasets when writing
franzpoeschel d5534cb
openpmd-pipe: use short modes for test
franzpoeschel 7983763
Less intrusive warnings, allow disabling them
franzpoeschel f413d75
TOML: Use short modes by default
franzpoeschel 429ade5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c309e89
Documentation
franzpoeschel e5f1177
Short mode in default in openPMD >= 2.
franzpoeschel 183c1a1
Short value by default in TOML
franzpoeschel 395cd10
Store the openPMD version information in the IOHandler
franzpoeschel d4b6f88
Fixes
franzpoeschel afa0165
Adapt test to recent rebase
franzpoeschel 50ea53c
toml11 4.0 compatibility
franzpoeschel 61a84c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d5b35e2
wip: cleanup
franzpoeschel 346c37e
wip: cleanup
franzpoeschel be3543a
Cleanup
franzpoeschel 7f81e62
Extensive testing
franzpoeschel 985a59f
CI fixes
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,111 @@ | ||
#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({}); | ||
|
||
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.parseBase(); | ||
openPMD::helper::listSeries(read); | ||
} | ||
|
||
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
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