Skip to content

Commit a003a9a

Browse files
committed
Adapt examles
1 parent 71e921e commit a003a9a

8 files changed

Lines changed: 47 additions & 18 deletions

examples/11_particle_dataframe.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535

3636
# This "if" is important for distributed dask runs
3737
if __name__ == "__main__":
38-
s = io.Series("../samples/git-sample/data%T.h5", io.Access.read_only)
39-
electrons = s.snapshots()[400].particles["electrons"]
38+
s = io.Series("../samples/git-sample/data%T.h5", io.Access.read_only, {
39+
"defer_iteration_parsing": True
40+
})
41+
# with defer_iteration_parsing, open() must be called explicitly
42+
electrons = s.snapshots()[400].open().particles["electrons"]
4043

4144
# all particles
4245
df = electrons.to_df()

examples/2_read_serial.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ using namespace openPMD;
2929

3030
int main()
3131
{
32-
Series series =
33-
Series("../samples/git-sample/data%T.h5", Access::READ_ONLY);
32+
Series series = Series(
33+
"../samples/git-sample/data%T.h5",
34+
Access::READ_ONLY,
35+
R"({"defer_iteration_parsing": true})");
3436
cout << "Read a Series with openPMD standard version " << series.openPMD()
3537
<< '\n';
3638

@@ -40,7 +42,8 @@ int main()
4042
cout << "\n\t" << i.first;
4143
cout << '\n';
4244

43-
Iteration i = series.snapshots()[100];
45+
// with defer_iteration_parsing, open() must be called explicitly
46+
Iteration i = series.snapshots()[100].open();
4447
cout << "Iteration 100 contains " << i.meshes.size() << " meshes:";
4548
for (auto const &m : i.meshes)
4649
cout << "\n\t" << m.first;

examples/2_read_serial.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
if __name__ == "__main__":
1212
series = io.Series("../samples/git-sample/data%T.h5",
13-
io.Access.read_only)
13+
io.Access.read_only, {
14+
"defer_iteration_parsing": True
15+
})
1416
print("Read a Series with openPMD standard version %s" %
1517
series.openPMD)
1618

@@ -20,7 +22,8 @@
2022
print("\t {0}".format(i))
2123
print("")
2224

23-
i = series.snapshots()[100]
25+
# with defer_iteration_parsing, open() must be called explicitly
26+
i = series.snapshots()[100].open()
2427
print("Iteration 100 contains {0} meshes:".format(len(i.meshes)))
2528
for m in i.meshes:
2629
print("\t {0}".format(m))

examples/2a_read_thetaMode_serial.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ int main()
3131
{
3232
/* The pattern %E instructs the openPMD-api to determine the file ending
3333
* automatically. It can also be given explicitly, e.g. `data%T.h5`. */
34-
Series series =
35-
Series("../samples/git-sample/thetaMode/data%T.h5", Access::READ_ONLY);
34+
Series series = Series(
35+
"../samples/git-sample/thetaMode/data%T.h5",
36+
Access::READ_ONLY,
37+
R"({"defer_iteration_parsing": true})");
3638

37-
Iteration i = series.snapshots()[500];
39+
// defer_iteration_parsing implies that open() must be called explicitly
40+
Iteration i = series.snapshots()[500].open();
3841
MeshRecordComponent E_z_modes = i.meshes["E"]["z"];
3942
Extent extent = E_z_modes.getExtent(); // (modal components, r, z)
4043

examples/2a_read_thetaMode_serial.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
# The pattern %E instructs the openPMD-api to determine the file ending
1313
# automatically. It can also be given explicitly, e.g. `data%T.h5`.
1414
series = io.Series("../samples/git-sample/thetaMode/data%T.h5",
15-
io.Access.read_only)
15+
io.Access.read_only, {
16+
"defer_iteration_parsing": True
17+
})
1618

17-
i = series.snapshots()[500]
19+
# with defer_iteration_parsing, open() must be called explicitly
20+
i = series.snapshots()[500].open()
1821
E_z_modes = i.meshes["E"]["z"]
1922
shape = E_z_modes.shape # (modal components, r, z)
2023

examples/4_read_parallel.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ int main(int argc, char *argv[])
4040
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
4141

4242
Series series = Series(
43-
"../samples/git-sample/data%T.h5", Access::READ_ONLY, MPI_COMM_WORLD);
43+
"../samples/git-sample/data%T.h5",
44+
Access::READ_ONLY,
45+
MPI_COMM_WORLD,
46+
R"({"defer_iteration_parsing": true})");
4447
if (0 == mpi_rank)
4548
cout << "Read a series in parallel with " << mpi_size << " MPI ranks\n";
4649

47-
MeshRecordComponent E_x = series.snapshots()[100].meshes["E"]["x"];
50+
// with defer_iteration_parsing, open() must be called explicitly
51+
// explicit Iteration opening is recommended in general for parallel
52+
// applications
53+
MeshRecordComponent E_x = series.snapshots()[100].open().meshes["E"]["x"];
4854

4955
Offset chunk_offset = {static_cast<long unsigned int>(mpi_rank) + 1, 1, 1};
5056
Extent chunk_extent = {2, 2, 1};

examples/4_read_parallel.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
series = io.Series(
2121
"../samples/git-sample/data%T.h5",
2222
io.Access.read_only,
23-
comm
23+
comm, {
24+
"defer_iteration_parsing": True
25+
}
2426
)
2527
if 0 == comm.rank:
2628
print("Read a series in parallel with {} MPI ranks".format(
2729
comm.size))
2830

29-
E_x = series.snapshots()[100].meshes["E"]["x"]
31+
# with defer_iteration_parsing, open() must be called explicitly
32+
# explicit use of open() is recommended for parallel applications
33+
E_x = series.snapshots()[100].open().meshes["E"]["x"]
3034

3135
chunk_offset = [comm.rank + 1, 1, 1]
3236
chunk_extent = [2, 2, 1]

examples/6_dump_filebased_series.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ using namespace openPMD;
77

88
int main()
99
{
10-
Series o =
11-
Series("../samples/git-sample/data%T.h5", Access::READ_RANDOM_ACCESS);
10+
Series o = Series(
11+
"../samples/git-sample/data%T.h5",
12+
Access::READ_RANDOM_ACCESS,
13+
R"({"defer_iteration_parsing": true})");
1214

1315
std::cout << "Read iterations ";
1416
for (auto const &val : o.snapshots())
@@ -39,6 +41,8 @@ int main()
3941

4042
for (auto &[index, i] : o.snapshots())
4143
{
44+
// with defer_iteration_parsing, open() must be called explicitly
45+
i.open();
4246
std::cout << "Read attributes in iteration " << index << ":\n";
4347
for (auto const &val : i.attributes())
4448
std::cout << '\t' << val << '\n';

0 commit comments

Comments
 (0)