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 · 6 comments
Open

Reduce time it takes to run the examples #204

moorepants opened this issue Aug 4, 2024 · 6 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.

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