DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
Serializer_bind.hpp
Go to the documentation of this file.
1#pragma once
2/// @file Serializer_bind.hpp
3/// @brief pybind11 bindings for the serializer hierarchy (@ref DNDS::SerializerBase "SerializerBase",
4/// @ref DNDS::SerializerJSON "SerializerJSON", @ref DNDS::SerializerH5 "SerializerH5") and the factory.
5
6#include "DNDS/MPI.hpp"
8#include "pybind11_json/pybind11_json.hpp"
9namespace py = pybind11;
10
11#include "SerializerBase.hpp"
12#include "SerializerH5.hpp"
13#include "SerializerJSON.hpp"
14
15#include "SerializerFactory.hpp"
16#include <pybind11/stl.h>
17
18#include <utility>
19
20namespace DNDS::Serializer
21{
22 inline auto pybind11_SerializerBase_declare(py::module_ m)
23 {
24 return py_class_ssp<SerializerBase>(std::move(m), "SerializerBase");
25 }
26
27 inline auto pybind11_SerializerBase_get_class(const py::module_ &m)
28 {
29 return py_class_ssp<SerializerBase>(m.attr("SerializerBase"));
30 }
31 inline void pybind11_SerializerBase_define(py::module_ m)
32 {
33 auto Serializer_ = pybind11_SerializerBase_declare(std::move(m));
34 using tSerializer = SerializerBase;
35 // Serializer_ //! no initializer (ctor) as this is virtual base
36 // .def(py::init<>());
37 Serializer_
38 .def("OpenFile", &tSerializer::OpenFile, py::arg("fName"), py::arg("read"))
39 .def("CloseFile", &tSerializer::CloseFile)
40 .def("GoToPath", &tSerializer::GoToPath, py::arg("p"))
41 .def("CreatePath", &tSerializer::CreatePath, py::arg("p"))
42 .def("GetCurrentPath", &tSerializer::GetCurrentPath)
43 .def("ListCurrentPath", &tSerializer::ListCurrentPath)
44 .def("IsPerRank", &tSerializer::IsPerRank);
45 }
46
47 inline auto pybind11_SerializerJSON_declare(const py::module_ &m)
48 {
50 }
51 inline void pybind11_SerializerJSON_define(const py::module_ &m)
52 {
53 auto Serializer_ = pybind11_SerializerJSON_declare(m);
54 using tSerializer = SerializerJSON;
55 Serializer_
56 .def(py::init<>());
57 Serializer_
58 .def("SetDeflateLevel", &tSerializer::SetDeflateLevel)
59 .def("SetUseCodecOnUint8", &tSerializer::SetUseCodecOnUint8);
60 }
61
62 inline auto pybind11_SerializerH5_declare(const py::module_ &m)
63 {
65 }
66 inline void pybind11_SerializerH5_define(const py::module_ &m)
67 {
68 auto Serializer_ = pybind11_SerializerH5_declare(m);
69 using tSerializer = SerializerH5;
70 Serializer_
71 .def(py::init<const MPIInfo &>(), py::arg("mpi"));
72 Serializer_
73 .def("SetChunkAndDeflate", &tSerializer::SetChunkAndDeflate, py::arg("n_chunksize"), py::arg("n_deflateLevel"))
74 .def("SetCollectiveRW", &tSerializer::SetCollectiveRW);
75 }
76
77 inline auto pybind11_SerializerFactory_declare(py::module_ m)
78 {
79 return py_class_ssp<SerializerFactory>(std::move(m), "SerializerFactory");
80 }
81 inline void pybind11_SerializerFactory_define(py::module_ m)
82 {
83 auto SerializerFactory_ = pybind11_SerializerFactory_declare(std::move(m));
84 SerializerFactory_
85 .def(py::init<>())
86 // .def(py::init<const std::string &>(), py::arg("type"))
87 .def("BuildSerializer", &SerializerFactory::BuildSerializer, py::arg("mpi"))
88 .def("ModifyFilePath", &SerializerFactory::ModifyFilePath,
89 py::arg("fname"), py::arg("mpi"), py::arg("rank_part_fmt") = "%06d",
90 py::arg("read") = false)
91 .def(
92 "to_dict",
93 [](SerializerFactory &self) -> py::object
94 {
95 nlohmann::ordered_json j;
96 to_json(j, self);
97 return j;
98 })
99 .def(
100 "from_dict",
101 [](SerializerFactory &self, const py::object &options_in) -> void
102 {
103 nlohmann::json j(options_in);
104 from_json(j, self);
105 });
106 }
107
108 void pybind11_bind_Serializer(py::module_ m);
109}
Shared pybind11 plumbing used by every *_bind.hpp in DNDS (buffer-protocol type check,...
MPI wrappers: MPIInfo, collective operations, type mapping, CommStrategy.
Eigen::Matrix< real, 3, 3 > m
Base types and abstract interface for array serialization.
Configurable factory that builds either a SerializerJSON or a SerializerH5 with all tunables exposed ...
MPI-parallel HDF5 serializer implementing the SerializerBase interface.
Per-rank JSON serializer implementing the SerializerBase interface.
Abstract interface for reading/writing scalars, vectors, and byte arrays.
MPI-parallel HDF5 serializer; all ranks collectively read/write a single .h5 file.
Per-rank JSON file serializer; each MPI rank writes its own .json file.
void pybind11_SerializerBase_define(py::module_ m)
auto pybind11_SerializerH5_declare(const py::module_ &m)
void pybind11_SerializerFactory_define(py::module_ m)
auto pybind11_SerializerBase_declare(py::module_ m)
void pybind11_bind_Serializer(py::module_ m)
auto pybind11_SerializerJSON_declare(const py::module_ &m)
auto pybind11_SerializerBase_get_class(const py::module_ &m)
auto pybind11_SerializerFactory_declare(py::module_ m)
void pybind11_SerializerJSON_define(const py::module_ &m)
void pybind11_SerializerH5_define(const py::module_ &m)
py::classh< T > py_class_ssp
void from_json(const nlohmann::ordered_json &j, host_device_vector< real > &v)
Definition JsonUtil.hpp:183
void to_json(nlohmann::ordered_json &j, const host_device_vector< real > &v)
Definition JsonUtil.hpp:177
Config-backed factory selecting between JSON and HDF5 serializers.
std::tuple< std::string, std::string > ModifyFilePath(std::string fname, const MPIInfo &mpi, const std::string &rank_part_fmt="%06d", bool read=false) const
Expand a user-supplied base file name into the backend-specific path layout.
SerializerBaseSSP BuildSerializer(const MPIInfo &mpi) const
Instantiate the selected serializer and apply its tunables.