ModelFlowIb 2.71__tar.gz → 2.72__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.71 → modelflowib-2.72}/ModelFlowIb.egg-info/PKG-INFO +1 -1
- {modelflowib-2.71 → modelflowib-2.72}/ModelFlowIb.egg-info/SOURCES.txt +2 -0
- {modelflowib-2.71 → modelflowib-2.72}/ModelFlowIb.egg-info/top_level.txt +2 -0
- {modelflowib-2.71 → modelflowib-2.72}/PKG-INFO +1 -1
- {modelflowib-2.71 → modelflowib-2.72}/modelclass.py +75 -25
- {modelflowib-2.71 → modelflowib-2.72}/modelconstruct.py +94 -7
- modelflowib-2.72/modelconstruct_estimation.py +2829 -0
- modelflowib-2.72/modelestimator_new.py +2608 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeljupytermagic.py +104 -92
- {modelflowib-2.71 → modelflowib-2.72}/modelmf.py +135 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelpattern.py +48 -24
- modelflowib-2.72/pyproject.toml +46 -0
- modelflowib-2.71/pyproject.toml +0 -46
- {modelflowib-2.71 → modelflowib-2.72}/ModelFlowIb.egg-info/dependency_links.txt +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/ModelFlowIb.egg-info/requires.txt +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelBLfunk.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_Excel.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_cvx.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_doable.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_dynare.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_financial_stability.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_ifrs9.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_latex.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_latex_class.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_parquet_mixin.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/model_run_numba.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelclass2.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeldash.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeldashboot.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeldashsidebar.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeldekom.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeldiff.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeldisplay.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelestimation.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelfeedback.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelgrab.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelgrabgdx.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelgrabwf2.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelhelp.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelinvert.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeljupyter.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelmacrograb.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelmanipulation.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelnet.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelnewton.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelnormalize.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelpatternrev.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelreport.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelsandbox.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelsandbox_Mixin.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeltodo.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeluserfunk.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modeluserfunk_old.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelvis.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelwidget.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelwidget_input.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelwidget_input_old.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/modelwidget_shinypy.py +0 -0
- {modelflowib-2.71 → modelflowib-2.72}/setup.cfg +0 -0
|
@@ -12,6 +12,7 @@ model_run_numba.py
|
|
|
12
12
|
modelclass.py
|
|
13
13
|
modelclass2.py
|
|
14
14
|
modelconstruct.py
|
|
15
|
+
modelconstruct_estimation.py
|
|
15
16
|
modeldash.py
|
|
16
17
|
modeldashboot.py
|
|
17
18
|
modeldashsidebar.py
|
|
@@ -19,6 +20,7 @@ modeldekom.py
|
|
|
19
20
|
modeldiff.py
|
|
20
21
|
modeldisplay.py
|
|
21
22
|
modelestimation.py
|
|
23
|
+
modelestimator_new.py
|
|
22
24
|
modelfeedback.py
|
|
23
25
|
modelgrab.py
|
|
24
26
|
modelgrabgdx.py
|
|
@@ -13,6 +13,7 @@ model_run_numba
|
|
|
13
13
|
modelclass
|
|
14
14
|
modelclass2
|
|
15
15
|
modelconstruct
|
|
16
|
+
modelconstruct_estimation
|
|
16
17
|
modeldash
|
|
17
18
|
modeldashboot
|
|
18
19
|
modeldashsidebar
|
|
@@ -20,6 +21,7 @@ modeldekom
|
|
|
20
21
|
modeldiff
|
|
21
22
|
modeldisplay
|
|
22
23
|
modelestimation
|
|
24
|
+
modelestimator_new
|
|
23
25
|
modelfeedback
|
|
24
26
|
modelgrab
|
|
25
27
|
modelgrabgdx
|
|
@@ -5910,48 +5910,98 @@ class Display_Mixin():
|
|
|
5910
5910
|
display(HTML(
|
|
5911
5911
|
f' <a href="{fname}" target="_blank">{name}</a>'))
|
|
5912
5912
|
|
|
5913
|
+
|
|
5913
5914
|
@staticmethod
|
|
5914
5915
|
def widescreen():
|
|
5915
|
-
'''
|
|
5916
|
+
'''Make the notebook use more of the available browser width.
|
|
5917
|
+
|
|
5918
|
+
Works on Classic Notebook (<=6), Jupyter Notebook 7, and JupyterLab.
|
|
5916
5919
|
'''
|
|
5917
5920
|
from IPython.display import HTML, display
|
|
5918
|
-
display(HTML(
|
|
5919
|
-
<style>
|
|
5920
|
-
|
|
5921
|
-
div#
|
|
5922
|
-
div#
|
|
5921
|
+
display(HTML("""
|
|
5922
|
+
<style id="mf-widescreen">
|
|
5923
|
+
/* Classic Notebook (<=6) */
|
|
5924
|
+
div#notebook-container { width: 95% !important; }
|
|
5925
|
+
div#menubar-container { width: 65% !important; }
|
|
5926
|
+
div#maintoolbar-container { width: 99% !important; }
|
|
5927
|
+
|
|
5928
|
+
/* Notebook 7 / JupyterLab */
|
|
5929
|
+
.jp-Notebook,
|
|
5930
|
+
.jp-WindowedPanel-outer,
|
|
5931
|
+
.jp-WindowedPanel-inner { max-width: none !important; }
|
|
5932
|
+
.jp-Notebook .jp-Cell { max-width: none !important; }
|
|
5933
|
+
/* Some themes constrain the notebook via a centered column: */
|
|
5934
|
+
.jp-NotebookPanel { max-width: none !important; }
|
|
5923
5935
|
</style>
|
|
5924
|
-
"""))
|
|
5936
|
+
"""))
|
|
5937
|
+
|
|
5938
|
+
|
|
5925
5939
|
|
|
5926
|
-
|
|
5927
5940
|
@staticmethod
|
|
5928
5941
|
def scroll_off():
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5942
|
+
"""Disable the 'scroll long outputs into a scrollbox' behavior.
|
|
5943
|
+
|
|
5944
|
+
Works on classic Jupyter Notebook (<=6), Jupyter Notebook 7,
|
|
5945
|
+
and JupyterLab. Silently does nothing on frontends where
|
|
5946
|
+
neither mechanism applies (e.g. VS Code, plain terminal).
|
|
5947
|
+
"""
|
|
5948
|
+
try:
|
|
5949
|
+
from IPython.display import display, Javascript, HTML
|
|
5950
|
+
|
|
5951
|
+
# Classic Notebook (<=6): IPython.OutputArea global exists.
|
|
5952
|
+
# Guarded so Notebook 7 / Lab don't throw 'IPython is not defined'.
|
|
5953
|
+
display(Javascript("""
|
|
5954
|
+
try {
|
|
5955
|
+
if (typeof IPython !== 'undefined'
|
|
5956
|
+
&& IPython.OutputArea
|
|
5957
|
+
&& IPython.OutputArea.prototype) {
|
|
5958
|
+
IPython.OutputArea.prototype._should_scroll =
|
|
5959
|
+
function(lines) { return false; };
|
|
5934
5960
|
}
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5961
|
+
} catch (e) { /* ignore */ }
|
|
5962
|
+
"""))
|
|
5963
|
+
|
|
5964
|
+
# Notebook 7 / JupyterLab: remove the scrolled-output max-height
|
|
5965
|
+
# and the scrolled modifier wherever it is applied.
|
|
5966
|
+
display(HTML("""
|
|
5967
|
+
<style id="mf-scroll-off">
|
|
5968
|
+
.jp-OutputArea-output.jp-OutputArea-output { max-height: none !important; }
|
|
5969
|
+
.jp-mod-outputsScrolled .jp-OutputArea-child {
|
|
5970
|
+
max-height: none !important;
|
|
5971
|
+
}
|
|
5972
|
+
</style>
|
|
5973
|
+
"""))
|
|
5974
|
+
except Exception as e:
|
|
5975
|
+
print(f'Error: {e}. Unable to turn off scrolling.')
|
|
5976
|
+
|
|
5977
|
+
|
|
5941
5978
|
@staticmethod
|
|
5942
5979
|
def scroll_on():
|
|
5980
|
+
"""Re-enable scrolled outputs. Inverse of scroll_off()."""
|
|
5943
5981
|
try:
|
|
5944
|
-
from IPython.display import display, Javascript
|
|
5982
|
+
from IPython.display import display, Javascript, HTML
|
|
5983
|
+
|
|
5945
5984
|
display(Javascript("""
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5985
|
+
try {
|
|
5986
|
+
if (typeof IPython !== 'undefined'
|
|
5987
|
+
&& IPython.OutputArea
|
|
5988
|
+
&& IPython.OutputArea.prototype) {
|
|
5989
|
+
IPython.OutputArea.prototype._should_scroll =
|
|
5990
|
+
function(lines) { return true; };
|
|
5991
|
+
}
|
|
5992
|
+
} catch (e) { /* ignore */ }
|
|
5993
|
+
"""))
|
|
5994
|
+
|
|
5995
|
+
# Remove the override stylesheet we injected above, if present.
|
|
5996
|
+
display(Javascript("""
|
|
5997
|
+
try {
|
|
5998
|
+
var s = document.getElementById('mf-scroll-off');
|
|
5999
|
+
if (s) { s.parentNode.removeChild(s); }
|
|
6000
|
+
} catch (e) { /* ignore */ }
|
|
5949
6001
|
"""))
|
|
5950
6002
|
except Exception as e:
|
|
5951
6003
|
print(f'Error: {e}. Unable to turn on scrolling.')
|
|
5952
6004
|
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
6005
|
@staticmethod
|
|
5956
6006
|
def modelflow_auto(run=True):
|
|
5957
6007
|
'''In a jupyter notebook this function activate autorun of the notebook.
|
|
@@ -18,7 +18,7 @@ import textwrap
|
|
|
18
18
|
|
|
19
19
|
from modelmanipulation import tofrml,dounloop, sumunroll
|
|
20
20
|
from modelpattern import find_statements,split_frml,find_frml,list_extract,udtryk_parse,kw_frml_name,commentchar,split_frml_reqopts,rebuild_list
|
|
21
|
-
from modelpattern import namepat
|
|
21
|
+
from modelpattern import namepat, check_syntax_model
|
|
22
22
|
from modelhelp import debug_var
|
|
23
23
|
from model_latex_class import a_latex_model,a_latex_equation,defrack, depower,debrace,defunk
|
|
24
24
|
from modelreport import LatexRepo
|
|
@@ -40,10 +40,17 @@ def clean_expressions(original_statements: str) -> str:
|
|
|
40
40
|
"""
|
|
41
41
|
import re
|
|
42
42
|
|
|
43
|
-
stmt_start = re.compile(r'^\s*(LIST|FRML|DO|ENDDO|DOABLE)\b')
|
|
43
|
+
stmt_start = re.compile(r'^\s*(LIST|TLIST|FRML|DO|ENDDO|DOABLE)\b')
|
|
44
44
|
|
|
45
45
|
def is_list_start(line: str) -> bool:
|
|
46
|
-
|
|
46
|
+
# Both LIST and TLIST start a list block. TLIST is the transposed
|
|
47
|
+
# form: the second "row" gives sublist names and values run down
|
|
48
|
+
# the columns. TLIST is converted to standard LIST during
|
|
49
|
+
# normalize_lists() so downstream code only ever sees LIST.
|
|
50
|
+
return bool(re.match(r'^\s*(LIST|TLIST)\b', line))
|
|
51
|
+
|
|
52
|
+
def is_tlist_start(line: str) -> bool:
|
|
53
|
+
return bool(re.match(r'^\s*TLIST\b', line))
|
|
47
54
|
|
|
48
55
|
def collect_list_block(lines, start_index):
|
|
49
56
|
"""
|
|
@@ -71,12 +78,88 @@ def clean_expressions(original_statements: str) -> str:
|
|
|
71
78
|
|
|
72
79
|
return '\n'.join(block_lines), j
|
|
73
80
|
|
|
81
|
+
def _convert_tlist_to_list(flat_no_dollar: str) -> str:
|
|
82
|
+
"""
|
|
83
|
+
Convert a flattened TLIST single-line form to standard LIST form.
|
|
84
|
+
|
|
85
|
+
Input (flat, no trailing '$'):
|
|
86
|
+
TLIST <name> = h1 h2 h3 / v11 v12 v13 / v21 v22 v23 / v31 v32 v33
|
|
87
|
+
|
|
88
|
+
Output:
|
|
89
|
+
LIST <name> = h1 : v11 v21 v31 / h2 : v12 v22 v32 / h3 : v13 v23 v33
|
|
90
|
+
|
|
91
|
+
The first '/'-separated chunk after '=' is the header row giving
|
|
92
|
+
sublist names. Each subsequent chunk is one tuple of values, one
|
|
93
|
+
value per sublist. Data therefore runs *down* the columns, hence
|
|
94
|
+
'transposed list'.
|
|
95
|
+
"""
|
|
96
|
+
# strip the leading TLIST keyword
|
|
97
|
+
m = re.match(r'^\s*TLIST\b\s*(.*)$', flat_no_dollar, flags=re.IGNORECASE)
|
|
98
|
+
if not m:
|
|
99
|
+
raise ModelSpecificationError(
|
|
100
|
+
f"Internal: _convert_tlist_to_list called on non-TLIST: {flat_no_dollar!r}"
|
|
101
|
+
)
|
|
102
|
+
body = m.group(1).strip()
|
|
103
|
+
|
|
104
|
+
if '=' not in body:
|
|
105
|
+
raise ModelSpecificationError(
|
|
106
|
+
f"TLIST is missing '=' between name and contents: {flat_no_dollar!r}"
|
|
107
|
+
)
|
|
108
|
+
list_name, rhs = body.split('=', 1)
|
|
109
|
+
list_name = list_name.strip()
|
|
110
|
+
if not list_name:
|
|
111
|
+
raise ModelSpecificationError(
|
|
112
|
+
f"TLIST has empty name: {flat_no_dollar!r}"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# split rows on '/'
|
|
116
|
+
raw_rows = [r.strip() for r in rhs.split('/')]
|
|
117
|
+
raw_rows = [r for r in raw_rows if r != '']
|
|
118
|
+
if len(raw_rows) < 2:
|
|
119
|
+
raise ModelSpecificationError(
|
|
120
|
+
f"TLIST {list_name} needs a header row and at least one value row "
|
|
121
|
+
f"(rows separated by '/'); got: {flat_no_dollar!r}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def tokens(row: str):
|
|
125
|
+
# split on whitespace or commas, drop empties
|
|
126
|
+
return [t for t in re.split(r'[\s,]+', row.strip()) if t != '']
|
|
127
|
+
|
|
128
|
+
header = tokens(raw_rows[0])
|
|
129
|
+
value_rows = [tokens(r) for r in raw_rows[1:]]
|
|
130
|
+
|
|
131
|
+
if not header:
|
|
132
|
+
raise ModelSpecificationError(
|
|
133
|
+
f"TLIST {list_name} has empty header row"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
ncols = len(header)
|
|
137
|
+
for k, vr in enumerate(value_rows, 1):
|
|
138
|
+
if len(vr) != ncols:
|
|
139
|
+
raise ModelSpecificationError(
|
|
140
|
+
f"TLIST {list_name}: value row {k} has {len(vr)} entries "
|
|
141
|
+
f"but header has {ncols} ({header})"
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# transpose: column j across all value rows becomes the j-th sublist
|
|
145
|
+
sublists = []
|
|
146
|
+
for j, sublist_name in enumerate(header):
|
|
147
|
+
col = [vr[j] for vr in value_rows]
|
|
148
|
+
sublists.append(f"{sublist_name} : {' '.join(col)}")
|
|
149
|
+
|
|
150
|
+
return f"LIST {list_name} = " + ' / '.join(sublists)
|
|
151
|
+
|
|
74
152
|
def normalize_list_block(block: str) -> str:
|
|
75
153
|
"""
|
|
76
|
-
Flatten one LIST block to a single line.
|
|
154
|
+
Flatten one LIST or TLIST block to a single line.
|
|
77
155
|
Preserve a trailing '$' if present in the original block.
|
|
156
|
+
|
|
157
|
+
TLIST blocks are transposed into the canonical LIST form here, so
|
|
158
|
+
every later stage (tofrml, list_extract, rebuild_list, ...) only
|
|
159
|
+
ever sees LIST.
|
|
78
160
|
"""
|
|
79
161
|
saw_dollar = bool(re.search(r'\$\s*$', block))
|
|
162
|
+
is_tlist = bool(re.match(r'^\s*TLIST\b', block))
|
|
80
163
|
|
|
81
164
|
flat = ' '.join(line.strip() for line in block.splitlines())
|
|
82
165
|
flat = re.sub(r'\s+', ' ', flat).strip()
|
|
@@ -85,6 +168,9 @@ def clean_expressions(original_statements: str) -> str:
|
|
|
85
168
|
flat = re.sub(r'\s*\$\s*$', '', flat)
|
|
86
169
|
flat = re.sub(r'\s*/\s*$', '', flat)
|
|
87
170
|
|
|
171
|
+
if is_tlist:
|
|
172
|
+
flat = _convert_tlist_to_list(flat)
|
|
173
|
+
|
|
88
174
|
if saw_dollar:
|
|
89
175
|
flat = flat + ' $'
|
|
90
176
|
|
|
@@ -1135,6 +1221,8 @@ class Mexplode(BaseExplode):
|
|
|
1135
1221
|
])
|
|
1136
1222
|
|
|
1137
1223
|
self.normal_frml = '\n'.join( [self.normal_main,self.normal_fit,self.normal_calc_add])
|
|
1224
|
+
|
|
1225
|
+
check_syntax_model(self.normal_frml)
|
|
1138
1226
|
|
|
1139
1227
|
self.list_specification = self.get_lists()
|
|
1140
1228
|
return
|
|
@@ -1404,6 +1492,5 @@ and yes
|
|
|
1404
1492
|
|
|
1405
1493
|
#%% latex
|
|
1406
1494
|
leq = r'CRF^{l,es,d}=\frac{DiscountRate^{l,es,d}}{1 - \left(1 + DiscountRate^{l,es,d}\right)^{-LifeSpan^{l,es,d}}}'
|
|
1407
|
-
meq = latex_to_doable('ii'
|
|
1408
|
-
print(meq)
|
|
1409
|
-
|
|
1495
|
+
meq = latex_to_doable(leq, '<ii>')
|
|
1496
|
+
print(meq)
|