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

Reduce time it takes to run the examples #204

Open
moorepants opened this issue Aug 4, 2024 · 10 comments
Open

Reduce time it takes to run the examples #204

moorepants opened this issue Aug 4, 2024 · 10 comments

Comments

@moorepants
Copy link
Member

Here is the current timing from a clean build:

computation time summary:
    - ../examples-gallery/plot_pendulum_swing_up_variable_duration.py:   110.06 sec   0.0 MB
    - ../examples-gallery/plot_drone.py:                                  75.58 sec   0.0 MB
    - ../examples-gallery/plot_two_link_pendulum_on_a_cart.py:            75.11 sec   0.0 MB
    - ../examples-gallery/plot_sliding_block.py:                          59.82 sec   0.0 MB
    - ../examples-gallery/plot_parallel_park.py:                          58.78 sec   0.0 MB
    - ../examples-gallery/plot_pendulum_swing_up_fixed_duration.py:       56.85 sec   0.0 MB
    - ../examples-gallery/plot_one_legged_time_trial.py:                  44.69 sec   0.0 MB
    - ../examples-gallery/plot_vyasarayani.py:                            11.22 sec   0.0 MB
    - ../examples-gallery/plot_betts2003.py:                              10.89 sec   0.0 MB

Reducing the time it takes to create animations is an easy adjusted, for example. We can safely skip generating a frame for every time instance by skipping frames with a minor adjustment to the code. Here is an example:

https://github.com/csu-hmc/opty/blob/master/examples-gallery/plot_drone.py#L299-L300

@moorepants
Copy link
Member Author

Another way to reduce time is to give better initial guesses. We can even store a solution and give that as a guess.

@Peter230655
Copy link
Contributor

Peter230655 commented Aug 4, 2024

Another way to reduce time is to give better initial guesses. We can even store a solution and give that as a guess.

How can I store a solution, so it does not get lost when the program is closed?
I thought about this often, but never came up with an idea... :-(
(I mean short of printing the solution and then typüing it into the program...)

@moorepants
Copy link
Member Author

You can save any value to a txt file with many different methods. NumPy has builtin ways to do this: https://numpy.org/doc/stable/reference/routines.io.html

@Peter230655
Copy link
Contributor

Peter230655 commented Aug 4, 2024

You can save any value to a txt file with many different methods. NumPy has builtin ways to do this: https://numpy.org/doc/stable/reference/routines.io.html

Amazing how this works - and it is two lines of code initially, no additional line in the final simulation. (After your hint, chatGPT told me the lines) I once modeled a drone with propellers, the one that wiggled and it cut down the simulation time from over one minute to 16 sec. - still wiggles, though :-)

@moorepants
Copy link
Member Author

Here is the output from a recent build on the readthedocs system, which is slower than running it locally:

computation time summary:
    - ../examples-gallery/plot_parallel_park.py:                             128.56 sec   0.0 MB
    - ../examples-gallery/plot_pendulum_swing_up_variable_duration.py:       127.54 sec   0.0 MB
    - ../examples-gallery/plot_pendulum_swing_up_fixed_duration.py:          124.13 sec   0.0 MB
    - ../examples-gallery/plot_sliding_block.py:                             105.60 sec   0.0 MB
    - ../examples-gallery/plot_ball_rolling_on_spinning_disc.py:              95.81 sec   0.0 MB
    - ../examples-gallery/plot_drone.py:                                      64.82 sec   0.0 MB
    - ../examples-gallery/plot_one_legged_time_trial.py:                      63.60 sec   0.0 MB
    - ../examples-gallery/plot_two_link_pendulum_on_a_cart.py:                49.41 sec   0.0 MB
    - ../examples-gallery/plot_crane_moving_a_load.py:                        33.36 sec   0.0 MB
    - ../examples-gallery/plot_non_contiguous_parameter_identification.py:    12.81 sec   0.0 MB
    - ../examples-gallery/plot_vyasarayani.py:                                12.40 sec   0.0 MB
    - ../examples-gallery/plot_betts2003.py:                                  11.66 sec   0.0 MB

@Peter230655
Copy link
Contributor

If I understand correctly, this is what I tried with the examples that have animations. Should be in the PRs.

@moorepants
Copy link
Member Author

Yes, you are. I'm just logging information here on the broader issue. I will get to all your PRs, but it just takes time.

@Peter230655
Copy link
Contributor

Peter230655 commented Sep 20, 2024

Yes, you are. I'm just logging information here on the broader issue. I will get to all your PRs, but it just takes time.

I am in NO rush, I have time! Just wanted to make sure I understood right - which you confirmed!

NB: now that I know examples-gallery a bit better, I do not think, that my sailboat and my Mississippi steamer contribute much. The Kane part may be interesting - but the opty is standard.
My double body skateboard at least shows, that iterating from a simple problem to a harder one can help opty to find a solution - but otherwise it is very contrived.
Anyway, you be the judge.

@moorepants
Copy link
Member Author

We can add them all as long as we keep the time down and can always delete them later if we every have to replace one.

@Peter230655
Copy link
Contributor

We can add them all as long as we keep the time down and can always delete them later if we every have to replace one.

makes emminent sense!

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

No branches or pull requests

2 participants