csu-hmc / opty

A library for using direct collocation in the optimization of dynamic systems.
http://opty.readthedocs.io
Other
86 stars 20 forks source link

Strange error #138

Closed Peter230655 closed 3 months ago

Peter230655 commented 3 months ago

When I ran my opty simulation, I go the error below.

I use Visual Studio to run my opty simulations As this error looks similar to an error I got a long time ago, before all the libraries were installed properly I proceeded as follows: 1. I took a simulation, which runs without any ptoblems (actually it eas skatebpard-timo) 2. I renamed it 3. One by one, I deleted the 'old' code (from skateboard_timo) and inserted the code from my program showing this error (I did all this because this eror looked so similar to this old error. I do not understand how the kernels interact with the programs, are they attached to each simulation? I thought that my simulation had maybe 'destroyed' the kernel 'attached' to the simulation, this was the simulation where I had problems with _create_objectivefunction, raised in an issue now closed)

In any case, the error persisted.

one more observation: This is the last line of the error message:

_ModuleNotFoundError: No module named 'ufuncifymatrix0'_

If I run the code again, it says matrix1_ then matrix2_ and so on.

Any help is greatly appreciated!

NB: Github will not allow me to attach my program, so I sent it to Jason and Timo by email

ModuleNotFoundError Traceback (most recent call last) Cell In[6], line 9 7 par_map[b] = inkrement * i 8 b_parameter.append(par_map[b]) ----> 9 prob = Problem(obj, obj_grad, EOM, state_symbols, num_nodes, interval_value, 10 known_parameter_map=par_map, 11 instance_constraints=instance_constraints, 12 bounds=bounds, 13 integration_method=methode) 16 prob.add_option('max_iter', 3000) # default is 3000 17 # Find the optimal solution.

File c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\opty\direct_collocation.py:53, in _DocInherit.get_with_inst..f(*args, kwargs) 51 @wraps(self.mthd, assigned=('name', 'module')) 52 def f(*args, *kwargs): ---> 53 return self.mthd(obj, args, kwargs)

File c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\opty\direct_collocation.py:119, in Problem.init(self, obj, obj_grad, *args, **kwargs) 117 self.obj = obj 118 self.obj_grad = obj_grad --> 119 self.con = self.collocator.generate_constraint_function() 120 logging.info('Constraint function generated.') 121 self.con_jac = self.collocator.generate_jacobian_function()

File c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\opty\direct_collocation.py:1463, in ConstraintCollocator.generate_constraint_function(self) 1460 """Returns a function which evaluates the constraints given the 1461 array of free optimization variables.""" 1462 logging.info('Generating constraint function.') -> 1463 self._gen_multi_arg_con_func() 1464 return self._wrap_constraint_funcs(self._multi_arg_con_func, 'con')

File c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\opty\direct_collocation.py:930, in ConstraintCollocator._gen_multi_arg_con_func(self) 927 adjacent_stop = None 929 logging.info('Compiling the constraint function.') --> 930 f = ufuncify_matrix(args, self.discrete_eom, 931 const=constant_syms + (h_sym,), 932 tmp_dir=self.tmp_dir, parallel=self.parallel) 934 def constraints(state_values, specified_values, constant_values, 935 interval_value): 936 """Returns a vector of constraint values given all of the 937 unknowns in the equations of motion over the 2, ..., N time 938 steps. (...) 957 958 """

File c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\opty\utils.py:476, in ufuncify_matrix(args, expr, const, tmp_dir, parallel) 473 cmd = [sys.executable, d['file_prefix'] + '_setup.py', 'build_ext', 474 '--inplace'] 475 subprocess.call(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) --> 476 cython_module = importlib.import_module(d['file_prefix']) 477 finally: 478 module_counter += 1

File c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\importlib__init__.py:126, in import_module(name, package) 124 break 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level)

File :1206, in _gcd_import(name, package, level)

File :1178, in _find_andload(name, import)

File :1142, in _find_and_loadunlocked(name, import)

ModuleNotFoundError: No module named 'ufuncify_matrix_0'

tjstienstra commented 3 months ago

I fully agree that this is a strange error indeed. I just debugged your program and found out that the problem is in the string representation of some of your symbols:

l, mb, ms, iZZb, iZZs = sm.symbols('l m_b m_s i_{ZZb}, i_{ZZs}')

The latter results in the following c code that of course crashes:

                 double i_{ZZb},
                 double i_{ZZs},

The easy fix in your case is to use:

l, mb, ms, iZZb, iZZs = sm.symbols('l m_b m_s i_ZZb, i_ZZs')
Peter230655 commented 3 months ago

Thank you VERY MUCH!! Just unbelievable the things you know!!