feat(python): added robust python bindings covering the entire codebase

This commit is contained in:
2025-07-23 16:26:30 -04:00
parent 6a22cb65b8
commit f20bffc411
134 changed files with 2202 additions and 170 deletions

View File

@@ -0,0 +1,43 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h> // Needed for vectors, maps, sets, strings
#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc. if needed directly
#include "bindings.h"
namespace py = pybind11;
#include "gridfire/network.h"
void register_type_bindings(pybind11::module &m) {
py::class_<gridfire::NetIn>(m, "NetIn")
.def(py::init<>())
.def_readwrite("composition", &gridfire::NetIn::composition)
.def_readwrite("tMax", &gridfire::NetIn::tMax)
.def_readwrite("dt0", &gridfire::NetIn::dt0)
.def_readwrite("temperature", &gridfire::NetIn::temperature)
.def_readwrite("density", &gridfire::NetIn::density)
.def_readwrite("energy", &gridfire::NetIn::energy)
.def("__repr__", [](const gridfire::NetIn &netIn) {
std::stringstream ss;
ss << "NetIn(composition=" << netIn.composition
<< ", tMax=" << netIn.tMax
<< ", dt0=" << netIn.dt0
<< ", temperature=" << netIn.temperature
<< ", density=" << netIn.density
<< ", energy=" << netIn.energy << ")";
return ss.str();
});
py::class_<gridfire::NetOut>(m, "NetOut")
.def_readonly("composition", &gridfire::NetOut::composition)
.def_readonly("num_steps", &gridfire::NetOut::num_steps)
.def_readonly("energy", &gridfire::NetOut::energy)
.def("__repr__", [](const gridfire::NetOut &netOut) {
std::stringstream ss;
ss << "NetOut(composition=" << netOut.composition
<< ", num_steps=" << netOut.num_steps
<< ", energy=" << netOut.energy << ")";
return ss.str();
});
}

View File

@@ -0,0 +1,5 @@
#pragma once
#include <pybind11/pybind11.h>
void register_type_bindings(pybind11::module &m);

View File

@@ -0,0 +1,17 @@
# Define the library
bindings_sources = files('bindings.cpp')
bindings_headers = files('bindings.h')
dependencies = [
gridfire_dep,
python3_dep,
pybind11_dep,
]
shared_module('py_gf_types',
bindings_sources,
cpp_args: ['-fvisibility=default'],
install : true,
dependencies: dependencies,
include_directories: include_directories('.')
)