by $g_c:\mathcal{S}\times\mathcal{A}\times\mathbb{R}^N\to \mathbb{R}^M$ the constraints imposed to the system and define the following policy $$\begin{aligned}
    \pi( {s,\theta}) &= \operatorname*{arg\,min}_{ {a}} c( {s},  {a}, \phi_\theta) \\
    &\quad \text{s.t.  } g_c( {s},  {a}, \phi_\theta) \leq 0 \nonumber.\end{aligned}$$ Observe that the policy depends on the learned model, and thus it is also a function of the parameters $\theta$. In particular, if the residual error of learning the model dynamics is low, we can expect good performance out of such policies. Since, the model is a neural network, it is easy to obtain gradients $\nabla_{ {a}} \phi_{\theta}( {s},  {a})$ which can be used for the same primal-dual method mentioned in Sec. \[Methodology\]. The only difference is that instead of optimizing model weights, the solver is optimizing for the inputs. This procedure is shown in Algorithm \[alg:controller\] where the Lagrangian is defined as $$L_c( {a}, \lambda) = c( {s},  {a}, \theta) + \lambda g_c( {s},  {a}, \theta).$$

\[alg:controller\] $\lambda \leftarrow \lambda_0$ , set dual variable to an initial value $ {a} \leftarrow  {a}_0$, set action to some initial action $ {a}$

Learning a model and using such an optimization problem as the policy allows different controllers to be designed for different goals and constraints. This 