linopy.model.Model.to_netcdf

linopy.model.Model.to_netcdf#

Model.to_netcdf(*args, **kwargs)#

Write out the model to a netcdf file.

Parameters:
  • m (linopy.Model) – Model to write out.

  • *args – Arguments passed to xarray.Dataset.to_netcdf.

  • **kwargs (TYPE) – Keyword arguments passed to xarray.Dataset.to_netcdf.

Notes

Variables, constraints, the objective, parameters and named expressions (Model.expressions, including their linear/quadratic type) are all persisted and fully restored by linopy.io.read_netcdf(). The insertion order of each container is stored as a JSON list in the _linopy_<kind>_order attribute.

The SOS reformulation lifecycle token lives only on the in-memory Model and is not persisted. If the model has an active SOS reformulation at serialization time, the netcdf contains the reformulated MILP form (aux binaries and cardinality constraints) and a UserWarning is emitted to flag that the deserialized copy will not be able to undo the reformulation.

Model.solve(remote=...) invokes to_netcdf internally on the reformulated model and suppresses this warning.