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

docstrings changed for solve to match opty #301

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

Conversation

Peter230655
Copy link
Contributor

Added a function solve to direct_collocation as suggested by JM above to get docstrings which better match opty.
In my tests in ran fine.

  1. I do not know how the check the visual appearance of what I did, so I do not know, how it will look in the opty documentation
  2. It seems to me, that the output of info['g'] has shape (n*(N-1) + o, ) not (n*N + o, ). This is only based on numerical trials, no understanding behind it.

@moorepants
Copy link
Member

The docstrings need to follow the numpydoc format, see here: https://numpydoc.readthedocs.io/en/latest/format.html

@moorepants
Copy link
Member

I would recommend copying the cyipopt docstring and then edit that so that the formatting and information match. We don't really want to remove any info that is in the cyipopt docstring, but just change the parts that are needed for opty:

https://github.com/mechmotum/cyipopt/blob/master/cyipopt/cython/ipopt_wrapper.pyx#L636

@Peter230655
Copy link
Contributor Author

Peter230655 commented Jan 19, 2025

I did copy - but from the part of the opty documentation instead of from the code directly. :-(
I changed it.
Question: is my point 2. above, concerning the shape of info['g'] correct? My numerical trials seem to say so.

@moorepants
Copy link
Member

It doesn't look like you copied this: https://github.com/mechmotum/cyipopt/blob/master/cyipopt/cython/ipopt_wrapper.pyx#L636

You are also missing the option arguments to solve.

@Peter230655
Copy link
Contributor Author

Peter230655 commented Jan 19, 2025

I did copy it. I did not push it, yet, because I am unsure about my point 2 above.
Should I just push it? If my assumption about the shape of info['g'] is wrong, I can change it later.

@Peter230655
Copy link
Contributor Author

Peter230655 commented Jan 20, 2025

Now I copied the docstring directly from the cyipopt code, and change the parts to make the opty docs consistent.
Based on some tests, I assumed the shape of info['g'] to be (n*(N-1) + o). Should this be wrong, I can easily correct it.


"""

return super().solve(free)
Copy link
Member

@moorepants moorepants Jan 20, 2025

Choose a reason for hiding this comment

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

This line is not correct because it will not handle the optional keyword arguments.

@@ -197,6 +197,54 @@ def __init__(self, obj, obj_grad, equations_of_motion, state_symbols,

self.obj_value = []

# this is added only to correct the docstring, which is a bit different with
# opty compared to cyipopt.
def solve(self, free):
Copy link
Member

@moorepants moorepants Jan 20, 2025

Choose a reason for hiding this comment

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

This signature does not match cyipopt's.

@@ -197,6 +197,54 @@ def __init__(self, obj, obj_grad, equations_of_motion, state_symbols,

self.obj_value = []

# this is added only to correct the docstring, which is a bit different with
# opty compared to cyipopt.
Copy link
Member

Choose a reason for hiding this comment

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

These two lines are not need. If is common to overwrite methods in sub classes for this reason and it needs no explanation.


"""

return super().solve(free, lagrange=[], zl=[], zu=[])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return super().solve(free, lagrange=[], zl=[], zu=[])
return super().solve(free, lagrange=lagrange, zl=zl, zu=zu)

Needs that changed, otherwise the arguments that the user passes in will never reach this method.

Copy link
Contributor Author

@Peter230655 Peter230655 Jan 20, 2025

Choose a reason for hiding this comment

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

Shows my weakness in python - after so many years! :-(
Corrected as per suggestions.

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.

2 participants