modelx v0.14.0 (2 May 2021)#

This release fixes bugs and introduces enhancements as follows.

Enhancements#

Enhanced Cells.doc property and new set_doc() method (GH44)#

Prior to this release Cells.doc property was read-only, and it was linked to the docstring of the Cells’s Formula, so the property for lambda Cells was always None.

With this release, Cells.doc property now works as setter. If a Cells has a no-lambda Formula, then the setter replaces the docstirng of the Formula:

>>> @mx.defcells
... def foo(x):
...     """This is foo"""
...     return x

>>> foo.doc
'This is foo'

>>> foo.doc = "foo's doc is updated"

>>> foo.formula
def foo(x):
    """foo's doc is updated"""
    return x

>>> foo.doc
"foo's doc is updated"

When setting the docstring of a Cells by Cells.doc property, the input string is not automatically indented:

>>> doc = """This is foo
...
... Unindented docstring
... """

>>> foo.doc = doc

>>> foo.formula
def foo(x):
    """This is foo

Unindented docstring
"""
    return x

The newly introduced Cells.set_doc method has the bool parameter insert_indents, and if it’s True, the second and subsequent lines of doc are auto-indented:

>>> foo.set_doc(doc, insert_indents=True)

>>> foo.formula
def foo(x):
    """This is foo

    Unindented docstring
    """
    return x

If a Cells’ Formula is defined by a lambda function, the doc is kept in the Cells separately from the function:

>>> space.new_cells(name="bar", formula=lambda x: x)
<Cells Model1.Space1.bar(x)>

>>> space.bar.doc = "I am bar"

>>> space.bar.doc
'I am bar'

modelx version saved in _system.json#

When a Model is written to files by Model.write, write_model(), Model.zip, or zip_model(), the version of the modelx is output in _system.json in addition to the serizalizer version.

Bug Fixes#

  • Model.doc was mistakenly treated as a Reference.

  • Fixed an error on rebinding a Reference that is referenced directly and indirectly by multiple Cells (GH43).

  • Fixed an error that was raised when a model was saved, if the model had saved previously by zip_model() or Model.zip and if the model contained a module created by new_module() (GH45).

  • On creating a new Space by new_space(), cur_model() is set to the Space’s Model.