Model.compare_cells#

Model.compare_cells(func)[source]#

Tentative: Compare cells with the same name across different spaces in the model.

Warning

This is a tentative feature based on a use request (See #196), and will be replaced with a more robust solution in future releases.

This method searches for cells with a given name across all spaces in the model, groups them by their normalized formula, and displays the results.

Parameters:

func – Either a function object or a string representing the cell name to compare. If a function object is provided, its __name__ attribute will be used.

Returns:

None. Results are printed to stdout.

Output Format:

Groups cells by their normalized formula and displays:

  • Group number

  • List of space names containing cells with identical formulas

  • The normalized formula (with empty lines removed)

Notes

  • Empty lines in formulas are removed during normalization

  • If a cell’s formula is not accessible, it will be labeled as “<formula not accessible>”

  • If no spaces contain a cell with the given name, a message is printed

  • Formulas are considered identical after normalization (stripping and removing empty lines)

Example

>>> import  modelx as mx

>>> m = mx.new_model()

>>> s1 = m.new_space()

>>> @mx.defcells
... def foo(x):
...     return 1

>>> s2 = mx.new_space()

>>> @mx.defcells
... def foo(x):
...     return 2

>>> m.compare_cells('foo')
------------------------------------------------------------
[Group 1]
Spaces    : Space1
Formula (normalized):
def foo(x):
    return 1
------------------------------------------------------------
------------------------------------------------------------
[Group 2]
Spaces    : Space2
Formula (normalized):
def foo(x):
    return 2
------------------------------------------------------------