Skip to content

Adding new tutorial to Plasmo#134

Merged
jalving merged 11 commits intoplasmo-dev:mainfrom
KiernanJ:main
Jun 29, 2025
Merged

Adding new tutorial to Plasmo#134
jalving merged 11 commits intoplasmo-dev:mainfrom
KiernanJ:main

Conversation

@KiernanJ
Copy link
Copy Markdown
Contributor

New tutorial implementation of multi-horizon MPC to Plasmo. Super simple example for beginners in optimization, JuMP, and Plasmo.

@jalving
Copy link
Copy Markdown
Member

jalving commented Apr 2, 2025

Hi @KiernanJ, thanks for your contribution! We had some issues with an old workflow. Can you try merging the latest main into your PR? It should re-trigger the checks.

KiernanJ added 2 commits May 21, 2025 12:42
Added new line to fix some formatting
Fixing MD for clarity
We define our graph and subgraph structure. This encapsulates the MH-MPC approach for each $H$ sub-interval $i \in H$. Here $H = 5$. To run the entire optimization over a set time period, we will wrap the model construction and optimization (steps 2 through 5) in a function called ``MHMPC``.

```julia
function MHMPC(x0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for adding the MHMPC function! One last request on this: can put these blocks into their own function calls just to make the code a little easier to copy over for a potential user? Something like what is in the optimal control of a quadcopter example: https://plasmo-dev.github.io/Plasmo.jl/dev/tutorials/quadcopter/

I think you can do something like:

function add_horizon_subgraphs()
    # All of the subgraphs
    graph_SG1 = OptiGraph()
    graph_SG2 = OptiGraph()
    graph_SG3 = OptiGraph()
    graph_SG4 = OptiGraph()
    graph_SG5 = OptiGraph()

    subgraphs_all = [graph_SG1, graph_SG2, graph_SG3, graph_SG4, graph_SG5]

    # Initialize all nodes for subgraphs
    @optinode(graph_SG1, nodes1[1:N_i[1]])
    @optinode(graph_SG2, nodes2[1:N_i[2]])
    @optinode(graph_SG3, nodes3[1:N_i[3]])
    @optinode(graph_SG4, nodes4[1:N_i[4]])
    @optinode(graph_SG5, nodes5[1:N_i[5]])

    

    nodes_all = [graph_SG1[:nodes1], graph_SG2[:nodes2], graph_SG3[:nodes3], graph_SG4[:nodes4], graph_SG5[:nodes5]]
    return subgraphs_all, nodes_all
end

Then you can do something like this farther down

function MHMPC
    graph = OptiGraph()
    subgraphs_all, nodes_all = add_horizon_subgraphs(graph)
    ...
end

end
```

Now, plotting the values of $x$ from our program:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe at the end of this last code snippet, add the code to call the run_sim function. Just something like:

x_sim, u_sim = run_sim()

KiernanJ added 2 commits May 22, 2025 08:32
Add functions to make tutorial more accessible to reader
@dlcole3
Copy link
Copy Markdown
Collaborator

dlcole3 commented Jun 17, 2025

@jalving any objections if we merge this? @KiernanJ updated the code and merged the previous main into this PR.

@jalving
Copy link
Copy Markdown
Member

jalving commented Jun 29, 2025

this looks good to me!

@jalving jalving merged commit 4fff38f into plasmo-dev:main Jun 29, 2025
5 checks passed
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.

3 participants