Skip to content

Conversation

Peter230655
Copy link
Contributor

@Peter230655 Peter230655 commented May 6, 2025

This is the example in examples-gallery/advanced

  • removed hacks and added inequalities.
  • adopted docstrings accordingly
  • cleaned it up using flake8

I also make a small change in plot_constraint_violations:
if subplots=True and there are eom_bounds, the eoms are shown, not supressed.

NB:
As this version is slightly more general than the one it should replace, I cannot compare the execution times.

@Peter230655
Copy link
Contributor Author

Peter230655 commented May 6, 2025

All tests fail with this message:
image
I have no idea what this could be.

@moorepants
Copy link
Member

Update with master to fix the build issue.

@Peter230655
Copy link
Contributor Author

Update with master to fix the build issue.

I am unclear what this means. Could you explain, please.

@moorepants
Copy link
Member

I have fixed the issue in the master branch and you have to merge the updated master branch into this branch.

@Peter230655
Copy link
Contributor Author

Peter230655 commented May 6, 2025

Got it, thanks!
Just pushed it again.

# %%
# Create the optimization problem and set any options.
eom_bounds = {
7: (-np.inf, par_map[radius]),
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be cleaner to have - radius in the eom?

Copy link
Contributor Author

@Peter230655 Peter230655 May 6, 2025

Choose a reason for hiding this comment

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

Wouldn't it be cleaner to have - radius in the eom?

As the distance can never be negative, {7: (0.0, par_map[radius]} would have been good enough.
I saw in the last simulation, that -np.inf worked faster, so I put it here. I did not test it with 0.0, though.

Copy link
Member

Choose a reason for hiding this comment

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

If you have an equation, e..g a + b/c >= d + c then I think we want to show in examples that you should always do something like: a + b/c - d - c >= 0 and then the bounds would be {0: (0, inf)}. I am not seeing why you'd ever need bounds that aren't zero and +/infinity.

Having to extract values from the par_map and then pass that to problem, which already has par_map passed in, seems like something is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have an equation, e..g a + b/c >= d + c then I think we want to show in examples that you should always do something like: a + b/c - d - c >= 0 and then the bounds would be {0: (0, inf)}. I am not seeing why you'd ever need bounds that aren't zero and +/infinity.

Having to extract values from the par_map and then pass that to problem, which already has par_map passed in, seems like something is wrong.

I agree:
any inequality a < eom < b can be comverted into two inequalities

  • 0 < eom - a < infinity
  • -infinity < eom - b < 0

Would this be the preferred way?
This doubles the eoms needed for bounds,

solution, info = prob.solve(initial_guess)
initial_guess = solution
print(info['status_msg'])
print(info['obj_val'])
Copy link
Member

Choose a reason for hiding this comment

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

This isn't good for a example. Examples should have 1 call to Problem and the initial guess should be prepared and stored so that elaborate initial guess coaching isn't needed.

Copy link
Contributor Author

@Peter230655 Peter230655 May 6, 2025

Choose a reason for hiding this comment

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

This isn't good for a example. Examples should have 1 call to Problem and the initial guess should be prepared and stored so that elaborate initial guess coaching isn't needed.

The solution is stored and used. I made this elaborate thing, so a solution will be found, if a user does not want to use the solution stored.
Does it make sense to offer a way to get as solution for first principles, which does not work if tried?
In this example, this approach from easy to difficult was the only way I found to make opty converge.

Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to offer a way to get as solution for first principles, which does not work if tried?

No, I don't think we need such things in these examples...unless we are making an example to teach methods of getting convergence or best practices for preparing an initial guess. This example has now become a mini research problem instead of a simple example to learn how to use opty.

Copy link
Contributor Author

@Peter230655 Peter230655 May 7, 2025

Choose a reason for hiding this comment

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

Obviously, I do not totally agree. :-)
A potential user should see examples how to apply opty.
Unless it converges it is of no use.
At least it took me quite a while to come up with this iterative approach. I could not get convergence any other way. (the need to build Problem numerous times got me to post #455 )
Hence I feel, that at least in the advanced section, such an example has its place.

I guess, getting convergence is not particular to opty, but to any nonlinear optimization program.
At least I came to opty without any experience in nonlinear optimization, could it not be the case that other potential users come my route?

Of course, your opinion counts, so I see these options:

  • we drop this example (then we should also drop the existing one, it suffers from the same problem)
  • we give a simple version, but we know it will not converge if no solution is available.

Copy link
Member

Choose a reason for hiding this comment

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

I guess, getting convergence is not particular to opty, but to any nonlinear optimization program.

Yes, that is more the point.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe the key thing is that the documentation for software is to show "how to use the software" not "how to solve any problem you possibly can with the software".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a clear direction.
I admit I like to test out the limits of opty (and of sympy mechanics)
But your examples, like the guy getting up from a chair, are also not exactly basic. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we ever add a feature to opty that automates iterating through initial guess designs, the we could have an example that shows how to use that feature. But opty currently has zero features that have anything to do with developing good initial guesses. We do have this open PR #365, which will need an example once merged. But that's it.

The example I am updating to inequalities right now, plot_car_around_pylons would certainly qualify.

Copy link
Member

Choose a reason for hiding this comment

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

But your examples, like the guy getting up from a chair, are also not exactly basic. :-)

Yes, this one should probably not be an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but it is GREAT!!

@Peter230655
Copy link
Contributor Author

Peter230655 commented May 7, 2025

  • changed inequalities as per suggestion, now contain only 0.0 and +/- infinity.
  • eliminated the 'monster' iterations if no solution is given. I found a way to still get a solution, glad you complained! :-)

Interesting: here backend='numpy' would not converge, while backend='cython' had no problems.
I will pay more attention to this in future.

As I reported earlier, backend='numpy' does not seem to 'like' zero initial conditions. A warning comes up, but no abortion. No idea, if these issues are related.

@moorepants
Copy link
Member

if subplots=True and there are eom_bounds, the eoms are shown, not supressed.

Please move to another PR>

@Peter230655
Copy link
Contributor Author

Peter230655 commented Jun 3, 2025

if subplots=True and there are eom_bounds, the eoms are shown, not supressed.

Please move to another PR>

This is a separate PR #464
I do not remember why I mentioned it here. Set subplots=False in the simulation.

As this is an example we already have on examples-gallery, just the hacks replaced with eom inequalities, I feel it should be merged.

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