Giter Site home page Giter Site logo

csu-hmc / opty Goto Github PK

View Code? Open in Web Editor NEW
91.0 14.0 20.0 770 KB

A library for using direct collocation in the optimization of dynamic systems.

Home Page: http://opty.readthedocs.io

License: Other

Python 89.87% TeX 10.13%
python optimization collocation optimal optimal-control parameter-estimation

opty's Introduction

Introduction

PyPi https://pepy.tech/badge/opty
Anaconda
Documentation https://readthedocs.org/projects/opty/badge/?version=stable
JOSS Paper
Zenodo Archive
Continous Integration

opty utilizes symbolic descriptions of differential algebraic equations expressed with SymPy to form the constraints needed to solve optimal control and parameter identification problems using the direct collocation method and non-linear programming (NLP). In general, if one can express the continuous first order differential algebraic equations of the system as symbolic expressions opty will automatically generate a function to efficiently evaluate the dynamical constraints and a function that evaluates the sparse Jacobian of the constraints, which have been optimized for speed and memory consumption. The translation of the dynamical system description to the NLP form, primarily the formation of the constraints and the Jacobian of the constraints, manually is a time consuming and error prone process. opty eliminates both of those issues.

Features

  • Both implicit and explicit forms of the first order ordinary differential equations and differential algebraic equations are supported, i.e. there is no need to solve for the derivatives of the dependent variables.
  • Backward Euler or Midpoint integration methods.
  • Supports both trajectory optimization and parameter identification, independently or simultaneously.
  • Solve fixed duration or variable duration problems.
  • Easy specification of bounds on free variables.
  • Easily specify additional "instance" constraints.
  • Efficient numerical execution of large equations of motion.
  • Automatic parallel execution using openmp if installed.
  • Built with support of sympy.physics.mechanics and PyDy in mind.

Installation

The required dependencies are as follows:

  • cyipopt >= 1.1.0 [with ipopt >= 3.11 (Linux & OSX), >= 3.13 (Windows)]
  • cython >= 0.29.19 [with a C compiler]
  • numpy >= 1.19.0
  • python 3.8-3.12
  • scipy >= 1.5.0
  • sympy >= 1.6.0

The optional dependencies are as follows:

  • matplotlib >= 3.2.0
  • openmp

To run all of the examples the following additional dependencies may be needed:

  • pandas
  • pydy >= 0.5.0
  • pytables
  • yeadon

The easiest way to install opty is to first install Anaconda (or Miniconda or Miniforge) and use the conda package manager to install opty and any desired optional dependencies from the Conda Forge channel, e.g. opty:

$ conda install --channel conda-forge opty

and the optional dependencies:

$ conda install --channel conda-forge matplotlib openmp pandas pydy pytables yeadon

Opty can be installed with pip, but this will require installing and compiling cyipopt if it is not already installed:

$ pip install opty

See the cyipopt documentation for information on installing that package.

Custom Ipopt

If you want a custom installation of any of the dependencies, e.g. Ipopt, you must first install Ipopt along with it's headers. For example, on Debian based systems you can use the package manager:

$ sudo apt-get install coinor-libipopt1v5 coinor-libipopt-dev

or prebuilt binaries can be downloaded from https://www.coin-or.org/download/binary/Ipopt/.

For customized installation (usually desired for performance) follow the instructions on the Ipopt documentation to compile the library. If you install to a location other than /usr/local on Unix systems you will likely have to set the LD_LIBRARY_PATH so that you can link to Ipopt when installing cyipopt.

Once Ipopt is installed and accessible, install conda then create an environment:

$ conda create -n opty-custom -c conda-forge cython numpy pip scipy sympy
$ source activate opty-custom
(opty-custom)$ pip install cyipopt  # this will compile cyipopt against the available ipopt
(opty-custom)$ pip install opty

If you want to develop opty, create a conda environment with all of the dependencies installed:

$ conda config --add channels conda-forge
$ conda create -n opty-dev python sympy numpy scipy cython ipopt cyipopt matplotlib pytables pydy pandas pytest sphinx sphinx-gallery numpydoc
$ source activate opty-dev

