Skip to content

Commit

Permalink
Fix C++ solver dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai committed Oct 13, 2023
1 parent b656da4 commit 086ad8c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions examples/cpp-dummy/micro_cpp_dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ py::dict MicroSimulation::solve(py::dict macro_data, double dt)
// This function needs to set the complete state of a micro simulation
void MicroSimulation::set_state(py::list state)
{
_sim_id = state[0].cast<int>()
_micro_scalar_data = state[1].cast<double>();
_state = state[2].cast<double>();
_micro_scalar_data = state[0].cast<double>();
_state = state[1].cast<double>();
}

// This function needs to return variables which can fully define the state of a micro simulation
py::list MicroSimulation::get_state() const
{
std::vector<double> state{_sim_id, _micro_scalar_data, _state};
std::vector<double> state{_micro_scalar_data, _state};
py::list state_python = py::cast(state);
return state_python;
}
Expand All @@ -65,7 +64,7 @@ PYBIND11_MODULE(micro_dummy, m) {
m.doc() = "pybind11 micro dummy plugin";

py::class_<MicroSimulation>(m, "MicroSimulation")
.def(py::init())
.def(py::init<int>())
.def("solve", &MicroSimulation::solve)
.def("get_state", &MicroSimulation::get_state)
.def("set_state", &MicroSimulation::set_state)
Expand All @@ -74,7 +73,7 @@ PYBIND11_MODULE(micro_dummy, m) {
return ms.get_state();
},
[](py::list t) { // __setstate__
if (t.size() != 3)
if (t.size() != 2)
throw std::runtime_error("Invalid state!");

/* Create a new C++ instance */
Expand Down

0 comments on commit 086ad8c

Please sign in to comment.