UserSpace.copy#

UserSpace.copy(parent, name=None, defined_only=False)[source]#

Create a copy of this space in a different parent.

Creates a new UserSpace in the specified parent by copying this space’s structure, including cells, child spaces, references.

Parameters:
  • parent (UserSpace or Model) – The parent object that will contain the copied space.

  • name (str, optional) – Name for the copied space. If not provided, uses the original space’s name. Must be unique within the parent.

  • defined_only (bool, optional) – If True, only copies spaces that are explicitly defined (not inherited from base spaces). Defaults to False.

Returns:

The newly created copy of this space

Return type:

UserSpace

Example

>>> space1 = model.new_space('Original')
>>> space1.new_cells('foo', lambda x: x * 2)

>>> # Copy to the model with different name
>>> space2 = space1.copy(model, 'Copy')
>>> space2.foo(5)
10

>>> # Copy to another space
>>> parent_space = model.new_space('Parent')
>>> space3 = space1.copy(parent_space)

See also