136static std::map<std::string, std::any>
getMembers(PyObject*
object) {
138 PyObject *key(0), *value(0);
141 std::map<std::string, std::any> params;
143 while (PyDict_Next(dictionary, &pos, &key, &value)) {
145 if (PyLong_Check(value)) {
146 if (PyBool_Check(value)) {
147 params[skey] = bool(PyLong_AsLong(value));
149 params[skey] = int(PyLong_AsLong(value));
151 }
else if (PyFloat_Check(value)) {
152 params[skey] = PyFloat_AsDouble(value);
153 }
else if (PyUnicode_Check(value)) {
155 }
else if (PyList_Check(value)) {
157 if (PyList_Size(value) > 0) {
158 auto vec0{PyList_GetItem(value, 0)};
160 if (PyLong_Check(vec0)) {
161 std::vector<int> vals;
163 for (
auto j{0}; j < PyList_Size(value); j++)
164 vals.push_back(PyLong_AsLong(PyList_GetItem(value, j)));
168 }
else if (PyFloat_Check(vec0)) {
169 std::vector<double> vals;
171 for (
auto j{0}; j < PyList_Size(value); j++)
172 vals.push_back(PyFloat_AsDouble(PyList_GetItem(value, j)));
176 }
else if (PyUnicode_Check(vec0)) {
177 std::vector<std::string> vals;
178 for (Py_ssize_t j = 0; j < PyList_Size(value); j++) {
179 PyObject* elem = PyList_GetItem(value, j);
184 }
else if (PyList_Check(vec0)) {
186 if (PyList_Size(vec0) > 0) {
187 auto vecvec0{PyList_GetItem(vec0, 0)};
188 if (PyLong_Check(vecvec0)) {
189 std::vector<std::vector<int>> vals;
190 for (
auto j{0}; j < PyList_Size(value); j++) {
191 auto subvec{PyList_GetItem(value, j)};
192 std::vector<int> subvals;
193 for (
auto k{0}; k < PyList_Size(subvec); k++) {
194 subvals.push_back(PyLong_AsLong(PyList_GetItem(subvec, k)));
196 vals.push_back(subvals);
199 }
else if (PyFloat_Check(vecvec0)) {
200 std::vector<std::vector<double>> vals;
201 for (
auto j{0}; j < PyList_Size(value); j++) {
202 auto subvec{PyList_GetItem(value, j)};
203 std::vector<double> subvals;
204 for (
auto k{0}; k < PyList_Size(subvec); k++) {
206 PyFloat_AsDouble(PyList_GetItem(subvec, k)));
208 vals.push_back(subvals);
211 }
else if (PyUnicode_Check(vecvec0)) {
212 std::vector<std::vector<std::string>> vals;
213 for (
auto j{0}; j < PyList_Size(value); j++) {
214 auto subvec{PyList_GetItem(value, j)};
215 std::vector<std::string> subvals;
216 for (
auto k{0}; k < PyList_Size(subvec); k++) {
217 subvals.push_back(
getPyString(PyList_GetItem(subvec, k)));
219 vals.push_back(subvals);
222 }
else if (PyList_Check(vecvec0)) {
223 EXCEPTION_RAISE(
"BadConf",
224 "A python list with dimension greater than 2 is "
228 std::vector<std::vector<framework::config::Parameters>> vals;
229 for (
auto j{0}; j < PyList_Size(value); j++) {
230 auto subvec{PyList_GetItem(value, j)};
231 std::vector<framework::config::Parameters> subvals;
232 for (
auto k{0}; k < PyList_Size(subvec); k++) {
233 subvals.emplace_back();
234 subvals.back().setParameters(
237 vals.push_back(subvals);
247 std::vector<framework::config::Parameters> vals;
248 for (
auto j{0}; j < PyList_Size(value); ++j) {
249 auto elem{PyList_GetItem(value, j)};
280 FILE* config_file{fopen(pythonScript.c_str(),
"r")};
281 if (config_file == NULL) {
282 EXCEPTION_RAISE(
"ConfigDNE",
283 "Passed config script '" + pythonScript +
284 "' is not accessible.\n"
285 " Did you make a typo in the path to the script?\n"
286 " Are you referencing a directory that is not "
287 "mounted to the container?");
290 std::string cmd = pythonScript;
291 if (pythonScript.rfind(
"/") != std::string::npos) {
292 cmd = pythonScript.substr(pythonScript.rfind(
"/") + 1);
294 cmd = cmd.substr(0, cmd.find(
".py"));
299 wchar_t** targs =
new wchar_t*[nargs + 1];
300 targs[0] = Py_DecodeLocale(pythonScript.c_str(), NULL);
301 for (
int i = 0; i < nargs; i++) targs[i + 1] = Py_DecodeLocale(args[i], NULL);
304 Py_SetProgramName(targs[0]);
314 PySys_SetArgvEx(nargs + 1, targs, 1);
317 if (PyRun_AnyFile(config_file, pythonScript.c_str()) != 0) {
319 EXCEPTION_RAISE(
"ConfigureError",
"Problem running python script.");
325 for (
int i = 0; i < nargs + 1; i++) PyMem_RawFree(targs[i]);
332 PyObject* script = PyImport_ImportModule(
"__main__");
333 if (script == NULL) {
335 EXCEPTION_RAISE(
"ConfigureError",
"Problem loading python script");
337 PyObject* pCMod = PyObject_GetAttrString(script,
root_module.c_str());
341 EXCEPTION_RAISE(
"ConfigureError",
342 "Did not import root configuration module " +
root_module);
345 PyObject* pProcessClass = PyObject_GetAttrString(pCMod,
root_class.c_str());
347 if (pProcessClass == 0) {
349 EXCEPTION_RAISE(
"ConfigureError",
350 "Did not import root configuration class " +
root_class);
354 PyObject_GetAttrString(pProcessClass,
root_object.c_str());
355 Py_DECREF(pProcessClass);
361 "Process object not defined. This object is required to run.");
362 }
else if (pProcess == Py_None) {
364 EXCEPTION_RAISE(
"ConfigureError",
365 "Did not create a configuration class instance");
380 if (Py_FinalizeEx() < 0) {
382 EXCEPTION_RAISE(
"PyError",
383 "I wasn't able to close up the python interpreter!");