Next download the opty source files and install with:

(opty-dev)$ cd /path/to/opty
(opty-dev)$ python setup.py develop

Usage

There are several examples available in the examples and examples-gallery directories. The optimal torque to swing up a pendulum with minimal energy can be run with:

$ python examples-gallery/plot_pendulum_swing_up_fixed_duration.py

Failed Compilation

If compilation fails it may be helpful to manually compile the generated Cython extension. To do so, provide a destination path to the tmp_dir kwarg when you instantiate Problem(), e.g.:

p = Problem(..., tmp_dir='opty_source')

You can then compile the files manually by navigating into the opty_source directory and running:

$ cd /path/to/opty_source
$ python ufuncify_matrix_X_setup.py build_ext --inplace

The highest integer value of X will be the most recently generated set of source files.

Build Documentation

Build the HTML documentation with:

(opty-dev)$ cd /path/to/opty/docs
(opty-dev)$ make html

and open the result with your web browser, for example:

$ firefox _build/html/index.html

Funding

The work was partially funded by the State of Ohio Third Frontier Commission through the Wright Center for Sensor Systems Engineering (WCSSE), by the USA National Science Foundation under Grant No. 1344954, and by National Center of Simulation in Rehabilitation Research 2014 Visiting Scholarship at Stanford University, and the CZI grant CZIF2021-006198 and grant DOI https://doi.org/10.37921/240361looxoj from the Chan Zuckerberg Initiative Foundation (funder DOI 10.13039/100014989).

opty's People

Contributors

brocksam avatar moorepants avatar peter230655 avatar tjstienstra avatar tvdbogert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opty's Issues

Implement h as a free variable

The time between nodes is currently a fixed value. We can solve variable duration problems if I enable it as a free variable. This may be necessary for getting the ackermann example to work.

Invalid C variables are possible

I used i as a state variable and opty creates ii and in in the C code. in is an invalid variable name in C, so the compilation fails. I think SymPy deals with this properly now with the CCode printers, but maybe this one slipped through.

(pendulum-robot) moorepants@garuda:cython_files$ python ufuncify_matrix_0_setup.py build_ext --inplace
Compiling ufuncify_matrix_0.pyx because it changed.
[1/1] Cythonizing ufuncify_matrix_0.pyx

Error compiling Cython file:
------------------------------------------------------------
...
    void eval_matrix(double matrix[3], double thetai,
                 double omegai,
                 double ii,
                 double thetan,
                 double omegan,
                 double in,
                       ^
------------------------------------------------------------

ufuncify_matrix_0.pyx:11:24: Expected ')', found 'in'
Traceback (most recent call last):
  File "ufuncify_matrix_0_setup.py", line 13, in <module>
    ext_modules=cythonize([extension]))
  File "/home/moorepants/miniconda3/envs/pendulum-robot/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 934, in cythonize
    cythonize_one(*args)
  File "/home/moorepants/miniconda3/envs/pendulum-robot/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1056, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: ufuncify_matrix_0.pyx

Add a regularization term to the cost function.

Add a regularization term to the cost function. This can be a small term to ensure that the solution is unique, such as: small_weight*sum(X.^2)/length(X). Where X contains all unknowns. You can also use a large weight to get a convex cost function, solve that optimization problem, and use it as an initial guess for the new problem with smaller weight. This is similar to Tom's homotopy, except you are modify the cost function rather than the model.

Add list of references

From: openjournals/joss-reviews#300 (comment)

A list of key references including a link to the software archive - References are not rendered in the paper.md file - No link to software archive - Other than Betts2010, the other citations appear to be just for dependencies. The paper should include citations to other software for direct colocation, and a comparison of feature sets, etc.

  • finish up the table of comparisons

Add process noise

We need to be able to inject both process and measurement noise into the simulation and identify from that resulting data.

Add contributing guidelines

From: openjournals/joss-reviews#300 (comment)

