Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/giaf/hpipm
Browse files Browse the repository at this point in the history
  • Loading branch information
giaf committed Jul 4, 2019
2 parents e66d0de + 4ed6cd7 commit 9df7b16
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,42 @@ It provides efficient implementations of dense and structure-exploiting algorith

--------------------------------------------------

Getting Started:
## Getting Started:
The best way to get started with HPIPM is to check out the examples in `/hpipm/examples/`.
HPIPM can be directly used from `C`, but there are also interfaces to Python and Matlab.
Depending on which level you want to use HPIPM, check out the following section below.
The QP notation used in HPIPM can be found in the `doc` folder.

The best way to get started with HPIPM is to check out the examples in /hpipm/examples/c/ and /hpipm/examples/python/. In order to run the C example, follow the steps below:

1) clone BLASFEO on your machine: 'git clone https://github.com/giaf/blasfeo.git'
2) from the BLASFEO root folder, run 'make static_library & sudo make install_static'
3) from the HPIPM root folder, run 'make static_library & make examples'
### C
In order to run the C examples in `/hpipm/examples/C/` follow the steps below:
1) clone BLASFEO on your machine: `git clone https://github.com/giaf/blasfeo.git`
2) from the BLASFEO root folder, run `make static_library & sudo make install_static`
3) from the HPIPM root folder, run `make static_library & make examples`
4) cd to /hpipm/examples/c/ and run getting_started.out to solve a simple OCP-structured QP.

If you would like to try out the Python interface, you will need to proceed as follows:
1) clone BLASFEO on your machine: 'git clone https://github.com/giaf/blasfeo.git'
2) from the BLASFEO root folder, run 'make shared_library & sudo make install_shared'
3) from the HPIPM root folder, run 'make shared_library & sudo make install_shared'
4) make sure that the location of the installed shared libraries is known to the system by running 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/blasfeo/lib:/opt/hpipm/lib'. If you would like
### Python
If you would like to try out the Python interface, check out the examples in `/hpipm/examples/python/` after going through the following steps:
1) clone BLASFEO on your machine: `git clone https://github.com/giaf/blasfeo.git`
2) from the BLASFEO root folder, run `make shared_library -j4 & sudo make install_shared`
3) from the HPIPM root folder, run `make shared_library -j4 & sudo make install_shared`
4) make sure that the location of the installed shared libraries is known to the system by running `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/blasfeo/lib:/opt/hpipm/lib`. If you would like
to avoid running this command whenever opening a new shell. You can add the commands above to your .bashrc.
5) cd to /hpipm/interfaces/python/hpipm_python and run 'pip3 install .'
6) cd to /hpipm/examples/python and run 'python3 getting_started.py' to solve a simple OCP-structured QP.
5) cd to /hpipm/interfaces/python/hpipm_python and run `pip3 install .`
6) cd to /hpipm/examples/python and run `python3 getting_started.py` to solve a simple OCP-structured QP.


### MATLAB
Since the HPIPM MATLAB interface is based on the HPIPM Python interface, please first follow the steps in the previous paragraph, "Python".
In order to be able to run HPIPM from Matlab the following steps are additionally required:
1) Make sure that the location of the shared libraries `libblasfeo.so` and `libhpipm.so` is known to the system, see step 4) for Python.
2) Check the paths are defined in the terminal using: `echo $LD_LIBRARY_PATH`
3) Start Matlab from a terminal in which the `LD_LIBRARY_PATH` is defined correctly
4) Make sure that hpipm_python has been installed for the Python version used by MATLAB.
You can check which version is used by running the Matlab command `py.sys.path`.
Use the Matlab command `pyversion <path_to_the_python_interpreter>` to change the Python interpreter used by Matlab.
5) Add `hpipm/interfaces/matlab/hpipm_matlab` to your MATLAB path.
6) Get started using HPIPM from Matlab by looking at the examples in `/hpipm/examples/matlab/`.


--------------------------------------------------

Expand Down
4 changes: 1 addition & 3 deletions examples/matlab/getting_started.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% pyversion /usr/bin/python3
% py.sys.path

clear all
clearvars
close all
clc

Expand Down Expand Up @@ -44,8 +44,6 @@

Jx = [1, 0; 0, 1];
x0 = [1; 1];
Jsx = [1, 0; 0, 1];
Zl = [1e5, 0; 0, 1e5];
Zu = [1e5, 0; 0, 1e5];
zl = [1e5; 1e5];
zu = [1e5; 1e5];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,19 @@ def __init__(self, dim):


def set(self, field, value, idx=None):
# cast to np array
if type(value) is not np.ndarray:
if type(value) is int:
if (type(value) is int) or (type(value) is float):
value_ = value
value = np.array((1,))
value[0] = value_

# reshape np arrays with empty shape, that occur when using hpipm_matlab
if type(value) is np.ndarray and value.shape == ():
value_ = value
value = np.array((1,))
value[0] = value_

# non-native setters (not implemented as C APIs)
setter_map = {
"Jx" : self.set_Jx,
Expand Down

0 comments on commit 9df7b16

Please sign in to comment.