Implement uncached Cells
TBD
Is the alternative to use custom imported modules for this purpose?
Yes, this can be used like a normal Python function.
Example
import modelx as mx
@mx.defcells
def cash_inflows():
return [1, 2, 3]
@mx.defcells
def cash_outflows():
return [2, 1, 0]
@mx.uncached
def get_pv(cashflows: list):
rate = 0.05
disc = 1 / (1 + rate)
return sum(v * disc**(i + 1) for i, v in enumerate(cashflows))
@mx.defcells
def pv_inflows():
return get_pv(cash_inflows())
@mx.defcells
def pv_outflows():
return get_pv(cash_outflows())
@mx.defcells
def pv_netflows():
return get_pv([i - o for i, o in zip(cash_inflows(), cash_outflows())])
print(f"pv_netflows():{pv_netflows()}")
print(f"pv_inflows() - pv_outflows():{pv_inflows() - pv_outflows()}")
I like the imported module approach as it creates a clear split between regular Python functions and modelx grid functionality.
You mean by "the import module approach" the way you import modules by new_module?
yes
This is a new feature. The import module approach is still available. I'll blog about pros and cons after introducing this.
Completed with the release of modelx v0.27.0