Community guidelines - Missing, should include: There should be clear guidelines for third-parties wishing to: Contribute to the software Report issues or problems with the software Seek support Examples

From: openjournals/joss-reviews#300 (comment)

comment: Missing. It would be great to have one. There is a useful instruction on the de facto standard way to add a contribution guideline: https://help.github.com/articles/setting-guidelines-for-repository-contributors/.

Compare all the IPOPT solvers

I'm not sure which of the sparse solvers give best performance. Ideally if any can be parallelized, that would help.

ackermann2010 example fails

The current state of affairs for the ackermann example is shown below.

Some things to try:

  • Create the sequential solutions: standing, walking with some tracking, walking with more tracking, etc. See Ton's code for an example.
  • Add tracking to the cost function (Ton typically tracks both the angles and the GRFs).
  • Ton hasn't tried to solve for joint torque trajectories without tracking, so it may not be possible.
  • Ton has only solve this from random initial guesses when he had an implicit contact model.
  • The Ackermann solution used an initial guess derived from inverse dynamics and getting estimates of the muscle activations from Opensim.
(inverted-pendulum-id)moorepants@moorepants-2170p:ackermann2010(master)$ ipython
Python 2.7.8 |Continuum Analytics, Inc.| (default, Aug 21 2014, 18:22:21) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: run ackermann2010.py 
Forming positions, velocities, accelerations and forces.
Initializing Kane's Method.
Forming Kane's Equations.
Printing ccode.
Computing the symbolic partial derivatives.
Printing ccode.

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

This is Ipopt version 3.11, running with linear solver ma57.

Number of nonzeros in equality constraint Jacobian...:    44618
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:        0

Reallocating memory for MA57: lfact (453385)
Reallocating memory for MA57: lfact (503593)
Total number of variables............................:     1440
                     variables with only lower bounds:        0
                variables with lower and upper bounds:     1440
                     variables with only upper bounds:        0
Total number of equality constraints.................:     1070
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  2.3742185e+07 2.72e+05 5.03e+00   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
WARNING: Problem in step computation; switching to emergency mode.
   1r 2.3742185e+07 2.72e+05 9.99e+02   3.9 0.00e+00  20.0 0.00e+00 0.00e+00R  1
WARNING: Problem in step computation; switching to emergency mode.
Restoration phase is called at point that is almost feasible,
  with constraint violation 0.000000e+00. Abort.
Restoration phase in the restoration phase failed.

Number of Iterations....: 1

                                   (scaled)                 (unscaled)
Objective...............:   2.3742184587421797e+07    2.3742184587421797e+07
Dual infeasibility......:   5.0338983554237284e+00    5.0338983554237284e+00
Constraint violation....:   8.6174364489984910e+03    2.7227023016135045e+05
Complementarity.........:   5.9700000596999996e+02    5.9700000596999996e+02
Overall NLP error.......:   8.6174364489984910e+03    2.7227023016135045e+05


Number of objective function evaluations             = 2
Number of objective gradient evaluations             = 2
Number of equality constraint evaluations            = 2
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 2
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 0
Total CPU secs in IPOPT (w/o function evaluations)   =      2.998
Total CPU secs in NLP function evaluations           =      0.157


Timing Statistics:

OverallAlgorithm....................:      3.155 (sys:      7.384 wall:      3.090)
 PrintProblemStatistics.............:      0.000 (sys:      0.000 wall:      0.000)
 InitializeIterates.................:      0.332 (sys:      0.560 wall:      0.263)
 UpdateHessian......................:      0.000 (sys:      0.000 wall:      0.000)
 OutputIteration....................:      0.001 (sys:      0.000 wall:      0.000)
 UpdateBarrierParameter.............:      1.278 (sys:      2.345 wall:      0.952)
 ComputeSearchDirection.............:      0.000 (sys:      0.000 wall:      0.000)
 ComputeAcceptableTrialPoint........:      1.507 (sys:      4.392 wall:      1.835)
 AcceptTrialPoint...................:      0.000 (sys:      0.000 wall:      0.000)
 CheckConvergence...................:      0.036 (sys:      0.088 wall:      0.039)
