rollout: fix bugs in checking list lengths, add tests

This commit is contained in:
Levi Burner
2025-01-21 00:34:40 -05:00
parent 699a6765e3
commit cee122116e
3 changed files with 90 additions and 6 deletions
+8 -4
View File
@@ -254,16 +254,20 @@ class Rollout {
}
// check length d and nthread are consistent
if (this->nthread_ == 0 && py::len(d) > 1) {
if (py::len(d) == 0) {
std::ostringstream msg;
msg << "The list of data instances is empty";
throw py::value_error(msg.str());
} else if (this->nthread_ == 0 && py::len(d) > 1) {
std::ostringstream msg;
msg << "More than one data instance passed but "
<< "rollout is configured to run on main thread";
py::value_error(msg.str());
} else if (this->nthread_ != py::len(d)) {
throw py::value_error(msg.str());
} else if (this->nthread_ > 0 && this->nthread_ != py::len(d)) {
std::ostringstream msg;
msg << "Length of data: " << py::len(d)
<< " not equal to nthread: " << this->nthread_;
py::value_error(msg.str());
throw py::value_error(msg.str());
}
std::vector<raw::MjData*> data_ptrs(py::len(d));