modelx v0.1.0 (1 December 2019)#
This release introduces major spec changes and enhancements, as well as a few minor bug fixes.
Input and calculated values
A Cells holds values either input by the user, or calculated by its formula. The former are now called input values, and distinguished from tha latter:
@mx.defcells def foo(x): return x * foo(x-1) foo = 5 foo # Calculated buy the formula
foo in this example holds an input value of 5,
foo holds a calculated value of 120.
To check whether a node of a Cells has an input value,
is_input() is now available.:
>>> foo.node(0).is_input() True >>> foo.node(5).is_input() False
Change in Cells.clear and introduction of Cells.clear_all and Cells.clear_at
With the introduction of the input value concept,
Cells.clear() method now only clears calculated values, but not input values.
Cells.clear_all() method is introduced for clearing both input and calculated values.
Another new method
Cells.clear_at() is introduced for clearing
the value of a specific Cells node, whether it’s an input value or a calculated value.
Recalculation upon input change
Before version 0.1.0, when a new input value is assigned to a node of a Cells, the values of the nodes depending on the input cells are cleared. From version 0.1.0, those values are recalculated. Continuing the previous example:
>>> foo.series x 0 1 1 1 2 2 3 6 4 24 5 120 Name: foo, dtype: int64 >>> foo = 2 >>> foo.series x 0 2 1 2 2 4 3 12 4 48 5 240 Name: foo, dtype: int64
Models available as modelx attirbutes
Only available with Python 3.7 or newer
In addition to
get_models(), models can also be acquired
through modelx attribute access:
>>> m1 = mx.get_models["Model1"] >>> m2 = mx.Model1 >>> m1 is m2 True
defcells and new_space creates new model/space if no current model/space is available
Previously, if the current model and/or the current space don’t exist,
the user needs to create a model and/or a space manually.
From version 0.1.0, if the current model and/or the current space are
missing when calling
new_space() API decorator/functions,
a new model and/or a new space are created automatically, and
are assigned to the current model and/or the current space, so
the user does not need to create them explicitly beforehand.
New serializer for reading/writing models
Serializer is an internal part of modelx to implement the functionality of reading models from and writing models to files in a human-readable format. The initial version of modelx serializer (version 1) was introduced in modelx v0.0.22. The version 1 serializer had limited functionality.
modelx v0.1.0 comes with almost completely rewritten serializer (version 2). The version 2 serializer reflects the following improvements.
Output files with “.py” extension are syntactically correct Python scripts, and also importable.
The new format of the output files is more readable.
When writing a model to an existing directory, the existing directory is renamed with the prefix of “_BAK1”.
Any picklable objects as references can be stored in binary data files.
Input values of Cells are also stored. Input values can be any picklable objects.
Object identities among the stored picklable objects are preserved.
read_model() of modelx v0.1.0 still supports reading files written
in the version 1 format.
defcells()can now be used to update existing cells formulas, in addition to creating a new cells.
maxlen parameter is added to
start_stacktrace(), to specify the maximum length of traces to be kept (GH13).
Backward Incompatible Changes#
The behaviour of
Cells.clear()has changed. See Enhancements section.
The behaviour of the value assignment operation on
Cellshas changed. See Enhancements section.
The behaviour or
new_space()API functions have changed. See Enhancements section.
The new format of
write_model()is introduced. See Enhancements section.
cur_space()is set to None when the current model is deleted.
The current space attribute of a models is now saved and restored by
Fix the error raised from a package supporting IPython’s auto complete feature when used in Windows command prompt console.
Fix the error raised when attempting to delete refs by the del statement.
Fix missing source file info from restored cells.
Fix crash with Python 3.8 on Windows due to stack overflow.