PDSystemSolverTotal.................:      1.278 (sys:      2.345 wall:      0.952)
 PDSystemSolverSolveOnce............:      1.277 (sys:      2.345 wall:      0.952)
 ComputeResiduals...................:      0.000 (sys:      0.000 wall:      0.000)
 StdAugSystemSolverMultiSolve.......:      2.945 (sys:      6.892 wall:      2.859)
 LinearSystemScaling................:      0.000 (sys:      0.000 wall:      0.000)
 LinearSystemSymbolicFactorization..:      0.009 (sys:      0.000 wall:      0.002)
 LinearSystemFactorization..........:      2.875 (sys:      6.891 wall:      2.840)
 LinearSystemBackSolve..............:      0.000 (sys:      0.000 wall:      0.000)
 LinearSystemStructureConverter.....:      0.000 (sys:      0.000 wall:      0.000)
  LinearSystemStructureConverterInit:      0.000 (sys:      0.000 wall:      0.000)
QualityFunctionSearch...............:      0.000 (sys:      0.000 wall:      0.000)
TryCorrector........................:      0.000 (sys:      0.000 wall:      0.000)
Task1...............................:      0.000 (sys:      0.000 wall:      0.000)
Task2...............................:      0.000 (sys:      0.000 wall:      0.000)
Task3...............................:      0.000 (sys:      0.000 wall:      0.000)
Task4...............................:      0.000 (sys:      0.000 wall:      0.000)
Task5...............................:      0.000 (sys:      0.000 wall:      0.000)
Function Evaluations................:      0.157 (sys:      0.384 wall:      0.155)
 Objective function.................:      0.001 (sys:      0.000 wall:      0.000)
 Objective function gradient........:      0.004 (sys:      0.000 wall:      0.001)
 Equality constraints...............:      0.067 (sys:      0.192 wall:      0.075)
 Inequality constraints.............:      0.000 (sys:      0.000 wall:      0.000)
 Equality constraint Jacobian.......:      0.084 (sys:      0.192 wall:      0.078)
 Inequality constraint Jacobian.....:      0.000 (sys:      0.000 wall:      0.000)
 Lagrangian Hessian.................:      0.000 (sys:      0.000 wall:      0.000)

EXIT: Restoration Failed!

In [2]: pro
%profile  prob      property  

In [2]: prob.con(initial_guess)
Out[2]: 
array([ 914.98161943,  720.16048423, -974.78036008, ...,   -9.75610511,
         -3.85324192,   -8.17724079])

In [3]: prob.con_jac(initial_guess)
Out[3]: array([ 118.,    0.,    0., ...,    1.,    1.,    1.])

In [4]: prob.obj(initial_guess)
Out[4]: 150127264.38578781

In [5]: prob.obj_grad(initial_guess)
Out[5]: 
array([  0.        ,   0.        ,   0.        , ..., -10.56153419,
        -1.25221308,   4.8188792 ])

In [6]: %timeit prob.con_jac(initial_guess)
10 loops, best of 3: 21.8 ms per loop

park2004 example is erroring with latest versions of dependencies

moorepants@hanuman:park2004(master)$ python park2004.py 
GLib-GIO-Message: Using the 'memory' GSettings backend.  Your settings will not be saved or shared with other applications.
/home/moorepants/miniconda/lib/python2.7/site-packages/pydy/codegen/code.py:25: PyDyDeprecationWarning: This module, 'pydy.codgen.code', is deprecated. The function 'generate_ode_function' can be found in the 'pydy.codegen.ode_function_generator' module. 'CythonGenerator' has been removed, use 'pydy.codegen.cython_code.CythonMatrixGenerator' instead.
  PyDyDeprecationWarning)
