Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of the python interface #159

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

sandmaennchen
Copy link
Contributor

  • add print_stats() which prints a summary of the IP iterations
  • add getter for lagrange multiplier to OCP QP solution
  • consistent return type in getter of OCP QP solution: return a list whenever idx_end is given
  • fix dimension of feedback gains
  • cleanup python examples

Comment on lines 93 to 94
'n_row': __hpipm.d_ocp_qp_dim_get_nx,
'n_col': __hpipm.d_ocp_qp_dim_get_nu,
Copy link
Owner

@giaf giaf Feb 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was correct at it was before, K is the state feedback matrix of size nu times nx.
It is probably a bit confusing, but n_row is the number of rows, not the length of each row.
Consistently with that, the (column) vectors lr, p and k have n_row but not n_col.

Copy link
Owner

@giaf giaf Feb 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you found numerically from the example that it was wrong as it was before, it may be that the issue is this: HPIPM writes back the result in column-major, but numpy matrices are row-major by default.
If this is the case, either the feedback matrix is saved in a temporary matrix and transposed into the actual one, or the zeros numpy matrix is set to column-major before getting the data from C, e.g. like in https://github.com/giaf/hpipm/blob/master/interfaces/python/hpipm_python/hpipm_python/wrapper/hpipm_ocp_qp.py#L75 (note that here we did for setters, but it may also make the job for the getters).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column- vs. row-major was indeed the problem! thanks 👍

@giaf
Copy link
Owner

giaf commented Mar 26, 2024

@sandmaennchen trying to compile the python interface, I get the error

    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-4sianxjm/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-4sianxjm/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-4sianxjm/pip-egg-info
         cwd: /tmp/pip-req-build-4sianxjm/
    Complete output (15 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-4sianxjm/setup.py", line 38, in <module>
        import hpipm_python
      File "/tmp/pip-req-build-4sianxjm/hpipm_python/__init__.py", line 36, in <module>
        from .common  import *
      File "/tmp/pip-req-build-4sianxjm/hpipm_python/common.py", line 37, in <module>
        from .wrapper.hpipm_solver import *
      File "/tmp/pip-req-build-4sianxjm/hpipm_python/wrapper/__init__.py", line 41, in <module>
        from .hpipm_ocp_qp_sol import *
      File "/tmp/pip-req-build-4sianxjm/hpipm_python/wrapper/hpipm_ocp_qp_sol.py", line 41, in <module>
        class hpipm_ocp_qp_sol:
      File "/tmp/pip-req-build-4sianxjm/hpipm_python/wrapper/hpipm_ocp_qp_sol.py", line 106, in hpipm_ocp_qp_sol
        def get(self, field: str, idx_start: int, idx_end: Optional[int] = None) -> Union[np.ndarray, list[np.ndarray]]:
    TypeError: 'type' object is not subscriptable
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I have python 3.8. It seems to be unhappy of the Union stuff, removing that the error is gone. Any hint?

@sandmaennchen
Copy link
Contributor Author

Hi @giaf, type hints should now be backward compatible with python 3.8!
Will look into your other comments soon, sorry for the late reply 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants