drake
drake copied to clipboard
Serialize (and deserialize) a MathematicalProgram (e.g. to Yaml)
For mathematical programs using only built-in types for costs and constraints (e.g. LinearCost, LinearConstraint, ...)... it should be possible to serialize an entire program to yaml... and load it again. There are existing serialization formats for optimization problems from other packages (e.g. ampl), but adding the yaml workflow will allow the same methods to additionally be used with other parts of Drake. For instance, we would like to serialize GraphOfConvexSets instances as a follow-on effort to this.
The relevant yaml serialization documentation is here.
Adding the serialization methods to the costs and constraints should be easy enough. The serialize method in MathematicalProgram knows enough of the type information for some of the types (e.g. it keeps separate lists for linear_constraints, linear_equality_constraints, etc) to support deserialization. However, there are other built-in types that we might like to serialize/deserialize which currently get dumped into "generic" costs/constraints. Examples include L2NormCost, ExpressionConstraint, etc. I think we would need to be a little more clever about deserializing to those types. cc @jwnimmer-tri in case he has any wisdom/recommendations.
cc @bernhardpg .