Skip to content

Commit

Permalink
Made the most minimal version of the non-working l4casadi example
Browse files Browse the repository at this point in the history
  • Loading branch information
pariterre committed Jan 10, 2025
1 parent 34d95df commit 7d9469f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 65 deletions.
65 changes: 0 additions & 65 deletions bioptim/examples/getting_started/race_car.py

This file was deleted.

40 changes: 40 additions & 0 deletions bioptim/examples/getting_started/temporary_non_working_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from casadi import Opti, MX, Function
import l4casadi as l4c
import torch


class NeuralNetworkModel(torch.nn.Module):
def __init__(self, layer_node_count: tuple[int]):
super(NeuralNetworkModel, self).__init__()
layers = torch.nn.ModuleList()
layers.append(torch.nn.Linear(layer_node_count[0], layer_node_count[-1]))
self._forward_model = torch.nn.Sequential(*layers)
self.eval()

def forward(self, x: torch.Tensor) -> torch.Tensor:
return self._forward_model(x)


def main():
opti = Opti()
nx = nu = 1
torch_model = NeuralNetworkModel(layer_node_count=(nu, nx))

# ---- decision variables ---------
x = opti.variable(nx, 1) # state
u = opti.variable(nu, 1) # control

# ---- dynamic constraints --------
x_sym = MX.sym("x", nx, 1)
u_sym = MX.sym("u", nu, 1)
forward_model = l4c.L4CasADi(torch_model, device="cpu")
f = Function("xdot", [x_sym, u_sym], [x_sym - forward_model(u_sym)])
opti.subject_to(f(x, u) == 0) # Adding this line yields the error : jac_adj_i0_adj_o0 is not provided by L4CasADi.

# ---- solve NLP ------
opti.solver("ipopt")
opti.solve()


if __name__ == "__main__":
main()

0 comments on commit 7d9469f

Please sign in to comment.