Generating equations of motion.
Generating right hand side function.
/home/moorepants/miniconda/lib/python2.7/site-packages/pydy/codegen/code.py:71: PyDyDeprecationWarning: This function is deprecated and will be removed in PyDy 0.4.0. Use the the new 'generate_ode_function' in 'pydy.codegen.ode_function_generator'
  PyDyDeprecationWarning)
Integrating equations of motion.
/home/moorepants/miniconda/lib/python2.7/site-packages/pydy/codegen/ode_function_generators.py:398: PyDyDeprecationWarning: The old style args, i.e. {'constants': , 'specified'}, for the generated function will be removed in PyDy 0.4.0.
  PyDyDeprecationWarning)
/home/moorepants/miniconda/lib/python2.7/site-packages/pydy/codegen/ode_function_generators.py:420: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  self._constants_values[i] = p[c]
^C^CTraceback (most recent call last):
  File "park2004.py", line 39, in <module>
    x = odeint(rhs, x0, time, args=(args,))
  File "/home/moorepants/miniconda/lib/python2.7/site-packages/scipy/integrate/odepack.py", line 215, in odeint
    ixpr, mxstep, mxhnil, mxordn, mxords)
  File "/home/moorepants/miniconda/lib/python2.7/site-packages/pydy/codegen/ode_function_generators.py", line 543, in rhs
    args = self._parse_all_args(*args)
  File "/home/moorepants/miniconda/lib/python2.7/site-packages/pydy/codegen/ode_function_generators.py", line 481, in _parse_all_args
    args = self._parse_specifieds(*args)
  File "/home/moorepants/miniconda/lib/python2.7/site-packages/pydy/codegen/ode_function_generators.py", line 463, in _parse_specifieds
    self._specifieds_values[:] = r(x, t)
  File "/home/moorepants/src/opty/examples/park2004/model.py", line 558, in controller
    result = interp_func(t)
  File "/home/moorepants/miniconda/lib/python2.7/site-packages/scipy/interpolate/polyint.py", line 79, in __call__
    y = self._evaluate(x)
  File "/home/moorepants/miniconda/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 586, in _evaluate
    y_new = self._call(self, x_new)
  File "/home/moorepants/miniconda/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 557, in _call_linear
    y_new = slope*(x_new - x_lo)[:, None] + y_lo
KeyboardInterrupt

support for SNOPT

This is more of a feature request.

We have a license (and Fortran source) for SNOPT. SNOPT would be a good option to have, because it is a sequential quadratic programming method (IPOPT is interior point). In my experience, SNOPT works better on highly nonlinear problems when a good initial guess is available.

A quick google search reveals three python-snopt interfaces on Github, and one in pyopt.org. Of course we need one that supports sparse matrices.

Figure out why convergence is more difficult with human scaled parameters.

  • See if convergence for the n-pendulum problem is faster if I set the parameters to the original numerical values. I need to determine if it is actually the change in parameter values that affects this or if I've changed something else in my code that affected this.
  • Explore scaling the constraints and objective.
  • Try SNOPT?

Improve the theory explanation in the docs

From: openjournals/joss-reviews#300 (comment)

โ€” [optional] a full theory guide would be very beneficial for introducing the basic concepts of direct colocation. Although this type of information can be found in textbooks / papers (e.g. the Betts paper cited), but it can be very helpful to include it within the software paper, as the software authors typically have their own interpretation of the theory, and the equations can be better matched to the software implementation. For example, both FEBio and Simbody have excellent theory guides, which are arguably one of the main contributions of those works.

Example inverted_pendulum.py linked to the outdated module pydy.codegen.code'

All your examples ran smoothly, but I can't run the inverted_pendulum.py; it gives the following error:

Traceback (most recent call last):
File "pendulum.py", line 48, in
import simulate
File "/media/Data/Python/opty-master/examples/inverted_pendulum/simulate.py", line 10, in
from pydy.codegen.code import generate_ode_function
ModuleNotFoundError: No module named 'pydy.codegen.code'

cyipopt fails to instal lif pkg-config is not installed

This is because if you don't have pkg-config installed, this is returned:

