fumitoh / modelx

Use Python like a spreadsheet!

Home Page:https://modelx.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

model serializer: dynamic space reference issue

alebaran opened this issue · comments

The following code including space referencing dynamic space breaks.

from modelx import *
m = new_model()
def t_arg(t):
    pass

m.new_space('s1', formula=t_arg)
m.new_space('s2', refs={'s1': m.s1(0)})
write_model(m, 'm')
read_model('m')

Dynamic spaces themselves are not stored by write_model at the moment.
I'll think about how it can be achieved.

Thank you for this fix. It is now breaking at a later stage for me. Below you can see an example of the breaking code:

from modelx import *
m, s1 = new_model(), new_space()

def t_arg(t):
    pass

m.new_space(name='s2', formula=t_arg, refs={'a': 1})

s3 = s1.new_space(name='s3')
s3.b = m.s2(0) # this line makes it break
write_model(m, 'm')
m2 = read_model('m')
m2.s2.a # works
m2.s2(0).a # doesn't work

Without this line s3.b = m.s2(0) the code runs.

Thanks, I can finally save the model in a new way.
I have a related question. Why is some data stored in a large container "data.pickle", when the remainder are saved in separate files with MD5 like names?

What are the separate files with MD5 like names? I thought all data is now stored in data.pickle.

E.g.

from modelx.serialize.jsonvalues import *

_formula = None

_bases = []

_allow_none = None

_spaces = []

_method = {
    "method": "new_cells_from_pandas",
    "args": [
        "data_curve/data"
    ],
    "kwargs": {
        "cells": "MA_or_VA",
        "param": null,
        "call_id": "15713466-8163-4bf4-a004-270d14745ab0"
    }
}

# ---------------------------------------------------------------------------
# Cells

Swap_ByName_df = lambda: None

Spread_ByName_df = lambda: None

MA_or_VA cell references a separate file, when Swap_ByName_df and Spread_ByName_df are in data.pickle

Cells created by new_cells_from_pandas and new_spaces_from_pandas are treated differently.
The source DataFrame or Series objects passed to the methods are saved separately from other data.

This treatment is analogous to how new_spaces/cells_from_excel/csv save their source Excel or CSV files under the model folder instead of saving the values taken from the files in data.pickle.