csu-hmc / opty

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

Problems with opty with windows #207

Closed Peter230655 closed 1 day ago

Peter230655 commented 4 weeks ago

Sometimes, when I run a opyt simulation I get the error listed below. For examply with plot_one_legged_time_trial.py I get this error. (Note: many opry simulations run without problems!)

So, I followed the instructions given under the heading Failed Compilation.

problem = Problem(
    obj,
    gradient,
    eom,
    state_vars,
    num_nodes,
    h,
    known_parameter_map=par_map,
    instance_constraints=instance_constraints,
    time_symbol=t,
    bounds=bounds,
    tmp_dir= 'opty_source',
)

It created the directory opty_source

I followed the instructions, using Anaconda Prompt in my environment which I always use for opt, but got this error:

image

Thankful for any help!

{
    "name": "ImportError",
    "message": "Unable to import the compiled Cython module ufuncify_matrix_0, compilation likely failed. STDERR output from compilation:
c:\\Users\\Peter\\anaconda3\\envs\\opty-dev\\Lib\\site-packages\\Cython\\Compiler\\Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: c:\\Users\\Peter\\Candidates_for_PyDy\\opty_source\\ufuncify_matrix_0.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
error: command 'C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.38.33130\\\\bin\\\\HostX86\\\\x64\\\\cl.exe' failed with exit code 2
",
    "stack": "---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File c:\\users\\peter\\github_repos\\opty\\opty\\utils.py:739, in ufuncify_matrix(args, expr, const, tmp_dir, parallel, show_compile_output)
    738 try:
--> 739     cython_module = importlib.import_module(d['file_prefix'])
    740 except ImportError as error:

File c:\\Users\\Peter\\anaconda3\\envs\\opty-dev\\Lib\\importlib\\__init__.py:90, in import_module(name, package)
     89         level += 1
---> 90 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1387, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1360, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:1324, in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'ufuncify_matrix_0'

The above exception was the direct cause of the following exception:

ImportError                               Traceback (most recent call last)
File c:\\Users\\Peter\\Candidates_for_PyDy\\pedaller-braking-with-opty.py:4
      1 # %%
      2 # Instantiate the Optimal Control Problem
      3 # ---------------------------------------
----> 4 problem = Problem(
      5     obj,
      6     gradient,
      7     eom,
      8     state_vars,
      9     num_nodes,
     10     h,
     11     known_parameter_map=par_map,
     12     instance_constraints=instance_constraints,
     13     time_symbol=t,
     14     bounds=bounds,
     15     tmp_dir= 'opty_source',
     16 )
     17 problem.add_option('nlp_scaling_method', 'gradient-based')
     18 problem.add_option('max_iter', 1000)

File c:\\users\\peter\\github_repos\\opty\\opty\\direct_collocation.py:53, in _DocInherit.get_with_inst.<locals>.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\\github_repos\\opty\\opty\\direct_collocation.py:161, in Problem.__init__(self, obj, obj_grad, equations_of_motion, state_symbols, num_collocation_nodes, node_time_interval, known_parameter_map, known_trajectory_map, instance_constraints, time_symbol, tmp_dir, integration_method, parallel, bounds, show_compile_output)
    159 self.obj = obj
    160 self.obj_grad = obj_grad
--> 161 self.con = self.collocator.generate_constraint_function()
    162 logging.info('Constraint function generated.')
    163 self.con_jac = self.collocator.generate_jacobian_function()

File c:\\users\\peter\\github_repos\\opty\\opty\\direct_collocation.py:1593, in ConstraintCollocator.generate_constraint_function(self)
   1590 \"\"\"Returns a function which evaluates the constraints given the
   1591 array of free optimization variables.\"\"\"
   1592 logging.info('Generating constraint function.')
-> 1593 self._gen_multi_arg_con_func()
   1594 return self._wrap_constraint_funcs(self._multi_arg_con_func, 'con')

File c:\\users\\peter\\github_repos\\opty\\opty\\direct_collocation.py:1042, in ConstraintCollocator._gen_multi_arg_con_func(self)
   1039     adjacent_stop = None
   1041 logging.info('Compiling the constraint function.')
-> 1042 f = ufuncify_matrix(args, self.discrete_eom,
   1043                     const=constant_syms + (h_sym,),
   1044                     tmp_dir=self.tmp_dir, parallel=self.parallel,
   1045                     show_compile_output=self.show_compile_output)
   1047 def constraints(state_values, specified_values, constant_values,
   1048                 interval_value):
   1049     \"\"\"Returns a vector of constraint values given all of the
   1050     unknowns in the equations of motion over the 2, ..., N time
   1051     steps.
   (...)
   1070 
   1071     \"\"\"

File c:\\users\\peter\\github_repos\\opty\\opty\\utils.py:744, in ufuncify_matrix(args, expr, const, tmp_dir, parallel, show_compile_output)
    740     except ImportError as error:
    741         msg = ('Unable to import the compiled Cython module {}, '
    742                'compilation likely failed. STDERR output from '
    743                'compilation:\
{}')
--> 744         raise ImportError(msg.format(d['file_prefix'], stderr)) from error
    745 finally:
    746     module_counter += 1

ImportError: Unable to import the compiled Cython module ufuncify_matrix_0, compilation likely failed. STDERR output from compilation:
c:\\Users\\Peter\\anaconda3\\envs\\opty-dev\\Lib\\site-packages\\Cython\\Compiler\\Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: c:\\Users\\Peter\\Candidates_for_PyDy\\opty_source\\ufuncify_matrix_0.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
error: command 'C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\VC\\\\Tools\\\\MSVC\\\\14.38.33130\\\\bin\\\\HostX86\\\\x64\\\\cl.exe' failed with exit code 2
"
}
moorepants commented 3 weeks ago

I followed the instructions, using Anaconda Prompt in my environment which I always use for opt, but got this error:

The file doesn't exist in that directory.

Peter230655 commented 3 weeks ago

I followed the instructions, using Anaconda Prompt in my environment which I always use for opt, but got this error:

The file doesn't exist in that directory.

What would I have to do? Thanks!

moorepants commented 3 weeks ago

You have to execute the command in the directory with the file generated by opty.

Peter230655 commented 3 weeks ago

You have to execute the command in the directory with the file generated by opty.

I thought, this is what I did? with the Anaconda Prompt, I navigated to this directory? opty_source is the directory created by opty. image

moorepants commented 1 day ago

This is a failed compilation and no information provided showing it isn't a user error, so closing.