linopy.model.Model.copy

Contents

linopy.model.Model.copy#

Model.copy(include_solution=False, deep=True)#

Return a copy of this model.

With deep=True (default), variables, constraints, objective, parameters, blocks, and scalar attributes are copied to a fully independent model. With deep=False, returns a shallow copy.

Model.copy() defaults to deep copy for workflow safety. In contrast, copy.copy(model) is shallow via __copy__, and copy.deepcopy(model) is deep via __deepcopy__.

Solver runtime metadata (for example, solver_name and solver_model) is intentionally not copied. Solver backend state is recreated on solve().

Parameters:
  • m (Model) – The model to copy.

  • include_solution (bool, optional) – Whether to include solution and dual values in the copy. If False (default), solve artifacts are excluded: solution/dual data, objective value, and solve status are reset to initialized state. If True, these values are copied when present. For unsolved models, this has no additional effect.

  • deep (bool, optional) – Whether to return a deep copy (default) or shallow copy. If False, the returned model uses independent wrapper objects that share underlying data buffers with the source model.

Returns:

Model – A deep or shallow copy of the model.