ModelFlowIb 2.91__tar.gz → 2.93__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.91 → modelflowib-2.93}/PKG-INFO +1 -1
- {modelflowib-2.91 → modelflowib-2.93}/model_parquet_mixin.py +15 -4
- {modelflowib-2.91 → modelflowib-2.93}/modelcausality.py +4 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelclass.py +80 -28
- {modelflowib-2.91 → modelflowib-2.93}/modelconstruct_estimation.py +3 -3
- modelflowib-2.93/modelfactorize.py +346 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelflowib.egg-info/PKG-INFO +1 -1
- {modelflowib-2.91 → modelflowib-2.93}/modelflowib.egg-info/SOURCES.txt +2 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelflowib.egg-info/top_level.txt +2 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelhelp.py +17 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelnewton.py +50 -1
- modelflowib-2.93/modelode.py +552 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelsolver_ng.py +99 -25
- {modelflowib-2.91 → modelflowib-2.93}/pyproject.toml +3 -3
- {modelflowib-2.91 → modelflowib-2.93}/README.md +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/license.md +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelBLfunk.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/model_Excel.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/model_cvx.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/model_dynare.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/model_financial_stability.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/model_latex.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/model_latex_class.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelconstruct.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeldash.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeldashboot.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeldashsidebar.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeldekom.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeldiff.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeldisplay.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelestimation.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelestimator_new.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelflowib.egg-info/dependency_links.txt +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelflowib.egg-info/requires.txt +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelgrab.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelgrabexcel.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelgrabgdx.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelgrabgekkobank.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelgrabwf2.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelhtml.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelinput_shiny.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelinvert.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeljupyter.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeljupytermagic.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelmacrograb.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelmanipulation.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelmf.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelnet.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelnormalize.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelpattern.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelreport.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modeluserfunk.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelvis.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelwidget.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelwidget_core.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/modelwidget_input.py +0 -0
- {modelflowib-2.91 → modelflowib-2.93}/setup.cfg +0 -0
|
@@ -164,7 +164,7 @@ class Parquet_Mixin:
|
|
|
164
164
|
|
|
165
165
|
# ── dump ──────────────────────────────────────────────────────────────
|
|
166
166
|
|
|
167
|
-
def modeldump(self, file_path='', keep=False, large=False, compact=False, **kwargs):
|
|
167
|
+
def modeldump(self, file_path='', keep=False, large=False, compact=False, derivatives=False, **kwargs):
|
|
168
168
|
"""Dump model to disk.
|
|
169
169
|
|
|
170
170
|
Parameters
|
|
@@ -181,6 +181,12 @@ class Parquet_Mixin:
|
|
|
181
181
|
If True (only effective when large=True), store float64
|
|
182
182
|
columns as float32 to roughly halve file size.
|
|
183
183
|
On load the data is restored to float64.
|
|
184
|
+
derivatives : bool
|
|
185
|
+
If True, also store the expressions for the derivatives that a Newton
|
|
186
|
+
solver has found (``model.diff_expressions``). A Newton solver in a later
|
|
187
|
+
session takes them from the model instead of finding them again, which is
|
|
188
|
+
the slow part of its first solve for a large model. They are used only if
|
|
189
|
+
the equations and the solver options are the same.
|
|
184
190
|
|
|
185
191
|
A model instance without a lastdf holds no dataframe, so the feather
|
|
186
192
|
format has nothing to be fast about. Such a model is always written as a
|
|
@@ -194,7 +200,7 @@ class Parquet_Mixin:
|
|
|
194
200
|
|
|
195
201
|
if not large or nodata:
|
|
196
202
|
# ── original JSON/gzip path ──────────────────────────────────
|
|
197
|
-
return super().modeldump(file_path=file_path, keep=keep, **kwargs)
|
|
203
|
+
return super().modeldump(file_path=file_path, keep=keep, derivatives=derivatives, **kwargs)
|
|
198
204
|
|
|
199
205
|
# ── fast feather/zip path ────────────────────────────────────────
|
|
200
206
|
pathname = Path(file_path)
|
|
@@ -216,8 +222,10 @@ class Parquet_Mixin:
|
|
|
216
222
|
'format': 'feather_zip',
|
|
217
223
|
'frml': self.equations,
|
|
218
224
|
'modelname': self.name,
|
|
219
|
-
'oldkwargs': self.oldkwargs,
|
|
225
|
+
'oldkwargs': self.__dict__.get('oldkwargs', {}), # a model never solved has none
|
|
220
226
|
'run_on_load': self.__dict__.get('run_on_load', False),
|
|
227
|
+
'straight': bool(self.__dict__.get('straight', False)), # loads the same way again
|
|
228
|
+
'diff_expressions': self.__dict__.get('diff_expressions', {}) if derivatives else {},
|
|
221
229
|
'var_description': self.var_description,
|
|
222
230
|
'equations_latex': self.equations_latex,
|
|
223
231
|
'wb_MFMSAOPTIONS': (
|
|
@@ -383,8 +391,11 @@ class Parquet_Mixin:
|
|
|
383
391
|
# while threads work, build the model object (parses equations)
|
|
384
392
|
frml = meta['frml']
|
|
385
393
|
modelname = meta['modelname']
|
|
386
|
-
|
|
394
|
+
# a model dumped with straight=True is loaded like that, unless the call says otherwise
|
|
395
|
+
model_kwargs = {**({'straight': True} if meta.get('straight', False) else {}), **kwargs}
|
|
396
|
+
mmodel = cls(frml, modelname=modelname, funks=funks, **model_kwargs)
|
|
387
397
|
mmodel.oldkwargs = meta.get('oldkwargs', {})
|
|
398
|
+
mmodel.diff_expressions = meta.get('diff_expressions', {})
|
|
388
399
|
mmodel.run_on_load = meta.get('run_on_load', False)
|
|
389
400
|
if run is None:
|
|
390
401
|
run = mmodel.run_on_load
|
|
@@ -736,6 +736,10 @@ if AnyWidget is not None:
|
|
|
736
736
|
self.observe(self._refresh, names=self._settings)
|
|
737
737
|
self._refresh()
|
|
738
738
|
|
|
739
|
+
def __repr__(self):
|
|
740
|
+
# the text/plain output, shown where the widget is not run (a static book)
|
|
741
|
+
return f'Interactive causality viewer for {self.var}, run the notebook to use it'
|
|
742
|
+
|
|
739
743
|
def _refresh(self, change=None):
|
|
740
744
|
navn = self.var.upper()
|
|
741
745
|
if navn not in self.mmodel.allvar:
|
|
@@ -116,6 +116,7 @@ from modelhelp import cutout, update_var
|
|
|
116
116
|
from modelnormalize import normal
|
|
117
117
|
from modeldekom import totdif
|
|
118
118
|
from modelhelp import debug_var
|
|
119
|
+
from modelhelp import nonfinite_places
|
|
119
120
|
|
|
120
121
|
|
|
121
122
|
# functions used in BL language
|
|
@@ -1027,7 +1028,8 @@ class BaseModel():
|
|
|
1027
1028
|
convergence = True
|
|
1028
1029
|
for after, before in zip(itafter, itbefore):
|
|
1029
1030
|
# print(before,after)
|
|
1030
|
-
|
|
1031
|
+
# NaN fails before > absconv, so it has to be tested on its own
|
|
1032
|
+
if not np.all(np.isfinite(after)) or (before > absconv and abs(after-before)/abs(before) > relconv):
|
|
1031
1033
|
convergence = False
|
|
1032
1034
|
break
|
|
1033
1035
|
if convergence:
|
|
@@ -2105,13 +2107,16 @@ class Model_help_Mixin():
|
|
|
2105
2107
|
if nofit and v.endswith('_FITTED'): continue
|
|
2106
2108
|
check = self.get_values(v,pct=True).T
|
|
2107
2109
|
check.columns = ['Before check','After calculation','Difference','Pct']
|
|
2108
|
-
|
|
2110
|
+
# NaN >= tol is False, so a calculated NaN has to be caught separately
|
|
2111
|
+
isnan = check['After calculation'].isna()
|
|
2112
|
+
if (check.Difference.abs() >= tol).any() or isnan.any():
|
|
2109
2113
|
err=err+1
|
|
2110
2114
|
maxdiff = check.Difference.abs().max()
|
|
2111
2115
|
maxpct = check.Pct.abs().max()
|
|
2116
|
+
nantext = f' NaN in {isnan.sum()} periods from {check.index[isnan][0]}' if isnan.any() else ''
|
|
2112
2117
|
if err==1 :
|
|
2113
|
-
print('\nVariable with residuals above threshold')
|
|
2114
|
-
print(f"{v:{self.maxnavlen}}, Max difference:{maxdiff:15.8f} Max Pct {maxpct:15.10f}% It is number {i:5} in the solveorder and error number {err}")
|
|
2118
|
+
print('\nVariable with residuals above threshold or NaN result')
|
|
2119
|
+
print(f"{v:{self.maxnavlen}}, Max difference:{maxdiff:15.8f} Max Pct {maxpct:15.10f}% It is number {i:5} in the solveorder and error number {err}{nantext}")
|
|
2115
2120
|
if showall:
|
|
2116
2121
|
print(f'{self.allvar[v]["frml"]}')
|
|
2117
2122
|
print(f'{self.var_description[v]}')
|
|
@@ -3171,7 +3176,7 @@ class Description_Mixin():
|
|
|
3171
3176
|
out = (ind.replace('&','&').replace('<', '<').replace('>', '>').replace('\n', ' ')
|
|
3172
3177
|
.replace('æ', 'æ').replace('ø', 'ø').replace('å', 'å')
|
|
3173
3178
|
.replace('Æ', 'Æ').replace('Ø', 'Ø').replace('Å', 'Å')
|
|
3174
|
-
.replace('$','$')
|
|
3179
|
+
.replace('$','$').replace('"', '"')
|
|
3175
3180
|
)
|
|
3176
3181
|
return out
|
|
3177
3182
|
|
|
@@ -6860,11 +6865,15 @@ class Json_Mixin():
|
|
|
6860
6865
|
|
|
6861
6866
|
return pathname, dump_data
|
|
6862
6867
|
|
|
6863
|
-
def modeldump_base(self, outfile='',keep=False,data=True):
|
|
6868
|
+
def modeldump_base(self, outfile='',keep=False,data=True,derivatives=False):
|
|
6864
6869
|
'''Dumps a model and its lastdf to a json file
|
|
6865
6870
|
|
|
6866
6871
|
if keep=True the model.keep_solutions will alse be dumped
|
|
6867
6872
|
|
|
6873
|
+
if derivatives=True the expressions for the derivatives, which a Newton solver has found
|
|
6874
|
+
(model.diff_expressions), are dumped too. A Newton solver in a later session then takes them
|
|
6875
|
+
from the model instead of finding them again - the slow part of its first solve for a large model
|
|
6876
|
+
|
|
6868
6877
|
if data=False, or the model instance has no lastdf, only the model
|
|
6869
6878
|
structure is dumped and the file has no dataframes'''
|
|
6870
6879
|
# print('dump ready')
|
|
@@ -6925,6 +6934,8 @@ class Json_Mixin():
|
|
|
6925
6934
|
'modelname': self.name,
|
|
6926
6935
|
'oldkwargs': self.__dict__.get('oldkwargs',{}),
|
|
6927
6936
|
'run_on_load': self.__dict__.get('run_on_load', False),
|
|
6937
|
+
'straight': bool(self.__dict__.get('straight', False)), # loads the same way again
|
|
6938
|
+
'diff_expressions': self.__dict__.get('diff_expressions', {}) if derivatives else {},
|
|
6928
6939
|
'var_description': self.var_description,
|
|
6929
6940
|
'equations_latex': self.equations_latex ,
|
|
6930
6941
|
'keep_solutions': {k:v.to_json(double_precision=15) for k,v in self.keep_solutions.items()} if (keep and dump_data) else {},
|
|
@@ -7062,8 +7073,11 @@ class Json_Mixin():
|
|
|
7062
7073
|
current_per = None
|
|
7063
7074
|
modelname = input['modelname']
|
|
7064
7075
|
# breakpoint()
|
|
7065
|
-
|
|
7076
|
+
# a model dumped with straight=True is loaded like that, unless the call says otherwise
|
|
7077
|
+
model_kwargs = {**({'straight': True} if input.get('straight', False) else {}), **kwargs}
|
|
7078
|
+
mmodel = cls(frml, modelname=modelname, funks=funks,**model_kwargs)
|
|
7066
7079
|
mmodel.oldkwargs = input.get('oldkwargs',{})
|
|
7080
|
+
mmodel.diff_expressions = input.get('diff_expressions', {})
|
|
7067
7081
|
mmodel.run_on_load = input.get('run_on_load', False)
|
|
7068
7082
|
if run is None:
|
|
7069
7083
|
run = mmodel.run_on_load and has_data
|
|
@@ -7120,12 +7134,12 @@ class Json_Mixin():
|
|
|
7120
7134
|
|
|
7121
7135
|
class Zip_Mixin():
|
|
7122
7136
|
'''This experimental class zips a dumped file '''
|
|
7123
|
-
def modeldump(self, file_path='',keep=False,zip_file=True,data=True):
|
|
7137
|
+
def modeldump(self, file_path='',keep=False,zip_file=True,data=True,derivatives=False):
|
|
7124
7138
|
pathname, dump_data = self._dump_pathname(file_path, self.has_data, data=data)
|
|
7125
7139
|
|
|
7126
7140
|
pathname.parent.mkdir(parents=True, exist_ok=True)
|
|
7127
7141
|
|
|
7128
|
-
json_string = self.modeldump_base(keep=keep,data=dump_data)
|
|
7142
|
+
json_string = self.modeldump_base(keep=keep,data=dump_data,derivatives=derivatives)
|
|
7129
7143
|
|
|
7130
7144
|
|
|
7131
7145
|
if zip_file:
|
|
@@ -7637,7 +7651,8 @@ class Solver_Mixin():
|
|
|
7637
7651
|
# this is how convergence is measured
|
|
7638
7652
|
convplace = [databank.columns.get_loc(c) for c in convvar]
|
|
7639
7653
|
convergence = True
|
|
7640
|
-
|
|
7654
|
+
endovar = list(self.endogene)
|
|
7655
|
+
endoplace = [databank.columns.get_loc(c) for c in endovar]
|
|
7641
7656
|
# breakpoint()
|
|
7642
7657
|
if ldumpvar:
|
|
7643
7658
|
self.dumplist = []
|
|
@@ -7665,6 +7680,7 @@ class Solver_Mixin():
|
|
|
7665
7680
|
values[row, c] = values[row-1, c]
|
|
7666
7681
|
itbefore = values[row, convplace]
|
|
7667
7682
|
self.pro2d(values, values, row, 1.0)
|
|
7683
|
+
corenan = False
|
|
7668
7684
|
for iteration in range(max_iterations):
|
|
7669
7685
|
with self.timer(f'Evaluate {self.periode}/{iteration} ', timeon) as t:
|
|
7670
7686
|
self.solve2d(values, values, row, alfa)
|
|
@@ -7676,18 +7692,30 @@ class Solver_Mixin():
|
|
|
7676
7692
|
if iteration > first_test:
|
|
7677
7693
|
itafter = values[row, convplace]
|
|
7678
7694
|
select = absconv <= np.abs(itbefore)
|
|
7695
|
+
# NaN drops out of select, so it has to be tested on its own
|
|
7696
|
+
nonfinite = nonfinite_places(itafter)
|
|
7679
7697
|
convergence = (
|
|
7680
|
-
np.abs((itafter-itbefore)[select])/np.abs(itbefore[select]) <= relconv).all()
|
|
7698
|
+
np.abs((itafter-itbefore)[select])/np.abs(itbefore[select]) <= relconv).all() and not len(nonfinite)
|
|
7681
7699
|
if convergence:
|
|
7682
7700
|
if not silent:
|
|
7683
7701
|
print(
|
|
7684
7702
|
f'{self.periode} Solved in {iteration} iterations')
|
|
7685
7703
|
break
|
|
7704
|
+
if len(nonfinite):
|
|
7705
|
+
corenan = True
|
|
7706
|
+
bad = [convvar[i] for i in nonfinite]
|
|
7707
|
+
print(f"{self.periode} not converged, NaN or inf in {len(bad)} variables after {iteration} iterations: {' '.join(bad[:10])}{' ...' if len(bad) > 10 else ''}")
|
|
7708
|
+
break
|
|
7686
7709
|
itbefore = itafter
|
|
7687
7710
|
else:
|
|
7688
7711
|
print(f'{self.periode} not converged in {iteration} iterations')
|
|
7689
|
-
|
|
7712
|
+
|
|
7690
7713
|
self.epi2d(values, values, row, 1.0)
|
|
7714
|
+
# the convergence test only sees the core, prolog/epilog can also be NaN
|
|
7715
|
+
nonfinite = nonfinite_places(values[row, endoplace])
|
|
7716
|
+
if len(nonfinite) and not corenan:
|
|
7717
|
+
bad = [endovar[i] for i in nonfinite]
|
|
7718
|
+
print(f"{self.periode} NaN or inf in {len(bad)} endogenous variables: {' '.join(bad[:10])}{' ...' if len(bad) > 10 else ''}")
|
|
7691
7719
|
pbar.update()
|
|
7692
7720
|
endtime = time.time()
|
|
7693
7721
|
|
|
@@ -7972,7 +8000,8 @@ class Solver_Mixin():
|
|
|
7972
8000
|
# convplace=[databank.columns.get_loc(c) for c in convvar] # this is how convergence is measured
|
|
7973
8001
|
convplace = [self.allvar[c]['startnr'] -
|
|
7974
8002
|
self.allvar[c]['maxlead'] for c in convvar]
|
|
7975
|
-
|
|
8003
|
+
endovar = list(self.endogene)
|
|
8004
|
+
endoplace = [databank.columns.get_loc(c) for c in endovar]
|
|
7976
8005
|
|
|
7977
8006
|
convergence = True
|
|
7978
8007
|
|
|
@@ -8007,6 +8036,7 @@ class Solver_Mixin():
|
|
|
8007
8036
|
itbeforeold = [a[c] for c in convplace]
|
|
8008
8037
|
itbefore = a[convplace]
|
|
8009
8038
|
this_pro1d(a, 1.0)
|
|
8039
|
+
corenan = False
|
|
8010
8040
|
for iteration in range(max_iterations):
|
|
8011
8041
|
with self.timer(f'Evaluate {self.periode}/{iteration} ', timeon) as t:
|
|
8012
8042
|
this_solve1d(a, alfa)
|
|
@@ -8019,20 +8049,32 @@ class Solver_Mixin():
|
|
|
8019
8049
|
itafter = a[convplace]
|
|
8020
8050
|
# breakpoint()
|
|
8021
8051
|
select = absconv <= np.abs(itbefore)
|
|
8052
|
+
# NaN drops out of select, so it has to be tested on its own
|
|
8053
|
+
nonfinite = nonfinite_places(itafter)
|
|
8022
8054
|
convergence = (
|
|
8023
|
-
np.abs((itafter-itbefore)[select])/np.abs(itbefore[select]) <= relconv).all()
|
|
8055
|
+
np.abs((itafter-itbefore)[select])/np.abs(itbefore[select]) <= relconv).all() and not len(nonfinite)
|
|
8024
8056
|
if convergence:
|
|
8025
8057
|
if not silent:
|
|
8026
8058
|
print(
|
|
8027
8059
|
f'{self.periode} Solved in {iteration} iterations')
|
|
8028
8060
|
break
|
|
8061
|
+
if len(nonfinite):
|
|
8062
|
+
corenan = True
|
|
8063
|
+
bad = [convvar[i] for i in nonfinite]
|
|
8064
|
+
print(f"{self.periode} not converged, NaN or inf in {len(bad)} variables after {iteration} iterations: {' '.join(bad[:10])}{' ...' if len(bad) > 10 else ''}")
|
|
8065
|
+
break
|
|
8029
8066
|
itbefore = itafter
|
|
8030
8067
|
else:
|
|
8031
8068
|
print(f'{self.periode} not converged in {iteration} iterations')
|
|
8032
|
-
|
|
8069
|
+
|
|
8033
8070
|
this_epi1d(a, 1.0)
|
|
8034
8071
|
|
|
8035
8072
|
self.saveeval3(values, row, a)
|
|
8073
|
+
# the convergence test only sees the core, prolog/epilog can also be NaN
|
|
8074
|
+
nonfinite = nonfinite_places(values[row, endoplace])
|
|
8075
|
+
if len(nonfinite) and not corenan:
|
|
8076
|
+
bad = [endovar[i] for i in nonfinite]
|
|
8077
|
+
print(f"{self.periode} NaN or inf in {len(bad)} endogenous variables: {' '.join(bad[:10])}{' ...' if len(bad) > 10 else ''}")
|
|
8036
8078
|
|
|
8037
8079
|
if ldumpvar:
|
|
8038
8080
|
self.dumpdf = pd.DataFrame(self.dumplist)
|
|
@@ -9614,9 +9656,23 @@ class Solver_Mixin():
|
|
|
9614
9656
|
|
|
9615
9657
|
def errfunk(self, values, linenr, overhead=4, overeq=0):
|
|
9616
9658
|
'''Development function to handle run time errors in model calculations'''
|
|
9617
|
-
|
|
9659
|
+
|
|
9618
9660
|
import pandas as pd
|
|
9619
|
-
|
|
9661
|
+
|
|
9662
|
+
if getattr(self, 'errfunk_defer', False):
|
|
9663
|
+
# a Newton trial step: keep the error point, the solver dumps it only if it gives up
|
|
9664
|
+
self.errfunk_deferred = (values.copy(), linenr, overhead, overeq)
|
|
9665
|
+
return
|
|
9666
|
+
|
|
9667
|
+
if hasattr(self, 'dumplist'):
|
|
9668
|
+
# first, so the returns below keep it, and it must never mask the real error
|
|
9669
|
+
dumplist = self.dumplist
|
|
9670
|
+
del self.dumplist
|
|
9671
|
+
try:
|
|
9672
|
+
self.dumpdf = pd.DataFrame(dumplist, columns=['fair', 'per', 'iteration'] + list(self.dump))
|
|
9673
|
+
except Exception as e:
|
|
9674
|
+
print('>> Could not build .dumpdf:', e)
|
|
9675
|
+
|
|
9620
9676
|
def find_log_arguments(text):
|
|
9621
9677
|
"""Return all arguments inside balanced LOG(...) calls."""
|
|
9622
9678
|
out = []
|
|
@@ -9663,7 +9719,8 @@ class Solver_Mixin():
|
|
|
9663
9719
|
outeq = self.allvar[errvar]['frml']
|
|
9664
9720
|
|
|
9665
9721
|
print('>>:', outeq,)
|
|
9666
|
-
|
|
9722
|
+
per = getattr(self, 'periode', None) # not set if the error comes before the period loop
|
|
9723
|
+
print('In:', per if per is not None else 'unknown period', '\n')
|
|
9667
9724
|
print('Below you will find information which might help you identify the problem')
|
|
9668
9725
|
terms = self.allvar[errvar]['terms']
|
|
9669
9726
|
|
|
@@ -9676,7 +9733,7 @@ class Solver_Mixin():
|
|
|
9676
9733
|
|
|
9677
9734
|
|
|
9678
9735
|
try:
|
|
9679
|
-
basepos = self.errdump.index.get_loc(
|
|
9736
|
+
basepos = self.errdump.index.get_loc(per)
|
|
9680
9737
|
rows = []
|
|
9681
9738
|
seen = set()
|
|
9682
9739
|
|
|
@@ -9715,8 +9772,8 @@ class Solver_Mixin():
|
|
|
9715
9772
|
for arg in log_args:
|
|
9716
9773
|
try:
|
|
9717
9774
|
val = self.errdump.mfcalc(
|
|
9718
|
-
f'<{
|
|
9719
|
-
).loc[
|
|
9775
|
+
f'<{per}> {tmpvar} = {arg}'
|
|
9776
|
+
).loc[per, tmpvar]
|
|
9720
9777
|
status = 'Bad log argument' if pd.isna(val) or val <= 0 else 'ok'
|
|
9721
9778
|
except Exception:
|
|
9722
9779
|
val = ''
|
|
@@ -9732,13 +9789,8 @@ class Solver_Mixin():
|
|
|
9732
9789
|
|
|
9733
9790
|
print('\nA snapshot of the data at the error point is at .errdump')
|
|
9734
9791
|
print('Also .lastdf contains a copy of .errdump for inspecting')
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
self.dumpdf = pd.DataFrame(self.dumplist)
|
|
9738
|
-
del self.dumplist
|
|
9739
|
-
self.dumpdf.columns = ['fair', 'per', 'iteration'] + self.dump
|
|
9740
|
-
|
|
9741
|
-
|
|
9792
|
+
|
|
9793
|
+
|
|
9742
9794
|
def show_iterations(self, pat='*', per='', last=0, change=False,top=.9):
|
|
9743
9795
|
'''
|
|
9744
9796
|
shows the last iterations for the most recent simulation.
|
|
@@ -598,14 +598,14 @@ def eviews_to_modelflow(stmt: str, behavioral_opts: str = '<>') -> str:
|
|
|
598
598
|
|
|
599
599
|
``@IDENTITY`` equations get ``<>``, all other equations get
|
|
600
600
|
``behavioral_opts`` (for instance ``'<STOC>'``). EViews functions are
|
|
601
|
-
translated with :meth:`modelgrabwf2.
|
|
601
|
+
translated with :meth:`modelgrabwf2.GrabWfModel.trans_eviews`
|
|
602
602
|
(``D(`` -> ``DIFF(``, ``@PC`` -> ``PCT_GROWTH``, ``^`` -> ``**`` ...).
|
|
603
603
|
"""
|
|
604
|
-
from modelgrabwf2 import
|
|
604
|
+
from modelgrabwf2 import GrabWfModel
|
|
605
605
|
|
|
606
606
|
m = re.match(r'\s*@IDENTITY\s+(.*)', stmt, flags=re.IGNORECASE | re.DOTALL)
|
|
607
607
|
opts, body = ('<>', m.group(1)) if m else (behavioral_opts, stmt)
|
|
608
|
-
return f'{opts} {
|
|
608
|
+
return f'{opts} {GrabWfModel.trans_eviews(body).strip()}'
|
|
609
609
|
|
|
610
610
|
|
|
611
611
|
# type_input presets for Makemodel; explicit eq_start/eq_end/comment_start/transform win
|