Skip to content

Commit 5c5362e

Browse files
committed
Env variables, better warning message
1 parent ef81bf6 commit 5c5362e

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

src/Series.cpp

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "openPMD/IterationEncoding.hpp"
3333
#include "openPMD/ThrowError.hpp"
3434
#include "openPMD/auxiliary/Date.hpp"
35+
#include "openPMD/auxiliary/Environment.hpp"
3536
#include "openPMD/auxiliary/Filesystem.hpp"
3637
#include "openPMD/auxiliary/JSON_internal.hpp"
3738
#include "openPMD/auxiliary/Mpi.hpp"
@@ -160,9 +161,34 @@ namespace
160161
current - start_parsing);
161162
if (!printed_warning_already)
162163
{
163-
std::cerr
164-
<< R"(Warning: Parsing Iterations is taking a long time. Consider setting {"defer_iteration_parsing": true} for lazy opening of the Series and then explicitly opening Iterations with Iteration::open(). Refer also to the documentation at https://openpmd-api.readthedocs.io. Suppress this warning by setting {"hint_lazy_parsing_timeout": 0}.)"
165-
<< '\n';
164+
std::cerr << &R"END(
165+
[openPMD] WARNING: Parsing Iterations is taking a long time.
166+
Consider using deferred Iteration parsing in order to open the Series lazily.
167+
This can be achieved by either setting an environment variable:
168+
169+
> export OPENPMD_DEFER_ITERATION_PARSING=1
170+
171+
Or by specifying it as part of a JSON/TOML configuration:
172+
173+
> // C++:
174+
> Series simData("my_data_%T.%E", R"({"defer_iteration_parsing": true})");
175+
> // Python:
176+
> simData = opmd.Series("my_data_%T.%E", {"defer_iteration_parsing": True})
177+
178+
Iterations will then be parsed only upon explicit user request:
179+
180+
> series.snapshots()[100].open() // new API
181+
> series.iterations[100].open() // old API
182+
183+
Alternatively, Iterations will be opened implicitly when iterating in
184+
READ_LINEAR access mode.
185+
Refer also to the documentation at https://openpmd-api.readthedocs.io
186+
187+
This warning can be suppressed also by either specifying
188+
an environment variable:
189+
190+
> export OPENPMD_HINT_LAZY_PARSING_TIMEOUT=0
191+
)END"[1] << '\n';
166192
printed_warning_already = true;
167193
}
168194
std::cerr << "Elapsed time: " << total_diff.count()
@@ -3032,9 +3058,18 @@ namespace
30323058
* If yes, read it into the specified location.
30333059
*/
30343060
template <typename From, typename Dest = From>
3035-
void
3036-
getJsonOption(json::TracingJSON &config, std::string const &key, Dest &dest)
3061+
void getJsonOption(
3062+
json::TracingJSON &config,
3063+
std::string const &key,
3064+
Dest &dest,
3065+
std::optional<std::string> envVar = std::nullopt)
30373066
{
3067+
if (envVar.has_value())
3068+
{
3069+
dest = auxiliary::getEnvNum(*envVar, dest);
3070+
std::cout << "Read from env var " << *envVar << " as: " << dest
3071+
<< std::endl;
3072+
}
30383073
if (config.json().contains(key))
30393074
{
30403075
dest = config[key].json().get<From>();
@@ -3077,11 +3112,15 @@ void Series::parseJsonOptions(TracingJSON &options, ParsedInput &input)
30773112
{
30783113
auto &series = get();
30793114
getJsonOption<bool>(
3080-
options, "defer_iteration_parsing", series.m_parseLazily);
3115+
options,
3116+
"defer_iteration_parsing",
3117+
series.m_parseLazily,
3118+
"OPENPMD_DEFER_ITERATION_PARSING");
30813119
getJsonOption<uint64_t>(
30823120
options,
30833121
"hint_lazy_parsing_timeout",
3084-
series.m_hintLazyParsingAfterTimeout);
3122+
series.m_hintLazyParsingAfterTimeout,
3123+
"OPENPMD_HINT_LAZY_PARSING_TIMEOUT");
30853124
internal::SeriesData::SourceSpecifiedViaJSON rankTableSource;
30863125
if (getJsonOptionLowerCase(options, "rank_table", rankTableSource.value))
30873126
{

0 commit comments

Comments
 (0)