vagrant@vagrant-ubuntu-trusty-64:~/moorepants-cyipopt-beafd15fbfe2$ pkg-config
--libs --cflags ipopt
The program 'pkg-config' can be found in the following packages:
 * pkg-config
    * pkgconf

So the setup.py script doesn't get any output to process. There needs to be some handling of this in setup.py.

8 links failed the controllability test

(inverted-pendulum-id)moorepants@moorepants-2170p:inverted-pendulum-sys-id(master)$ ipython
Python 2.7.8 |Continuum Analytics, Inc.| (default, Aug 21 2014, 18:22:21) 
Type "copyright", "credits" or "license" for more information.

IPython 2.1.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: run pendulum.py -n 8 -d 10.0 -r -s 100.0 -i known
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Running an identification for a 8 link inverted pendulum with a 10.0 second simulation discretized at 100.0 hz.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Generating equations of motion.
Finding the optimal gains.
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/home/moorepants/src/inverted-pendulum-sys-id/pendulum.py in <module>()
   1503                             args.samplerate, args.initialconditions,
   1504                             args.sensornoise, args.plot, args.animate)
-> 1505     identifier.identify()

/home/moorepants/src/inverted-pendulum-sys-id/pendulum.py in identify(self)
   1265         self.compute_discretization()
   1266         self.generate_eoms()
-> 1267         self.find_optimal_gains()
   1268         self.simulate()
   1269         self.generate_constraint_funcs()

/home/moorepants/src/inverted-pendulum-sys-id/pendulum.py in find_optimal_gains(self)
   1073         # Find some optimal gains for stablizing the pendulum on the cart.
   1074         print('Finding the optimal gains.')
-> 1075         self.gains = compute_controller_gains(self.num_links)
   1076 
   1077     def simulate(self):

/home/moorepants/src/inverted-pendulum-sys-id/pendulum.py in compute_controller_gains(num_links)
    127     B = np.dot(invM, F_B)
    128 
--> 129     assert controllable(A, B)
    130 
    131     Q = np.eye(len(states))

AssertionError: 

In [2]: 

Use static equilibria as initial guess

You could also try using a static equilibrium as initial guess: pendulum upright, zero torques, zero gains. This will actually satisfy the dynamics constraints when there is no perturbation applied to the model. NLP solvers usually do better if the initial guess is feasible, i.e. satisfies all constraints. The system is unstable, but collocation does not care! The cost function will be large, because the data has significant amounts of motion in it. If that converges, great. If not there are other options. If you give it zeros as motion data, this static initial guess is already the solution. Then you can add the perturbation, or initially just a fraction of the perturbation and it will probably converge to very large gains. So you need a bound on the gains, or an effort term or regularization term in the cost function to ensure that the optimal gains are < infinity. Then you can add the motion data, or a fraction of the motion data and solve that. There are all sorts of continuation/homotopy approaches that can be designed. I'm pretty sure something will work. I usually script that (example attached) so when it works, it's documented and I can repeat it whenever I want to.

Improve the high level summary

From: openjournals/joss-reviews#300 (comment)

A summary describing the high-level functionality and purpose of the software for a diverse, non-specialist audience โ€” current summary is written in highly technical language, I suggest a lay introduction followed by a more detailed technical description of the software that includes equations to clarify what types of problems are applicable for the software

Set bounds higher on pendulum swing up example

From Ton: You did the pendulum swingup with rather low bounds on the torque, so the solution looks almost like a bang-bang control. That is because the problem gets close to infeasible, doing the swingup in 10 seconds is just possible with this low torque. It is nice to demonstrate the bounds capability, though. Maybe set the bounds higher, so it has more of the minimal-energy character?

The Debian build of IPOPT doesn't seem to work.

On a fresh Ubuntu 14.04,

vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install coinor-libipopt1 coinor-libipopt-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libblacs-mpi-dev libblacs-mpi1 libblas3 libcr0 libgfortran3 libhwloc-dev
  libhwloc-plugins libhwloc5 libibverbs-dev libibverbs1 liblapack3 libltdl7
  libmumps-4.10.0 libmumps-dev libopenmpi-dev libopenmpi1.6 libpci-dev
  libscalapack-mpi-dev libscalapack-mpi1 libtorque2 libxml2-dev
  mpi-default-bin mpi-default-dev ocl-icd-libopencl1 openmpi-bin
  openmpi-common zlib1g-dev
Suggested packages:
  blcr-dkms libhwloc-contrib-plugins scalapack-doc pkg-config opencl-icd
  gfortran openmpi-checkpoint
The following NEW packages will be installed:
  coinor-libipopt-dev coinor-libipopt1 libblacs-mpi-dev libblacs-mpi1 libblas3
  libcr0 libgfortran3 libhwloc-dev libhwloc-plugins libhwloc5 libibverbs-dev
  libibverbs1 liblapack3 libltdl7 libmumps-4.10.0 libmumps-dev libopenmpi-dev
  libopenmpi1.6 libpci-dev libscalapack-mpi-dev libscalapack-mpi1 libtorque2
  libxml2-dev mpi-default-bin mpi-default-dev ocl-icd-libopencl1 openmpi-bin
  openmpi-common zlib1g-dev
apt-get install unzip python-numpy python-matplotlib cython
apt0get install  build-essential pkg-config gfortran libblas3gf libblas-dev liblapack3gf liblapack-dev
wget https://bitbucket.org/moorepants/cyipopt/get/tip.zip
unzip tip
cd moorepants-cyipopt-beafd15fbfe2/
python setup.py install
vagrant@vagrant-ubuntu-trusty-64:~/moorepants-cyipopt-beafd15fbfe2$ cd test/
vagrant@vagrant-ubuntu-trusty-64:~/moorepants-cyipopt-beafd15fbfe2/test$ ls
examplehs071.py  lasso.py
vagrant@vagrant-ubuntu-trusty-64:~/moorepants-cyipopt-beafd15fbfe2/test$ python examplehs071.py 
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/vagrant/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
  warnings.warn(msg, UserWarning)
[vagrant-ubuntu-trusty-64:09574] mca: base: component_find: unable to open /usr/lib/openmpi/lib/openmpi/mca_paffinity_hwloc: perhaps a missing symbol, or compiled for a different version of Open MPI? (ignored)
[vagrant-ubuntu-trusty-64:09574] mca: base: component_find: unable to open /usr/lib/openmpi/lib/openmpi/mca_carto_auto_detect: perhaps a missing symbol, or compiled for a different version of Open MPI? (ignored)
[vagrant-ubuntu-trusty-64:09574] mca: base: component_find: unable to open /usr/lib/openmpi/lib/openmpi/mca_carto_file: perhaps a missing symbol, or compiled for a different version of Open MPI? (ignored)
[vagrant-ubuntu-trusty-64:09574] mca: base: component_find: unable to open /usr/lib/openmpi/lib/openmpi/mca_shmem_mmap: perhaps a missing symbol, or compiled for a different version of Open MPI? (ignored)
[vagrant-ubuntu-trusty-64:09574] mca: base: component_find: unable to open /usr/lib/openmpi/lib/openmpi/mca_shmem_posix: perhaps a missing symbol, or compiled for a different version of Open MPI? (ignored)
[vagrant-ubuntu-trusty-64:09574] mca: base: component_find: unable to open /usr/lib/openmpi/lib/openmpi/mca_shmem_sysv: perhaps a missing symbol, or compiled for a different version of Open MPI? (ignored)
--------------------------------------------------------------------------
It looks like opal_init failed for some reason; your parallel process is
likely to abort.  There are many reasons that a parallel process can
fail during opal_init; some of which are due to configuration or
environment problems.  This failure appears to be an internal failure;
here's some additional information (which may only be relevant to an
Open MPI developer):

  opal_shmem_base_select failed
  --> Returned value -1 instead of OPAL_SUCCESS
