From 28f10eed708e38e941e921fe182b9bd1710d59f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 9 Oct 2023 16:25:10 +0200 Subject: [PATCH 1/5] Add openPMD 2.0 standard setting --- include/openPMD/Error.hpp | 6 ++++++ include/openPMD/version.hpp | 20 ++++++++++++++++++-- src/Error.cpp | 6 ++++++ src/Series.cpp | 13 ++++++++----- src/binding/python/Error.cpp | 3 +++ src/version.cpp | 10 ++++++++++ test/CoreTest.cpp | 5 ++++- test/SerialIOTest.cpp | 1 + 8 files changed, 56 insertions(+), 8 deletions(-) diff --git a/include/openPMD/Error.hpp b/include/openPMD/Error.hpp index 3e516e16ec..d1762e7e6d 100644 --- a/include/openPMD/Error.hpp +++ b/include/openPMD/Error.hpp @@ -109,6 +109,12 @@ namespace error public: NoSuchAttribute(std::string attributeName); }; + + class IllegalInOpenPMDStandard : public Error + { + public: + IllegalInOpenPMDStandard(std::string what); + }; } // namespace error /** diff --git a/include/openPMD/version.hpp b/include/openPMD/version.hpp index 9f32154d92..3bc1c13967 100644 --- a/include/openPMD/version.hpp +++ b/include/openPMD/version.hpp @@ -37,11 +37,20 @@ * compile-time) * @{ */ -#define OPENPMD_STANDARD_MAJOR 1 -#define OPENPMD_STANDARD_MINOR 1 +#define OPENPMD_STANDARD_MAJOR 2 +#define OPENPMD_STANDARD_MINOR 0 #define OPENPMD_STANDARD_PATCH 0 /** @} */ +/** maximum supported version of the openPMD standard (read & write, + * compile-time) + * @{ + */ +#define OPENPMD_STANDARD_DEFAULT_MAJOR 1 +#define OPENPMD_STANDARD_DEFAULT_MINOR 1 +#define OPENPMD_STANDARD_DEFAULT_PATCH 0 +/** @} */ + /** minimum supported version of the openPMD standard (read, compile-time) * @{ */ @@ -79,6 +88,13 @@ std::string getVersion(); */ std::string getStandard(); +/** Return the default used version of the openPMD standard (read & write, + * run-time) + * + * @return std::string openPMD standard version (dot separated) + */ +std::string getStandardDefault(); + /** Return the minimum supported version of the openPMD standard (read, * run-time) * diff --git a/src/Error.cpp b/src/Error.cpp index f2e27a0213..dbc13f40b0 100644 --- a/src/Error.cpp +++ b/src/Error.cpp @@ -122,6 +122,12 @@ namespace error , description(std::move(description_in)) {} + IllegalInOpenPMDStandard::IllegalInOpenPMDStandard(std::string what_in) + : Error( + "Operation leads to illegal use of the openPMD standard:\n" + + std::move(what_in)) + {} + void throwReadError( AffectedObject affectedObject, Reason reason, diff --git a/src/Series.cpp b/src/Series.cpp index d587575b44..fbbb8bf1bf 100644 --- a/src/Series.cpp +++ b/src/Series.cpp @@ -162,9 +162,10 @@ std::string Series::basePath() const Series &Series::setBasePath(std::string const &bp) { std::string version = openPMD(); - if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0") + if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" || + version == "2.0.0") throw std::runtime_error( - "Custom basePath not allowed in openPMD <=1.1.0"); + "Custom basePath not allowed in openPMD <=2.0"); setAttribute("basePath", bp); return *this; @@ -1222,7 +1223,7 @@ void Series::initDefaults(IterationEncoding ie, bool initAll) } } if (!containsAttribute("openPMD")) - setOpenPMD(getStandard()); + setOpenPMD(getStandardDefault()); /* * In Append mode, only init the rest of the defaults after checking that * the file does not yet exist to avoid overriding more than needed. @@ -1828,7 +1829,8 @@ void Series::readOneIterationFileBased(std::string const &filePath) Parameter pOpen; std::string version = openPMD(); - if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0") + if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" || + version == "2.0.0") pOpen.path = auxiliary::replace_first(basePath(), "/%T/", ""); else throw error::ReadError( @@ -1980,7 +1982,8 @@ creating new iterations. Parameter pOpen; std::string version = openPMD(); - if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0") + if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" || + version == "2.0.0") pOpen.path = auxiliary::replace_first(basePath(), "/%T/", ""); else throw error::ReadError( diff --git a/src/binding/python/Error.cpp b/src/binding/python/Error.cpp index 681398c579..27d9c7d9b4 100644 --- a/src/binding/python/Error.cpp +++ b/src/binding/python/Error.cpp @@ -9,6 +9,7 @@ #include "openPMD/Error.hpp" #include "openPMD/binding/python/Common.hpp" +#include void init_Error(py::module &m) { @@ -22,6 +23,8 @@ void init_Error(py::module &m) py::register_exception(m, "ErrorInternal", baseError); py::register_exception( m, "ErrorNoSuchAttribute", baseError); + py::register_exception( + m, "ErrorIllegalInOpenPMDStandard", baseError); #ifndef NDEBUG m.def("test_throw", [](std::string description) { diff --git a/src/version.cpp b/src/version.cpp index c2e8809a32..5feeccba13 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -41,6 +41,16 @@ std::string openPMD::getStandard() return standard.str(); } +std::string openPMD::getStandardDefault() +{ + std::stringstream standard; + standard << OPENPMD_STANDARD_DEFAULT_MAJOR << "." + << OPENPMD_STANDARD_DEFAULT_MINOR << "." + << OPENPMD_STANDARD_DEFAULT_PATCH; + std::string const standardstr = standard.str(); + return standardstr; +} + std::string openPMD::getStandardMinimum() { std::stringstream standardMin; diff --git a/test/CoreTest.cpp b/test/CoreTest.cpp index 17739e0b28..7c119ca0b6 100644 --- a/test/CoreTest.cpp +++ b/test/CoreTest.cpp @@ -36,8 +36,11 @@ TEST_CASE("versions_test", "[core]") auto const is_dot = [](char const c) { return c == '.'; }; REQUIRE(2u == std::count_if(apiVersion.begin(), apiVersion.end(), is_dot)); + auto const standardDefault = getStandardDefault(); + REQUIRE(standardDefault == "1.1.0"); + auto const standard = getStandard(); - REQUIRE(standard == "1.1.0"); + REQUIRE(standard == "2.0.0"); auto const standardMin = getStandardMinimum(); REQUIRE(standardMin == "1.0.0"); diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index f55c5ec235..166c4d7e3a 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -912,6 +912,7 @@ inline void constant_scalar(std::string const &file_ending) // constant scalar Series s = Series("../samples/constant_scalar." + file_ending, Access::CREATE); + s.setOpenPMD("2.0.0"); auto rho = s.iterations[1].meshes["rho"][MeshRecordComponent::SCALAR]; REQUIRE(s.iterations[1].meshes["rho"].scalar()); rho.resetDataset(Dataset(Datatype::CHAR, {1, 2, 3})); From ab45f42fa25feee6a773f974cffb59e80af9b405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Tue, 28 Nov 2023 11:35:23 +0100 Subject: [PATCH 2/5] Fix clang-tidy warning --- src/version.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/version.cpp b/src/version.cpp index 5feeccba13..1f89156695 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -47,8 +47,7 @@ std::string openPMD::getStandardDefault() standard << OPENPMD_STANDARD_DEFAULT_MAJOR << "." << OPENPMD_STANDARD_DEFAULT_MINOR << "." << OPENPMD_STANDARD_DEFAULT_PATCH; - std::string const standardstr = standard.str(); - return standardstr; + return standard.str(); } std::string openPMD::getStandardMinimum() From 06ba1a84ea006e059013f555933e53496bc49410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 4 Dec 2023 15:31:10 +0100 Subject: [PATCH 3/5] Introduce getStandardMaximum(), deprecate getStandard() --- include/openPMD/version.hpp | 12 +++++++++++- src/version.cpp | 13 +++++++++---- test/CoreTest.cpp | 4 +--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/openPMD/version.hpp b/include/openPMD/version.hpp index 3bc1c13967..11071a6f65 100644 --- a/include/openPMD/version.hpp +++ b/include/openPMD/version.hpp @@ -86,7 +86,10 @@ std::string getVersion(); * * @return std::string openPMD standard version (dot separated) */ -std::string getStandard(); +[[deprecated( + "Deprecated due to unclear semantics. Use one of getStandardMinimum, " + "getStandardMaximum() or getStandardDefault instead.")]] std::string +getStandard(); /** Return the default used version of the openPMD standard (read & write, * run-time) @@ -102,6 +105,13 @@ std::string getStandardDefault(); */ std::string getStandardMinimum(); +/** Return the minimum supported version of the openPMD standard (read, + * run-time) + * + * @return std::string minimum openPMD standard version (dot separated) + */ +std::string getStandardMaximum(); + /** Return the feature variants of the openPMD-api library (run-time) * * @return std::map< std::string, bool > with variants such as backends diff --git a/src/version.cpp b/src/version.cpp index 1f89156695..78f09ca733 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -35,10 +35,7 @@ std::string openPMD::getVersion() std::string openPMD::getStandard() { - std::stringstream standard; - standard << OPENPMD_STANDARD_MAJOR << "." << OPENPMD_STANDARD_MINOR << "." - << OPENPMD_STANDARD_PATCH; - return standard.str(); + return getStandardMaximum(); } std::string openPMD::getStandardDefault() @@ -58,3 +55,11 @@ std::string openPMD::getStandardMinimum() << OPENPMD_STANDARD_MIN_PATCH; return standardMin.str(); } + +std::string openPMD::getStandardMaximum() +{ + std::stringstream standard; + standard << OPENPMD_STANDARD_MAJOR << "." << OPENPMD_STANDARD_MINOR << "." + << OPENPMD_STANDARD_PATCH; + return standard.str(); +} diff --git a/test/CoreTest.cpp b/test/CoreTest.cpp index 7c119ca0b6..d27d68a8c5 100644 --- a/test/CoreTest.cpp +++ b/test/CoreTest.cpp @@ -1,6 +1,4 @@ // expose private and protected members for invasive testing -#include "openPMD/Datatype.hpp" -#include "openPMD/Error.hpp" #if openPMD_USE_INVASIVE_TESTS #define OPENPMD_private public: #define OPENPMD_protected public: @@ -39,7 +37,7 @@ TEST_CASE("versions_test", "[core]") auto const standardDefault = getStandardDefault(); REQUIRE(standardDefault == "1.1.0"); - auto const standard = getStandard(); + auto const standard = getStandardMaximum(); REQUIRE(standard == "2.0.0"); auto const standardMin = getStandardMinimum(); From b821b5c7c55638e6e64ab75b74ad20bc345f0746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Fri, 24 May 2024 16:49:31 +0200 Subject: [PATCH 4/5] Add warning: openPMD 2.0 still under development --- src/Series.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Series.cpp b/src/Series.cpp index fbbb8bf1bf..a3749c5e73 100644 --- a/src/Series.cpp +++ b/src/Series.cpp @@ -139,6 +139,11 @@ std::string Series::openPMD() const Series &Series::setOpenPMD(std::string const &o) { + if (o >= "2.0") + { + std::cerr << "[Warning] openPMD 2.0 is still under development." + << std::endl; + } setAttribute("openPMD", o); return *this; } From 4890c786e9486afea018ca0fa2902b21a3cf5245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 28 Oct 2024 14:59:06 +0100 Subject: [PATCH 5/5] Remove unnecessary import --- src/binding/python/Error.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/binding/python/Error.cpp b/src/binding/python/Error.cpp index 27d9c7d9b4..348c63f2cd 100644 --- a/src/binding/python/Error.cpp +++ b/src/binding/python/Error.cpp @@ -9,7 +9,6 @@ #include "openPMD/Error.hpp" #include "openPMD/binding/python/Common.hpp" -#include void init_Error(py::module &m) {