-
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 equations_of_motion are not AEs #236
Conversation
You'll need to check this on something at least the size of the bicycle model to make sure it doesn't slow down things. I'm generally fine having a "garbage in, garbage out" design, especially when there can be significant performance costs for checking inputs. |
The bicycle model does not run with me, and I still could not lokate the error.
with the eom having 23,000 operations, and duration was less than 10^(-15). |
If that is true, then it should be pretty fast. |
opty/direct_collocation.py
Outdated
@@ -152,6 +152,9 @@ def __init__(self, obj, obj_grad, equations_of_motion, state_symbols, | |||
|
|||
""" | |||
|
|||
if equations_of_motion.has(sm.Derivative) == False: | |||
raise ValueError('The equations of motion must be DEs or DAEs, not AEs.') |
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.
raise ValueError('The equations of motion must be DEs or DAEs, not AEs.') | |
raise ValueError('No time derivatives are present, the equations of motion must be ordinary differential equations (ODEs) or differential algebraic equations (DAEs),') |
This needs a unit test to make sure the error raises. This will isn't completely robust in the sense that it may find a |
As per chatGPT it is true, that it stops as soon as it has found the first term... |
I'm not the type that listens to anything ChatGPT may say... |
I tested it with a small example, where I simply deleted the .diff(t) in all the terms. This worked, it raised the error. What I tried earlier was this:
With 23,000 operations, this took about o.5 sec. |
likely smart - but it has helped me a lot with git commands. :-) |
Adjusted the wording of the ValueError, just in case you want to merge this. |
It would still need a unit test. |
Would this be a program without time derivaties so it gives the error? (of course I did test it) |
Yes to all three questions. |
I wrote a function, which when run will cause the ValueError to be raised - and of course will stop running. (copied it from an existing opty test function and modified according to my needs)
I found a way (with chatGPT!) so my function stops with an exception if no ValueError is found, If a ValueError occurs it keeps on running. |
I would recommend having a look at the existing unit tests and using the patterns there to come up with how your test will look. |
Yes. |
except ValueError: | ||
print('ValueError found correctly') | ||
else: | ||
raise Exception() |
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 should use the raises()
function from pytest. See where it is used elswhere in the file.
Is this how you meant it? I simply copied it from the only other place it is used in test_direct_collocation.py |
bounds={T(t): (-2.0, 2.0)}, | ||
) | ||
with raises(ValueError): | ||
eom = 'algebraic equations' |
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'd have to run the line that raises the error in the with statement.
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'd have to run the line that raises the error in the with statement.
Sorry, but I do not understand.
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.
These things are explained in documentation: https://docs.pytest.org/en/4.6.x/reference.html#pytest-raises |
You ARE a teacher! Your method of not telling me exactly what to do helps me to learn! Just curiosity: Would my original way have worked and just been very ugly compared to this way, or plain wrong? |
Probably would have worked. We use pytest for the tests, so no reason not to use these helper functions that are more robust than things we write. |
THANKS! |
Makes sense, plus more 'elegant', I think! |
Everything in the PR is merged. You can see all changes in the "files changed" tab. |
Thanks! Makes me feel good to contribute - even if not exactly in gigantic ways! :-) |
Check whether the equations of motions contain differential equation, and rais a ValueError if they are AEs.
I used @tjstienstra idea, which seems to be VERY fast!
Should take care of issue # 228