--------------------------------------------------------------------------
[vagrant-ubuntu-trusty-64:09574] [[INVALID],INVALID] ORTE_ERROR_LOG: Error in file runtime/orte_init.c at line 79
--------------------------------------------------------------------------
It looks like MPI_INIT failed for some reason; your parallel process is
likely to abort.  There are many reasons that a parallel process can
fail during MPI_INIT; some of which are due to configuration or environment
problems.  This failure appears to be an internal failure; here's some
additional information (which may only be relevant to an Open MPI
developer):

  ompi_mpi_init: orte_init failed
  --> Returned "Error" (-1) instead of "Success" (0)
--------------------------------------------------------------------------
*** An error occurred in MPI_Init
*** on a NULL communicator
*** MPI_ERRORS_ARE_FATAL: your MPI job will now abort
[vagrant-ubuntu-trusty-64:9574] Local abort before MPI_INIT completed successfully; not able to aggregate error messages, and not able to guarantee that all other processes were killed!

Implement midpoint integration

  • Add support for the current and next nodes in addition to the current and previous, which is used for the backward Euler.
  • Add support for ui (current), up (previous), un (next) of the specified values.
  • In the discretize method support these substitutions: x' : (xn - xi) / h, x : (xn + xi) / 2, u : (un + ui) / 2

Dockerfile: cannot find ipopt (cyipopt) 0.1.7

The Dockerfile command RUN cd /home/opty/opty && /home/opty/miniconda/envs/test-environment/bin/python setup.py install causes the following error:

No local packages or working download links found for ipopt>=0.1.7
error: Could not find suitable distribution for Requirement.parse('ipopt>=0.1.7')

Might be smart to do cse before taking the Jacobian

def csejac(A, x):
    r, E = cse(A)
    rr = numbered_symbols('x', start=len(r))
    E = E[0]
    f = {} # e.g. x0 -> x0(x, y)
    d = {} # e.g. D(x1(x, y), x) -> D(g(x, y, z, x0(x, y),...)
    c = {} # e.g. D(x1(x, y), x) -> x2
    s = set(x)
    for v, e in r:
        e1 = e.xreplace(f)
        dep = e1.free_symbols & s
        if not dep:
            continue
        v1 = v(*dep)
        f[v] = v1
        for i in dep:
            D = v1.diff(i)
            d[D] = e1.diff(i).xreplace(d)
            c[rr.next()] = D
    a = E.applyfunc(lambda q: q.xreplace(f))
    j = a.jacobian(x)
    j = j.applyfunc(lambda q: q.xreplace(dict([(v,k) for k, v in c.items()])))
    j = j.applyfunc(lambda q: q.xreplace(dict([(v,k) for k, v in f.items()])))
    return r, dict([(k, d[c[k]]) for k in c]), j

See the sympy email list for more details.

homotopy method and warm start

Huawei Wang has modified the double inverted pendulum notebook to do control identification on actual human data. He finds a different local optimum after each restart with random initial guess. The controller model at this time is simple and far from human, but even with a bad model, the parameter identification should find the unique global optimum.

We want to implement the homotopy method from the Vyasarayani paper. This requires:

  1. An extra term in the implicit dynamics which tracks the data. It would be easy to do in the notebook, but we are wondering if this is general enough that it can be added as an option in the opty toolbox.
  2. Doing a sequence of IPOPT runs while the lambda parameter increases. We have figured out how to warm start IPOPT (in Matlab) with lagrange multipliers from a previous runs and this works well. Ideally this would all be done inside opty.

@moorepants please comment on these feature requests and give some guidance on where and how to do this. Huawei is pretty comfortable with python, we just need some guidance.

Dockerfile leads to HTTPError

I am trying to build a docker image from the provided docker file, and I got a HTTPError: 403 Forbidden http://repo.continuum.io/pkgs/pro/linux-64/ error (related: conda/conda#3925).

The following change allowed the docker image to build much farther:

RUN cd /home/opty && wget http://repo.continuum.io/miniconda/Miniconda-3.4.2-Linux-x86_64.sh -O miniconda.sh

->

RUN cd /home/opty && wget http://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.