Skip to content

Commit 2f6b305

Browse files
committed
Env variables, better warning message
1 parent ef81bf6 commit 2f6b305

1 file changed

Lines changed: 48 additions & 7 deletions

File tree

src/Series.cpp

Lines changed: 48 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,36 @@ 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+
192+
Or by the JSON/TOML option {"hint_lazy_parsing_timeout": 0}.
193+
)END"[1] << '\n';
166194
printed_warning_already = true;
167195
}
168196
std::cerr << "Elapsed time: " << total_diff.count()
@@ -3032,9 +3060,18 @@ namespace
30323060
* If yes, read it into the specified location.
30333061
*/
30343062
template <typename From, typename Dest = From>
3035-
void
3036-
getJsonOption(json::TracingJSON &config, std::string const &key, Dest &dest)
3063+
void getJsonOption(
3064+
json::TracingJSON &config,
3065+
std::string const &key,
3066+
Dest &dest,
3067+
std::optional<std::string> envVar = std::nullopt)
30373068
{
3069+
if (envVar.has_value())
3070+
{
3071+
dest = auxiliary::getEnvNum(*envVar, dest);
3072+
std::cout << "Read from env var " << *envVar << " as: " << dest
3073+
<< std::endl;
3074+
}
30383075
if (config.json().contains(key))
30393076
{
30403077
dest = config[key].json().get<From>();
@@ -3077,11 +3114,15 @@ void Series::parseJsonOptions(TracingJSON &options, ParsedInput &input)
30773114
{
30783115
auto &series = get();
30793116
getJsonOption<bool>(
3080-
options, "defer_iteration_parsing", series.m_parseLazily);
3117+
options,
3118+
"defer_iteration_parsing",
3119+
series.m_parseLazily,
3120+
"OPENPMD_DEFER_ITERATION_PARSING");
30813121
getJsonOption<uint64_t>(
30823122
options,
30833123
"hint_lazy_parsing_timeout",
3084-
series.m_hintLazyParsingAfterTimeout);
3124+
series.m_hintLazyParsingAfterTimeout,
3125+
"OPENPMD_HINT_LAZY_PARSING_TIMEOUT");
30853126
internal::SeriesData::SourceSpecifiedViaJSON rankTableSource;
30863127
if (getJsonOptionLowerCase(options, "rank_table", rankTableSource.value))
30873128
{

0 commit comments

Comments
 (0)