Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions pyphare/pyphare/pharein/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,20 @@ def getSimulation():
return sim


def _patch_data_ids(path):
def _patch_data_ids(restart_file_dir):
"""
for restarts we save samrai patch data ids to the restart files, which we access from here
to tell samrai which patch datas to load from the restart file on restart
"""
import h5py
from pyphare.cpp import cpp_etc_lib

h5File = cpp_etc_lib().samrai_restart_file(path)
return h5py.File(h5File, "r")["phare"]["patch"]["ids"][:]
return cpp_etc_lib().patch_data_ids(restart_file_dir)


def _serialized_simulation_string(path):
import h5py
def _serialized_simulation_string(restart_file_dir):
from pyphare.cpp import cpp_etc_lib

h5File = cpp_etc_lib().samrai_restart_file(path)
return h5py.File(h5File, "r")["phare"].attrs["serialized_simulation"]
return cpp_etc_lib().serialized_simulation_string(restart_file_dir)


# converts scalars to array of expected size
Expand Down
14 changes: 13 additions & 1 deletion src/hdf5/detail/h5/h5_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class HighFiveFile

~HighFiveFile() {}

NO_DISCARD HiFile& file() { return h5file_; }
NO_DISCARD HiFile& file()
{
return h5file_;
}


template<typename T, std::size_t dim = 1>
Expand Down Expand Up @@ -235,6 +238,15 @@ class HighFiveFile
}
}

template<typename Attr = std::string>
auto read_attribute(std::string const& path, std::string const& key)
{
auto at = h5file_.getGroup(path).getAttribute(key);
Attr attr;
at.read(attr);
return attr;
}


HighFiveFile(const HighFiveFile&) = delete;
HighFiveFile(const HighFiveFile&&) = delete;
Expand Down
28 changes: 25 additions & 3 deletions src/python3/cpp_etc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ auto samrai_version()

PYBIND11_MODULE(cpp_etc, m)
{
auto samrai_restart_file = [](std::string path) {
return PHARE::amr::HierarchyRestarter::getRestartFileFullPath(path);
};
py::class_<core::Span<double>, std::shared_ptr<core::Span<double>>>(m, "Span");
py::class_<PyArrayWrapper<double>, std::shared_ptr<PyArrayWrapper<double>>, core::Span<double>>(
m, "PyWrapper");
Expand All @@ -46,14 +49,33 @@ PYBIND11_MODULE(cpp_etc, m)
return versions;
});

m.def("samrai_restart_file", [](std::string path) {
return PHARE::amr::HierarchyRestarter::getRestartFileFullPath(path);
});
m.def("samrai_restart_file", samrai_restart_file);

m.def("restart_path_for_time", [](std::string path, double timestamp) {
return PHARE::amr::Hierarchy::restartFilePathForTime(path, timestamp);
});

m.def("phare_build_config", []() { return PHARE::build_config(); });

m.def("patch_data_ids", [&](std::string const& path) -> std::vector<int> {
_PHARE_WITH_HIGHFIVE({
auto const& restart_file = samrai_restart_file(path);
PHARE::hdf5::h5::HighFiveFile h5File{restart_file, HighFive::File::ReadOnly,
/*para=*/false};
return h5File.read_data_set<int>("/phare/patch/ids");
});

throw std::runtime_error("PHARE not built with highfive support");
});
m.def("serialized_simulation_string", [&](std::string const& path) -> std::string {
_PHARE_WITH_HIGHFIVE({
auto const& restart_file = samrai_restart_file(path);
PHARE::hdf5::h5::HighFiveFile h5File{restart_file, HighFive::File::ReadOnly,
/*para=*/false};
return h5File.read_attribute("/phare", "serialized_simulation");
});

throw std::runtime_error("PHARE not built with highfive support");
});
}
} // namespace PHARE::pydata