Currently, the solve() method returns a dictionary containing the solution. I'm proposing here that we should implement a solution class that has the solution data packed inside but also comes with some useful methods.
For example, it could look something like the following.
import casadi as cs
from dataclasses import dataclass
from typing import Dict, List
from .models import Model
@dataclass
class Solution:
solution_dict: Dict[str, cs.DM]
success: bool
def get_model_solution_state(self, name, t):
return self.solution_dict[f{name}/q'][:, t]
def interpolate(self, name, duration):
pass # todo
This would be a little re-work but I think it would help optas become more extensible. I think this would be worthwhile. @joaomoura24, if this means a lot of hassle you're end. We could still incorporate the feature but put a flag in the Solver class interface. E.g. we put a flag saying solution_return_type='dict' by default (and the return type is what it is currently), and if the user wants to get the solution as the Solution class (something like above) perhaps they put solution_return_type='soln_cls' or something. I prefer not to do this but happy to if it means a lot of work your end.
I've not been a fan of having to do solution[f'{self.name}/q'] all the time, and also solver.interpolate doesn't make so much sense so would be good to put that functionality in a place that makes more sense.
Currently, the
solve()method returns a dictionary containing the solution. I'm proposing here that we should implement a solution class that has the solution data packed inside but also comes with some useful methods.For example, it could look something like the following.
This would be a little re-work but I think it would help optas become more extensible. I think this would be worthwhile. @joaomoura24, if this means a lot of hassle you're end. We could still incorporate the feature but put a flag in the
Solverclass interface. E.g. we put a flag sayingsolution_return_type='dict'by default (and the return type is what it is currently), and if the user wants to get the solution as theSolutionclass (something like above) perhaps they putsolution_return_type='soln_cls'or something. I prefer not to do this but happy to if it means a lot of work your end.I've not been a fan of having to do
solution[f'{self.name}/q']all the time, and alsosolver.interpolatedoesn't make so much sense so would be good to put that functionality in a place that makes more sense.