-
Notifications
You must be signed in to change notification settings - Fork 21
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
check that initial guesses are within bounds. Fixes #355 #358
base: master
Are you sure you want to change the base?
Conversation
Adjusted as per the suggestions given. |
If I read it correctly, about 10 examples seem to give problems.
Or what would you suggest? |
My suggestion was made above:
|
Good looking error message!
|
Thanks! |
I will go over the examples in the coming days, try to fix them and push them if fixed. |
opty/direct_collocation.py
Outdated
@@ -249,9 +254,58 @@ def solve(self, free, lagrange=[], zl=[], zu=[]): | |||
gives the status of the algorithm as a message | |||
|
|||
""" | |||
|
|||
if respect_bounds == True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if respect_bounds == True: | |
if respect_bounds: |
I proceeded as follows:
|
This test has been running for nearly 2 1/2 hours. |
seems to run too long, will start again. |
it seems that conda cannot resolve the environment on windows with python 3.10.
I don't know why that would be, as it has worked before. |
Peter, since you are on windows can you make this edit to your conda env file and see if it works locally when creating the environment:
|
So I understand correctly:
Thanks! |
You can do either, but I only changed this line |
So to update I proceed as follows?
|
That will work but only if you first remove the existing opty-dev conda environment. |
Sorry, nevermind, if you use "update" then it should be fine. You can also simple add |
This looks easiest for me! Then, when I push, this changed .yml file will also be pushed. Is this o.k.? OIr is this actually what we want to test? |
NO problem! I will use the .yml file in opty, right? |
I built from scratch as follows:
This took about 90 sec. |
Yes, you have to set python = 3.10 to do the same thing in the failing CI build. |
Clear, will do so. Right now I managed once again to mess up everything :-(( |
If you merge master the tests should run correctly again. I fixed it in #363 |
Worked !! :-) |
---------- | ||
free : array-like, shape(n*N + q*N + r + s, ) | ||
Initial guess given to solve. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add a "Raises" section to describe the ValueError. See the numpydoc documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
violating_variables.append(local_ts) | ||
|
||
symbole = self.collocator.state_symbols + \ | ||
self.collocator.unknown_input_trajectories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bit better to do:
a = (longgggggggggggggggggggggg +
longgggggggggggggggggggggggggg)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bit better to do:
a = (longgggggggggggggggggggggg + longgggggggggggggggggggggggggg)
So, parenthesis are always preferred over \ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to pep 8 it is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I would have thought the other way around, I will remember in future.
opty/direct_collocation.py
Outdated
|
||
if len(violating_variables) > 0: | ||
msg = f'The initial guesses for {violating_variables} are in '+\ | ||
f'conflict with their bounds.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings don't need \
if you do this:
msg = (f'sstringgggggggggggggggggggggggg'
f'anotherstringgggggg')
par_map = {b1: 1.0, | ||
b2: 2.0, | ||
b3: 3.0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preferred formating for dictionaries is:
a = {
'b': 1,
'c': 2,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean 'b1' instead of b1 or you mena the location of } ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the location of the parentheses and the indentation. Some examples here: https://peps.python.org/pep-0008/#code-lay-out
uy: (-1.0, 1.0), | ||
z: (-1.0, 1.0), | ||
uz: (-1.0, 1.0), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case seems to have all unknown variables with bounds. Do you tests cases where bounds are not given for some (or all)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case seems to have all unknown variables with bounds. Do you tests cases where bounds are not given for some (or all)?
I will check. I will also check, what happens with 'reversed' bounds
) | ||
|
||
bounds= { | ||
a1: (-1.0, 1.0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if this was? a1: (1.0, -1.0)
? I guess IPOPT may throw an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My method would not care, about IPOPT do not know, never tried.
Would this not be a completely nonstandard way to give an interval?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just trying to imagine what inputs may break your function (and thus should be written as tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just trying to imagine what inputs may break your function (and thus should be written as tests).
Sorry, I mixed this up my PR for create_linear_initial_guess
With 'reversed' bounds it would not work, but easy to fix. I never thought of this.
(Maybe subconsciously I assumed your guide: garbage in - garbage out... :-) )
with raises(ValueError): | ||
_, _ = prob.solve(initial_guess, respect_bounds=True) | ||
|
||
# D: respect_bounds=False by default. Bounds are ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could set max iterations to 1 or 2 to save computation time when solve actually runs.
This looks very good. I left a few minor comments, but they aren't necessary to fix for merging. The only major comment is that you probably need a few more unit tests to check some variation on what type of bounds were set. |
Thanks! I just checked an example (your drone) with 'reversed' bounds: {F: (100, -100)} |
I would have thought that IPOPT would raise an error. That makes me wonder why reverse bounds is allowed for IPOPT. Maybe there is a reason you'd want that. For this PR, we only need to ensure that your new functionality is well tested. Do we want to support reverse bounds with this functionality? If not, we should probably raise an error if reverse bounds are detected. A ValueError sounds correct. |
My method will not work for reversed bounds. (I must admit I did not think of this possibility) |
I'm fine with opty telling you no for this. |
I will do it like this. Maybe here the numpydocs |
Yes, that is the purpose of that documentation section. |
I now check for reversed bounds before I check whether the initial guess meets the bounds. If there is at least one reversed bound a ValueError will be raised. Can you somehow ignore all these changed simulations? I changed them, when we decided to set the kwarg of solve to True by default, so I tried to adjust the examples accordingly. When we decided to set it to False, I thought I changed them all back, but apparently this did not work..... |
What is the status of this PR? Is it ready for a review? Looks like merge conflicts need to be resolved. |
Yes, ready. |
Tried to fix the conflict. |
There are still outstanding comments from my first review that haven't been addressed. |
A method, called from solve to ensure that the initial guesses are within their respective bounds. As such a conflict is not fatal for opty, a UserWarning is raised. Should take care of issue #355