Skip to content

Commit fef83c3

Browse files
committed
Use cpp_function instead (.def(...))
These lose the setters, but those were not used anyway? bit of an ugly workaround
1 parent 84163e8 commit fef83c3

4 files changed

Lines changed: 28 additions & 26 deletions

File tree

src/binding/python/Iteration.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,18 @@ void init_Iteration(py::module &m)
9494
.def("set_dt", &Iteration::setDt<double>)
9595
.def("set_time_unit_SI", &Iteration::setTimeUnitSI)
9696

97-
// .def_readwrite(
98-
// "meshes",
99-
// &Iteration::meshes,
100-
// py::return_value_policy::copy,
101-
// // garbage collection: return value must be freed before Iteration
102-
// py::keep_alive<1, 0>())
103-
// .def_readwrite(
104-
// "particles",
105-
// &Iteration::particles,
106-
// py::return_value_policy::copy,
107-
// // garbage collection: return value must be freed before Iteration
108-
// py::keep_alive<1, 0>())
109-
;
97+
.def(
98+
"__meshes",
99+
[](Iteration &i) { return i.meshes; },
100+
py::return_value_policy::copy,
101+
// garbage collection: return value must be freed before Iteration
102+
py::keep_alive<1, 0>())
103+
.def(
104+
"__particles",
105+
[](Iteration &i) { return i.particles; },
106+
py::return_value_policy::copy,
107+
// garbage collection: return value must be freed before Iteration
108+
py::keep_alive<1, 0>());
110109

111110
add_pickle(
112111
cl, [](openPMD::Series series, std::vector<std::string> const &group) {

src/binding/python/ParticleSpecies.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ void init_ParticleSpecies(py::module &m)
4848
return stream.str();
4949
})
5050

51-
// .def_readwrite(
52-
// "particle_patches",
53-
// &ParticleSpecies::particlePatches,
54-
// py::return_value_policy::copy,
55-
// // garbage collection: return value must be freed before Series
56-
// py::keep_alive<1, 0>())
57-
;
51+
.def(
52+
"__particle_patches",
53+
[](ParticleSpecies &ps) { return ps.particlePatches; },
54+
py::return_value_policy::copy,
55+
// garbage collection: return value must be freed before Series
56+
py::keep_alive<1, 0>());
5857
add_pickle(
5958
cl, [](openPMD::Series series, std::vector<std::string> const &group) {
6059
uint64_t const n_it = std::stoull(group.at(1));

src/binding/python/Series.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,12 @@ this method.
497497
.def("set_iteration_format", &Series::setIterationFormat)
498498
.def("set_name", &Series::setName)
499499

500-
// .def_readwrite(
501-
// "iterations",
502-
// &Series::iterations,
503-
// py::return_value_policy::copy,
504-
// // garbage collection: return value must be freed before Series
505-
// py::keep_alive<1, 0>())
500+
.def(
501+
"__iterations",
502+
[](Series &s) { return s.iterations; },
503+
py::return_value_policy::copy,
504+
// garbage collection: return value must be freed before Series
505+
py::keep_alive<1, 0>())
506506
.def(
507507
"read_iterations",
508508
[](Series &s) {

src/binding/python/openpmd_api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
Record_Component.to_dask_array = record_component_to_daskarray # noqa
1717
Series.to_df = iterations_to_dataframe # noqa
1818
Series.to_cudf = iterations_to_cudf # noqa
19+
Series.iterations = property(Series.__iterations)
20+
Iteration.meshes = property(Iteration.__meshes)
21+
Iteration.particles = property(Iteration.__particles)
22+
ParticleSpecies.particle_patches = property(ParticleSpecies.__particle_patches)
1923

2024
# TODO remove in future versions (deprecated)
2125
Access_Type = Access # noqa

0 commit comments

Comments
 (0)