Closed Peter230655 closed 1 month ago
It means the C compliation failed. You've reported the issue before and the cause was that you were using symbols that are not compatible with C, for example Symbol('I_{xx}')
. It can also occur if you don't have a compiler installed, but Timo helped you with that before.
I remember, that initially I did not have the C compiler, and Timo installed it for me. I also remember the issue with these Symbol('I_{xx]'), so now I avoid them. But, frankly, I do not remember what other symbols are to be avoided. Thanks!
But, frankly, I do not remember what other symbols are to be avoided.
Rule of thumb: any symbol name that would give a SyntaxError in Python as well, e.g. I_{xx} = 1
would also give an error in C.
Hint when debugging:
You can specify tmp_dir
when instantiating your opty.direct_collocation.Problem
. If you do so I think that it will actually create those cython files in there allowing you to easily read them to see what is wrong.
Thanks! How exactly would I specify _tempdir ? (You know that I am an idiot in these matters)
These things are found in the documentation: https://opty.readthedocs.io/en/latest/api.html
Search that page for tmp_dir
.
I found it as an argument in opty.utils.ufuncify_matrix. there is another argument expr. Would this be EOM in my case? Thanks!
It is an argument to Problem also.
Found it there, thanks! (Now I need my son to help me create a path to a directory)
I tried to integrate my jumping lamp with pydy.System, to check if my EOMs seem right. I use: sys.generate_ode_function(generator='cython'), which JM had told me to speed up things. This generator = 'cython' worked perfectly well with another program, but here I get this error: Exception: Failed to compile and import Cython module. Could this be related to my problem with opty?
I use the same environment (sympy-dev) given to me by Timo -but maybe I screwed up something?
Thanks!
Yes, it is likely the same issue. You have to look at the generated C code to see the issue.
Thanks! To ensure there is no issue with my environment, I copied the relevant cells of the jumping lamp to a program, where _sys.generate_odefunction(generator='cython') worked - and with the jumping lamp it did not work.
Is there a way to look at the C code with pydy.System? (I looked in the documentation, but could not find anything,...., that's stupid me!)
sys.generate_ode_function(generator='cython', verbose=True)
Thanks! I use this code:
_sys = System(KM)
sys.constants = par_map
sys.initial_conditions = {wert: initial_state_constraints[wert] for wert in qL}
print('sys initial conditions', sys.initial_conditions)
sys.times = np.linspace(0., intervall, int(schritte*intervall))
sys.generate_ode_function(generator='cython', verbose=True)
resultat = sys.integrate()_
And now I get this error message, which seems to look similar to what I get without verbose=True.
TypeError Traceback (most recent call last)
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\codegen\ode_function_generators.py:907](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:907), in generate_ode_function(*args, **kwargs)
[905](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:905) try:
[906](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:906) # See if user passed in a custom class.
--> [907](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:907) g = generator(*args, **kwargs)
[908](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:908) except TypeError:
[909](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:909) # See if user passed in a string.
TypeError: 'str' object is not callable
During handling of the above exception, another exception occurred:
CalledProcessError Traceback (most recent call last)
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\codegen\cython_code.py:222](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:222), in CythonMatrixGenerator.compile(self, tmp_dir, verbose)
[220](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:220) cmd = [sys.executable, self.prefix + '_setup.py', 'build_ext',
[221](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:221) '--inplace']
--> [222](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:222) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
[223](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:223) if verbose:
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\subprocess.py:465](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:465), in check_output(timeout, *popenargs, **kwargs)
[463](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:463) kwargs['input'] = empty
--> [465](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:465) return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
[466](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:466) **kwargs).stdout
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\subprocess.py:569](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:569), in run(input, capture_output, timeout, check, *popenargs, **kwargs)
[568](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:568) if check and retcode:
--> [569](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:569) raise CalledProcessError(retcode, process.args,
[570](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:570) output=stdout, stderr=stderr)
[571](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/subprocess.py:571) return CompletedProcess(process.args, retcode, stdout, stderr)
CalledProcessError: Command '['c:\\Users\\Peter\\anaconda3\\envs\\sympy-dev\\python.exe', 'pydy_codegen_4_setup.py', 'build_ext', '--inplace']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
Cell In[99], [line 46](vscode-notebook-cell:?execution_count=99&line=46)
[44](vscode-notebook-cell:?execution_count=99&line=44) print('sys initial conditions', sys.initial_conditions)
[45](vscode-notebook-cell:?execution_count=99&line=45) sys.times = np.linspace(0., intervall, int(schritte*intervall))
---> [46](vscode-notebook-cell:?execution_count=99&line=46) sys.generate_ode_function(generator='cython', verbose=True)
[47](vscode-notebook-cell:?execution_count=99&line=47) resultat = sys.integrate()
[48](vscode-notebook-cell:?execution_count=99&line=48) print('shape of result', resultat.shape)
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\system.py:481](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/system.py:481), in System.generate_ode_function(self, **kwargs)
[477](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/system.py:477) print("User supplied 'specifieds' kwarg was disregarded.")
[479](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/system.py:479) kwargs.update(self._kwargs_for_gen_ode_func())
--> [481](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/system.py:481) self._evaluate_ode_function = generate_ode_function(
[482](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/system.py:482) *self._args_for_gen_ode_func(),
[483](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/system.py:483) **kwargs)
[485](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/system.py:485) return self.evaluate_ode_function
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\codegen\ode_function_generators.py:917](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:917), in generate_ode_function(*args, **kwargs)
[915](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:915) raise NotImplementedError(msg)
[916](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:916) else:
--> [917](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:917) return g.generate()
[918](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:918) else:
[919](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:919) return g.generate()
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\codegen\ode_function_generators.py:622](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:622), in ODEFunctionGenerator.generate(self)
[620](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:620) self.generate_full_rhs_function()
[621](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:621) elif self.system_type == 'full mass matrix':
--> [622](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:622) self.generate_full_mass_matrix_function()
[623](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:623) elif self.system_type == 'min mass matrix':
[624](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:624) self.generate_min_mass_matrix_function()
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\codegen\ode_function_generators.py:700](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:700), in CythonODEFunctionGenerator.generate_full_mass_matrix_function(self)
[697](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:697) self._set_eval_array(self._cythonize_symbolic_lusolve(outputs,
[698](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:698) self.inputs))
[699](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:699) else:
--> [700](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:700) self._set_eval_array(self._cythonize(outputs, self.inputs))
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\codegen\ode_function_generators.py:654](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:654), in CythonODEFunctionGenerator._cythonize(self, outputs, inputs)
[650](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:650) def _cythonize(self, outputs, inputs):
[651](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:651) g = CythonMatrixGenerator(inputs, outputs,
[652](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:652) prefix=self._options['prefix'],
[653](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:653) cse=self._options['cse'])
--> [654](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:654) return g.compile(tmp_dir=self._options['tmp_dir'],
[655](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/ode_function_generators.py:655) verbose=self._options['verbose'])
File [c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\pydy\codegen\cython_code.py:227](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:227), in CythonMatrixGenerator.compile(self, tmp_dir, verbose)
[225](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:225) cython_module = importlib.import_module(self.prefix)
[226](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:226) except:
--> [227](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:227) raise Exception('Failed to compile and import Cython module.')
[228](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:228) finally:
[229](file:///C:/Users/Peter/anaconda3/envs/sympy-dev/Lib/site-packages/pydy/codegen/cython_code.py:229) sys.path.remove(codedir)
Exception: Failed to compile and import Cython module.
This has been solved, thanks to all who helped!
I am trying to simulate the jumping lamp as described in the article Spacetime Constraints by Andrew Witkin and Michael Kass. I do it in 2D for simplicity, and I run it in the sympy-dev environment given to me by @tjstienstra (same environment I use for all my opty simulations). I get the error below. I got it earlier, too - but then there was an issue with the environment. NB: Just as earlier, if I run it again, the error : ModuleNotFoundError: No module named 'ufuncifymatrix0' changes to ModuleNotFoundError: No module named 'ufuncifymatrix1' Any help is greatly appreciated!