ModelFlowIb 2.94__tar.gz → 2.95__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {modelflowib-2.94 → modelflowib-2.95}/PKG-INFO +1 -1
- {modelflowib-2.94 → modelflowib-2.95}/model_parquet_mixin.py +29 -4
- {modelflowib-2.94 → modelflowib-2.95}/modelclass.py +19 -5
- {modelflowib-2.94 → modelflowib-2.95}/modelconstruct_estimation.py +8 -0
- modelflowib-2.95/modelestimator_r.py +1492 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelfactorize.py +240 -15
- {modelflowib-2.94 → modelflowib-2.95}/modelflowib.egg-info/PKG-INFO +1 -1
- {modelflowib-2.94 → modelflowib-2.95}/modelflowib.egg-info/SOURCES.txt +1 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelflowib.egg-info/top_level.txt +1 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelgrabgdx.py +42 -19
- {modelflowib-2.94 → modelflowib-2.95}/modelnewton.py +10 -6
- {modelflowib-2.94 → modelflowib-2.95}/modelreport.py +14 -10
- {modelflowib-2.94 → modelflowib-2.95}/modelsolver_ng.py +36 -14
- {modelflowib-2.94 → modelflowib-2.95}/pyproject.toml +3 -3
- {modelflowib-2.94 → modelflowib-2.95}/README.md +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/license.md +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelBLfunk.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/model_Excel.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/model_cvx.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/model_dynare.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/model_financial_stability.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/model_latex.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/model_latex_class.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelcausality.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelconstruct.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeldash.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeldashboot.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeldashsidebar.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeldekom.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeldiff.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeldisplay.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelestimation.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelestimator_new.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelflowib.egg-info/dependency_links.txt +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelflowib.egg-info/requires.txt +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelgrab.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelgrabexcel.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelgrabgekkobank.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelgrabwf2.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelhelp.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelhtml.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelinput_shiny.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelinvert.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeljupyter.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeljupytermagic.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelmacrograb.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelmanipulation.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelmf.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelnet.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelnormalize.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelode.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelpattern.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modeluserfunk.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelvis.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelwidget.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelwidget_core.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/modelwidget_input.py +0 -0
- {modelflowib-2.94 → modelflowib-2.95}/setup.cfg +0 -0
|
@@ -84,6 +84,24 @@ def _period_series_to_json(series):
|
|
|
84
84
|
return json.dumps(result_dict)
|
|
85
85
|
|
|
86
86
|
|
|
87
|
+
def storable_options(options):
|
|
88
|
+
"""The sticky solve options (oldkwargs) that can be written as JSON. A function with a ``spec`` dict (the
|
|
89
|
+
factorizers from modelfactorize.normal/pardiso) is stored as that dict. Others, such as a user function given
|
|
90
|
+
as factorizer=, are left out with a note: the loaded model then uses the default for them."""
|
|
91
|
+
keep, dropped = {}, []
|
|
92
|
+
for k, v in (options or {}).items():
|
|
93
|
+
if callable(v) and isinstance(getattr(v, 'spec', None), dict):
|
|
94
|
+
v = v.spec
|
|
95
|
+
try:
|
|
96
|
+
json.dumps(v)
|
|
97
|
+
keep[k] = v
|
|
98
|
+
except (TypeError, ValueError):
|
|
99
|
+
dropped.append(k)
|
|
100
|
+
if dropped:
|
|
101
|
+
print(f'modeldump: the solve option(s) {", ".join(dropped)} can not be saved and are left out')
|
|
102
|
+
return keep
|
|
103
|
+
|
|
104
|
+
|
|
87
105
|
def _df_to_feather_bytes(df):
|
|
88
106
|
"""Serialize a DataFrame to in-memory Feather/Arrow IPC bytes.
|
|
89
107
|
|
|
@@ -164,7 +182,8 @@ class Parquet_Mixin:
|
|
|
164
182
|
|
|
165
183
|
# ── dump ──────────────────────────────────────────────────────────────
|
|
166
184
|
|
|
167
|
-
def modeldump(self, file_path='', keep=False, large=False, compact=False, derivatives=False,
|
|
185
|
+
def modeldump(self, file_path='', keep=False, large=False, compact=False, derivatives=False, savebase=False,
|
|
186
|
+
**kwargs):
|
|
168
187
|
"""Dump model to disk.
|
|
169
188
|
|
|
170
189
|
Parameters
|
|
@@ -187,6 +206,11 @@ class Parquet_Mixin:
|
|
|
187
206
|
session takes them from the model instead of finding them again, which is
|
|
188
207
|
the slow part of its first solve for a large model. They are used only if
|
|
189
208
|
the equations and the solver options are the same.
|
|
209
|
+
savebase : bool
|
|
210
|
+
If True, store the basedf instead of the lastdf (for instance the baseline after an
|
|
211
|
+
experiment has been run). Only one dataframe is stored, so the file stays small; kept
|
|
212
|
+
solutions can be added with ``keep=True``. ``modelload`` gives it back as the dataframe
|
|
213
|
+
of the file, as always.
|
|
190
214
|
|
|
191
215
|
A model instance without a lastdf holds no dataframe, so the feather
|
|
192
216
|
format has nothing to be fast about. Such a model is always written as a
|
|
@@ -200,7 +224,8 @@ class Parquet_Mixin:
|
|
|
200
224
|
|
|
201
225
|
if not large or nodata:
|
|
202
226
|
# ── original JSON/gzip path ──────────────────────────────────
|
|
203
|
-
return super().modeldump(file_path=file_path, keep=keep, derivatives=derivatives,
|
|
227
|
+
return super().modeldump(file_path=file_path, keep=keep, derivatives=derivatives, savebase=savebase,
|
|
228
|
+
**kwargs)
|
|
204
229
|
|
|
205
230
|
# ── fast feather/zip path ────────────────────────────────────────
|
|
206
231
|
pathname = Path(file_path)
|
|
@@ -222,7 +247,7 @@ class Parquet_Mixin:
|
|
|
222
247
|
'format': 'feather_zip',
|
|
223
248
|
'frml': self.equations,
|
|
224
249
|
'modelname': self.name,
|
|
225
|
-
'oldkwargs': self.__dict__.get('oldkwargs', {}), # a model never solved has none
|
|
250
|
+
'oldkwargs': storable_options(self.__dict__.get('oldkwargs', {})), # a model never solved has none
|
|
226
251
|
'run_on_load': self.__dict__.get('run_on_load', False),
|
|
227
252
|
'straight': bool(self.__dict__.get('straight', False)), # loads the same way again
|
|
228
253
|
'diff_expressions': self.__dict__.get('diff_expressions', {}) if derivatives else {},
|
|
@@ -261,7 +286,7 @@ class Parquet_Mixin:
|
|
|
261
286
|
# current_per
|
|
262
287
|
zf.writestr('current_per.json', current_per_json)
|
|
263
288
|
# lastdf → feather
|
|
264
|
-
zf.writestr('lastdf.feather', _df_to_feather_bytes(_maybe_compact(self.
|
|
289
|
+
zf.writestr('lastdf.feather', _df_to_feather_bytes(_maybe_compact(self.dump_frame(savebase))))
|
|
265
290
|
# keep_solutions → one feather each, indexed by position
|
|
266
291
|
if keep:
|
|
267
292
|
for i, (name, df) in enumerate(self.keep_solutions.items()):
|
|
@@ -6865,11 +6865,24 @@ class Json_Mixin():
|
|
|
6865
6865
|
|
|
6866
6866
|
return pathname, dump_data
|
|
6867
6867
|
|
|
6868
|
-
def
|
|
6868
|
+
def dump_frame(self, savebase=False):
|
|
6869
|
+
'''The dataframe a dump stores: dump_df (normally the lastdf), or with savebase=True the basedf instead.
|
|
6870
|
+
Only one dataframe is stored, so the file stays small; kept solutions can be added with keep=True.'''
|
|
6871
|
+
if savebase:
|
|
6872
|
+
base = self.__dict__.get('basedf')
|
|
6873
|
+
if isinstance(base, pd.DataFrame):
|
|
6874
|
+
return base
|
|
6875
|
+
print('modeldump: savebase=True, but the model instance has no basedf - the lastdf is dumped')
|
|
6876
|
+
return self.dump_df
|
|
6877
|
+
|
|
6878
|
+
def modeldump_base(self, outfile='',keep=False,data=True,derivatives=False,savebase=False):
|
|
6869
6879
|
'''Dumps a model and its lastdf to a json file
|
|
6870
6880
|
|
|
6871
6881
|
if keep=True the model.keep_solutions will alse be dumped
|
|
6872
6882
|
|
|
6883
|
+
if savebase=True the basedf is dumped instead of the lastdf (for instance the baseline after an
|
|
6884
|
+
experiment has been run). modelload gives it back as the dataframe of the file, as always
|
|
6885
|
+
|
|
6873
6886
|
if derivatives=True the expressions for the derivatives, which a Newton solver has found
|
|
6874
6887
|
(model.diff_expressions), are dumped too. A Newton solver in a later session then takes them
|
|
6875
6888
|
from the model instead of finding them again - the slow part of its first solve for a large model
|
|
@@ -6925,14 +6938,15 @@ class Json_Mixin():
|
|
|
6925
6938
|
current_per_json = None
|
|
6926
6939
|
|
|
6927
6940
|
|
|
6941
|
+
from model_parquet_mixin import storable_options
|
|
6928
6942
|
dumpjson = {
|
|
6929
6943
|
'version': '1.10',
|
|
6930
6944
|
'has_data': dump_data,
|
|
6931
6945
|
'frml': self.equations,
|
|
6932
|
-
'lastdf': self.
|
|
6946
|
+
'lastdf': self.dump_frame(savebase).to_json(double_precision=15) if dump_data else None,
|
|
6933
6947
|
'current_per': current_per_json ,
|
|
6934
6948
|
'modelname': self.name,
|
|
6935
|
-
'oldkwargs': self.__dict__.get('oldkwargs',{}),
|
|
6949
|
+
'oldkwargs': storable_options(self.__dict__.get('oldkwargs',{})),
|
|
6936
6950
|
'run_on_load': self.__dict__.get('run_on_load', False),
|
|
6937
6951
|
'straight': bool(self.__dict__.get('straight', False)), # loads the same way again
|
|
6938
6952
|
'diff_expressions': self.__dict__.get('diff_expressions', {}) if derivatives else {},
|
|
@@ -7134,12 +7148,12 @@ class Json_Mixin():
|
|
|
7134
7148
|
|
|
7135
7149
|
class Zip_Mixin():
|
|
7136
7150
|
'''This experimental class zips a dumped file '''
|
|
7137
|
-
def modeldump(self, file_path='',keep=False,zip_file=True,data=True,derivatives=False):
|
|
7151
|
+
def modeldump(self, file_path='',keep=False,zip_file=True,data=True,derivatives=False,savebase=False):
|
|
7138
7152
|
pathname, dump_data = self._dump_pathname(file_path, self.has_data, data=data)
|
|
7139
7153
|
|
|
7140
7154
|
pathname.parent.mkdir(parents=True, exist_ok=True)
|
|
7141
7155
|
|
|
7142
|
-
json_string = self.modeldump_base(keep=keep,data=dump_data,derivatives=derivatives)
|
|
7156
|
+
json_string = self.modeldump_base(keep=keep,data=dump_data,derivatives=derivatives,savebase=savebase)
|
|
7143
7157
|
|
|
7144
7158
|
|
|
7145
7159
|
if zip_file:
|
|
@@ -1600,6 +1600,9 @@ BUILTIN_ESTIMATORS = {
|
|
|
1600
1600
|
'ols': 'Estimate_ols',
|
|
1601
1601
|
'nls_lmfit': 'Estimate_nls_lmfit',
|
|
1602
1602
|
'nls_eviews': 'Estimate_nls_eviews',
|
|
1603
|
+
# R as the estimation engine (modelestimator_r); method lm / nls by default
|
|
1604
|
+
'r_lm': 'Estimate_r_lm',
|
|
1605
|
+
'r_nls': 'Estimate_r_nls',
|
|
1603
1606
|
}
|
|
1604
1607
|
|
|
1605
1608
|
|
|
@@ -1650,6 +1653,11 @@ def _get_estimator_class(estimator_name, estimator_classes: Optional[dict] = Non
|
|
|
1650
1653
|
"Equations with <estimator=...> require modelestimator_new to be importable."
|
|
1651
1654
|
) from exc
|
|
1652
1655
|
|
|
1656
|
+
if class_names[name].startswith('Estimate_r_'):
|
|
1657
|
+
# The R backends live in their own module so modelestimator_new
|
|
1658
|
+
# does not depend on them.
|
|
1659
|
+
import modelestimator_r as me
|
|
1660
|
+
|
|
1653
1661
|
try:
|
|
1654
1662
|
return getattr(me, class_names[name])
|
|
1655
1663
|
except AttributeError as exc:
|