Feature description
PyBaMM uses model variables to do post-processing calculations on solved models, e.g. calculating the voltage from the internal state vector returned by the solver. This is quite similar in concept to the cost functions implemented in PyBop: "take the output of a simulation and calculate some function from this", so I would suggest that we can simply use PyBaMM variables to implement each cost function.
Motivation
This was inspired by this problem suggested by @NicolaCourtier:
Another example is: Imagine we want to optimise the energy density so we are scaling the simulation result by the cell mass. See this example. The mass of each component is not included in the standard parameter set because they are not used in typical models. When optimising the volume fractions, we then require parameters which are not used by PyBaMM but are used in the cost function to compute the cell mass.
(We currently solve the problem by making assumptions and neglecting the parameters not in the PyBaMM parameter set)
The advantage of using PyBaMM's variables are:
- more efficient calculation. Using the pybamm solvers
output_variables argument the calculation of the cost function can be moved into the solver itself
- use of pybamm's flexible expression trees to specify cost functions, allowing us to use additional parameters in the cost function that are not part of the base model
- simplifies the pybop code as there is no need to calculate any of the cost functions, you just use the solution object like so:
sol["my_cost_function"].data
Possible implementation
This would require some additions on the pybamm side. The pybamm.ExplicitTimeIntegral allows us to implement some of the design cost functions, but you would need something like pybamm.DiscreteSumOverTime to implement the fitting cost functions. You would also need to support the calculation of sensitivities for these symbol classes.
Additional context
No response
Feature description
PyBaMM uses model variables to do post-processing calculations on solved models, e.g. calculating the voltage from the internal state vector returned by the solver. This is quite similar in concept to the cost functions implemented in PyBop: "take the output of a simulation and calculate some function from this", so I would suggest that we can simply use PyBaMM variables to implement each cost function.
Motivation
This was inspired by this problem suggested by @NicolaCourtier:
The advantage of using PyBaMM's variables are:
output_variablesargument the calculation of the cost function can be moved into the solver itselfsol["my_cost_function"].dataPossible implementation
This would require some additions on the pybamm side. The
pybamm.ExplicitTimeIntegralallows us to implement some of the design cost functions, but you would need something likepybamm.DiscreteSumOverTimeto implement the fitting cost functions. You would also need to support the calculation of sensitivities for these symbol classes.Additional context
No response