DNDSR 0.1.0.dev1+gcd065ad
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 "MPI.hpp"
7#include "Defines_bind.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
18namespace DNDS::Serializer
19{
20 inline auto pybind11_SerializerBase_declare(py::module_ m)
21 {
22 return py_class_ssp<SerializerBase>(m, "SerializerBase");
23 }
24
25 inline auto pybind11_SerializerBase_get_class(py::module_ m)
26 {
27 return py_class_ssp<SerializerBase>(m.attr("SerializerBase"));
28 }
29 inline void pybind11_SerializerBase_define(py::module_ m)
30 {
31 auto Serializer_ = pybind11_SerializerBase_declare(m);
32 using tSerializer = SerializerBase;
33 // Serializer_ //! no initializer (ctor) as this is virtual base
34 // .def(py::init<>());
35 Serializer_
36 .def("OpenFile", &tSerializer::OpenFile, py::arg("fName"), py::arg("read"))
37 .def("CloseFile", &tSerializer::CloseFile)
38 .def("GoToPath", &tSerializer::GoToPath, py::arg("p"))
39 .def("CreatePath", &tSerializer::CreatePath, py::arg("p"))
40 .def("GetCurrentPath", &tSerializer::GetCurrentPath)
41 .def("ListCurrentPath", &tSerializer::ListCurrentPath)
42 .def("IsPerRank", &tSerializer::IsPerRank);
43 }
44
45 inline auto pybind11_SerializerJSON_declare(py::module_ m)
46 {
48 }
49 inline void pybind11_SerializerJSON_define(py::module_ m)
50 {
51 auto Serializer_ = pybind11_SerializerJSON_declare(m);
52 using tSerializer = SerializerJSON;
53 Serializer_
54 .def(py::init<>());
55 Serializer_
56 .def("SetDeflateLevel", &tSerializer::SetDeflateLevel)
57 .def("SetUseCodecOnUint8", &tSerializer::SetUseCodecOnUint8);
58 }
59
60 inline auto pybind11_SerializerH5_declare(py::module_ m)
61 {
63 }
64 inline void pybind11_SerializerH5_define(py::module_ m)
65 {
66 auto Serializer_ = pybind11_SerializerH5_declare(m);
67 using tSerializer = SerializerH5;
68 Serializer_
69 .def(py::init<const MPIInfo &>(), py::arg("mpi"));
70 Serializer_
71 .def("SetChunkAndDeflate", &tSerializer::SetChunkAndDeflate, py::arg("n_chunksize"), py::arg("n_deflateLevel"))
72 .def("SetCollectiveRW", &tSerializer::SetCollectiveRW);
73 }
74
75 inline auto pybind11_SerializerFactory_declare(py::module_ m)
76 {
77 return py_class_ssp<SerializerFactory>(m, "SerializerFactory");
78 }
79 inline void pybind11_SerializerFactory_define(py::module_ m)
80 {
81 auto SerializerFactory_ = pybind11_SerializerFactory_declare(m);
82 SerializerFactory_
83 .def(py::init<>())
84 // .def(py::init<const std::string &>(), py::arg("type"))
85 .def("BuildSerializer", &SerializerFactory::BuildSerializer, py::arg("mpi"))
86 .def("ModifyFilePath", &SerializerFactory::ModifyFilePath,
87 py::arg("fname"), py::arg("mpi"), py::arg("rank_part_fmt") = "%06d",
88 py::arg("read") = false)
89 .def(
90 "to_dict",
91 [](SerializerFactory &self) -> py::object
92 {
93 nlohmann::ordered_json j;
94 to_json(j, self);
95 return j;
96 })
97 .def(
98 "from_dict",
99 [](SerializerFactory &self, py::object options_in) -> void
100 {
101 nlohmann::json j(options_in);
102 from_json(j, self);
103 });
104 }
105
106 void pybind11_bind_Serializer(py::module_ m);
107}
Shared pybind11 plumbing used by every *_bind.hpp in DNDS (buffer-protocol type check,...
MPI wrappers: MPIInfo, collective operations, type mapping, CommStrategy.
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_SerializerJSON_declare(py::module_ m)
void pybind11_SerializerFactory_define(py::module_ m)
void pybind11_SerializerJSON_define(py::module_ m)
auto pybind11_SerializerBase_get_class(py::module_ m)
auto pybind11_SerializerBase_declare(py::module_ m)
void pybind11_bind_Serializer(py::module_ m)
void pybind11_SerializerH5_define(py::module_ m)
auto pybind11_SerializerFactory_declare(py::module_ m)
auto pybind11_SerializerH5_declare(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.
SerializerBaseSSP BuildSerializer(const MPIInfo &mpi)
Instantiate the selected serializer and apply its tunables.
std::tuple< std::string, std::string > ModifyFilePath(std::string fname, const MPIInfo &mpi, std::string rank_part_fmt="%06d", bool read=false)
Expand a user-supplied base file name into the backend-specific path layout.