Closed defrule closed 4 years ago
You can do:
import modelx as mx
import numpy
m, s = mx.new_model(), mx.new_space()
m.np = numpy
@mx.defcells
def unit_reserve_opening(t):
# your code
Or instead of m.np = numpy
, s.np = numpy
can limit the use of the name np
within the space
It won't be possible to save the model, if imported modules are added as refs.
In the example above if I add:
m.save('my_model.mx')
It breaks with message:
TypeError: can't pickle module objects
Btw. it is possible to save it with "write_model" feature, which is an awesome functionality. The only limitation of it is that "read_model" doesn't have a model name as a second parameter (like "open_model").
Thanks. I'll see if I can add renaming feature to read_model
.
I use model.save including custom class objects stored in the cells. E.g. bond class. Is there a way to do it with "write_model"?
Currently it's not possible. write_model
doesn't store cells values except for those cells that are created from new_cells_from_*
or new_space_from_*
methods, which are saved with their data source files.
In future, it may become possible to store input values with write_model
.
What do you call input values?
On Sat, 28 Sep 2019, 16:38 Fumito Hamamura, notifications@github.com wrote:
Currently it's not possible. write_model doesn't store cells values except for those cells that are created from new_cellsfrom or new_spacefrom methods, which are saved with their data source files. In future, it may become possible to store input values with write_model.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fumitoh/modelx/issues/8?email_source=notifications&email_token=AMOA4S3ZGKSKAK5TYQGAPP3QL5277A5CNFSM4G5QDQPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD724G7Y#issuecomment-536200063, or mute the thread https://github.com/notifications/unsubscribe-auth/AMOA4S362IR3UDI4NCIT3H3QL5277ANCNFSM4G5QDQPA .
I meant by input values those values stored in cells by the user through value assignment operations as opposed to those that are calculated by the formulas of the cells. Currently no information is held to distinguish between them, so need some work.
Just released v0.0.24 and those features are made available. See https://modelx.readthedocs.io/en/latest/releases/relnotes_v0_0_24.html
This really helps. Thank you very much
On Thu, 3 Oct 2019, 16:30 Fumito Hamamura, notifications@github.com wrote:
Just released v0.0.24 and those features are made available. See https://modelx.readthedocs.io/en/latest/releases/relnotes_v0_0_24.html
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fumitoh/modelx/issues/8?email_source=notifications&email_token=AMOA4S6RCMHPFRDDDKK3PLDQMYFYVA5CNFSM4G5QDQPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAIS4CI#issuecomment-537996809, or mute the thread https://github.com/notifications/unsubscribe-auth/AMOA4S5NVDW7XCKWF24KPHDQMYFYVANCNFSM4G5QDQPA .
modelx version 0.1.0 is released, and input values of a cells are distinguished from calculated values, and they are saved by write_model
function.
See the release note for the details.
https://modelx.readthedocs.io/en/latest/releases/relnotes_v0_1_0.html
Closing this issue as the discussion derailed from the title. Post on #15 for further discussion if any.
Not sure if this is an issue or intended. I wanted to use numpy so that each 'cell' represents an array.
In my example below 'unit_reserve_opening' is the opening account value at each projection timestep, but it get numpy to work, I had to import it within the function. Putting the import at the top of the module didn't work.