ModelFlowIb 2.54__tar.gz → 2.56__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.
Files changed (51) hide show
  1. {modelflowib-2.54 → modelflowib-2.56}/ModelFlowIb.egg-info/PKG-INFO +1 -1
  2. {modelflowib-2.54 → modelflowib-2.56}/PKG-INFO +1 -1
  3. {modelflowib-2.54 → modelflowib-2.56}/modelclass.py +47 -38
  4. {modelflowib-2.54 → modelflowib-2.56}/modelreport.py +5 -2
  5. {modelflowib-2.54 → modelflowib-2.56}/pyproject.toml +1 -1
  6. {modelflowib-2.54 → modelflowib-2.56}/ModelFlowIb.egg-info/SOURCES.txt +0 -0
  7. {modelflowib-2.54 → modelflowib-2.56}/ModelFlowIb.egg-info/dependency_links.txt +0 -0
  8. {modelflowib-2.54 → modelflowib-2.56}/ModelFlowIb.egg-info/requires.txt +0 -0
  9. {modelflowib-2.54 → modelflowib-2.56}/ModelFlowIb.egg-info/top_level.txt +0 -0
  10. {modelflowib-2.54 → modelflowib-2.56}/modelBLfunk.py +0 -0
  11. {modelflowib-2.54 → modelflowib-2.56}/model_Excel.py +0 -0
  12. {modelflowib-2.54 → modelflowib-2.56}/model_cvx.py +0 -0
  13. {modelflowib-2.54 → modelflowib-2.56}/model_doable.py +0 -0
  14. {modelflowib-2.54 → modelflowib-2.56}/model_dynare.py +0 -0
  15. {modelflowib-2.54 → modelflowib-2.56}/model_financial_stability.py +0 -0
  16. {modelflowib-2.54 → modelflowib-2.56}/model_ifrs9.py +0 -0
  17. {modelflowib-2.54 → modelflowib-2.56}/model_latex.py +0 -0
  18. {modelflowib-2.54 → modelflowib-2.56}/model_latex_class.py +0 -0
  19. {modelflowib-2.54 → modelflowib-2.56}/model_run_numba.py +0 -0
  20. {modelflowib-2.54 → modelflowib-2.56}/modelclass2.py +0 -0
  21. {modelflowib-2.54 → modelflowib-2.56}/modeldash.py +0 -0
  22. {modelflowib-2.54 → modelflowib-2.56}/modeldashboot.py +0 -0
  23. {modelflowib-2.54 → modelflowib-2.56}/modeldashsidebar.py +0 -0
  24. {modelflowib-2.54 → modelflowib-2.56}/modeldekom.py +0 -0
  25. {modelflowib-2.54 → modelflowib-2.56}/modeldiff.py +0 -0
  26. {modelflowib-2.54 → modelflowib-2.56}/modeldisplay.py +0 -0
  27. {modelflowib-2.54 → modelflowib-2.56}/modelfeedback.py +0 -0
  28. {modelflowib-2.54 → modelflowib-2.56}/modelgrab.py +0 -0
  29. {modelflowib-2.54 → modelflowib-2.56}/modelgrabwf2.py +0 -0
  30. {modelflowib-2.54 → modelflowib-2.56}/modelhelp.py +0 -0
  31. {modelflowib-2.54 → modelflowib-2.56}/modelinvert.py +0 -0
  32. {modelflowib-2.54 → modelflowib-2.56}/modeljupyter.py +0 -0
  33. {modelflowib-2.54 → modelflowib-2.56}/modeljupytermagic.py +0 -0
  34. {modelflowib-2.54 → modelflowib-2.56}/modelmacrograb.py +0 -0
  35. {modelflowib-2.54 → modelflowib-2.56}/modelmanipulation.py +0 -0
  36. {modelflowib-2.54 → modelflowib-2.56}/modelmf.py +0 -0
  37. {modelflowib-2.54 → modelflowib-2.56}/modelnet.py +0 -0
  38. {modelflowib-2.54 → modelflowib-2.56}/modelnewton.py +0 -0
  39. {modelflowib-2.54 → modelflowib-2.56}/modelnormalize.py +0 -0
  40. {modelflowib-2.54 → modelflowib-2.56}/modelpattern.py +0 -0
  41. {modelflowib-2.54 → modelflowib-2.56}/modelpatternrev.py +0 -0
  42. {modelflowib-2.54 → modelflowib-2.56}/modelsandbox.py +0 -0
  43. {modelflowib-2.54 → modelflowib-2.56}/modelsandbox_Mixin.py +0 -0
  44. {modelflowib-2.54 → modelflowib-2.56}/modeltodo.py +0 -0
  45. {modelflowib-2.54 → modelflowib-2.56}/modeluserfunk.py +0 -0
  46. {modelflowib-2.54 → modelflowib-2.56}/modeluserfunk_old.py +0 -0
  47. {modelflowib-2.54 → modelflowib-2.56}/modelvis.py +0 -0
  48. {modelflowib-2.54 → modelflowib-2.56}/modelwidget.py +0 -0
  49. {modelflowib-2.54 → modelflowib-2.56}/modelwidget_input.py +0 -0
  50. {modelflowib-2.54 → modelflowib-2.56}/modelwidget_shinypy.py +0 -0
  51. {modelflowib-2.54 → modelflowib-2.56}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ModelFlowIb
3
- Version: 2.54
3
+ Version: 2.56
4
4
  Summary: A tool to solve and manage dynamic economic models
5
5
  Author-email: Ib Hansen <your@email.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ModelFlowIb
3
- Version: 2.54
3
+ Version: 2.56
4
4
  Summary: A tool to solve and manage dynamic economic models
5
5
  Author-email: Ib Hansen <your@email.com>
6
6
  License: MIT
@@ -332,8 +332,8 @@ class BaseModel():
332
332
  self.endogene_true = self.endogene if self.normalized else {
333
333
  v for v in self.exogene if v+'___RES' in self.endogene}
334
334
 
335
- self.check_endo_rhs()
336
- # dummy variables for variables for which to calculate adjustment variables
335
+ # self.check_endo_rhs()
336
+ # sdummy variables for variables for which to calculate adjustment variables
337
337
 
338
338
 
339
339
  self.fix_dummy = sorted(vx+'_D' for vx in self.endogene
@@ -1071,7 +1071,9 @@ class BaseModel():
1071
1071
  return '<\n'+out+'>'
1072
1072
 
1073
1073
  def check_endo_rhs(self):
1074
- if self.normalized:
1074
+ #breakpoint()
1075
+ if self.normalized and not self.istopo:
1076
+ errors = []
1075
1077
  for i,endovar in enumerate(sorted(self.endogene)):
1076
1078
  if i >= 2000000000000000 :break
1077
1079
  this_term = self.allvar[endovar]['terms']
@@ -1079,12 +1081,11 @@ class BaseModel():
1079
1081
  lhs = {t.var for t in this_term[:ap] if t.var}
1080
1082
  rhs_nolag = {t.var for t in this_term[ap:] if t.var and not t.lag}
1081
1083
  both = lhs & rhs_nolag
1082
- if both:
1083
- print('\n\n*** PROBLEM **')
1084
- print(self.allvar[endovar]['frml'])
1085
- raise Exception (f'ERROR in frml for {endovar} this is on right hand side un-lagged {both}')
1086
-
1087
-
1084
+ if both:
1085
+ errors = errors + [f"{endovar} in: {self.allvar[endovar]['frml']}"]
1086
+ if errors:
1087
+ print('Potential problem in model, Left hand side unlagged on right hand')
1088
+ print(*errors,sep='\n')
1088
1089
  class Org_model_Mixin():
1089
1090
  ''' This mixin enrich the Basemodel class with different utility methods.
1090
1091
 
@@ -4938,14 +4939,14 @@ class Display_Mixin():
4938
4939
  return
4939
4940
  allvars = list({c for k, df in self.keep_solutions.items()
4940
4941
  for c in df.columns})
4941
- vars = self.vlist_names(allvars, pat)
4942
+ _vars = self.vlist_names(allvars, pat)
4942
4943
  res = {}
4943
4944
  with self.set_smpl(start, end) as a, self.set_smpl_relative(start_ofset, end_ofset):
4944
4945
  # print(f'{self.current_per[-1]=}')
4945
4946
  for solver, solution in self.keep_solutions.items():
4946
- outv = pd.concat([solution.loc[self.current_per, v] for v in vars ], axis=1)
4947
+ outv = pd.concat([solution.loc[self.current_per, v] for v in _vars ], axis=1)
4947
4948
  if trans:
4948
- outv.columns = [self.var_description[v] for v in vars]
4949
+ outv.columns = [self.var_description[v] for v in _vars]
4949
4950
  outv.columns.names = ['Variable']
4950
4951
  res[solver] = outv
4951
4952
  return res
@@ -4972,10 +4973,12 @@ class Display_Mixin():
4972
4973
  return
4973
4974
  allvars = list({c for k, df in self.keep_solutions.items()
4974
4975
  for c in df.columns})
4975
- vars = self.vlist_names(allvars, pat)
4976
+ _vars = self.vlist_names(allvars, pat)
4977
+ # print(f'xx {pat=} {vars=} {allvars=}')
4978
+
4976
4979
  res = {}
4977
4980
  with self.set_smpl(start, end) as a, self.set_smpl_relative(start_ofset, end_ofset):
4978
- for v in vars:
4981
+ for v in _vars:
4979
4982
  # print(f'{v=}')
4980
4983
  outv = pd.concat([solution.loc[self.current_per, v]
4981
4984
  for solver, solution in self.keep_solutions.items()], axis=1)
@@ -5070,6 +5073,7 @@ class Display_Mixin():
5070
5073
 
5071
5074
  """
5072
5075
  # breakpoint()
5076
+ # print(f'{pat=}')
5073
5077
  if showtype == 'growth':
5074
5078
  start_ofset = -1
5075
5079
  else:
@@ -5080,7 +5084,8 @@ class Display_Mixin():
5080
5084
  else:
5081
5085
  dfs = self.keep_var_dict(pat, start, end, start_ofset, trans=False)
5082
5086
 
5083
-
5087
+ # print(f'{dfs=}')
5088
+
5084
5089
  if showtype == 'growth':
5085
5090
  dfs = {v: vdf.astype('float').pct_change()*100. for v, vdf in dfs.items()}
5086
5091
 
@@ -6100,6 +6105,7 @@ class Json_Mixin():
6100
6105
  mmodel.current_per = current_per
6101
6106
  mmodel.basedf = lastdf.copy()
6102
6107
  return mmodel, lastdf
6108
+ mmodel.check_endo_rhs
6103
6109
 
6104
6110
  class Zip_Mixin():
6105
6111
  '''This experimental class zips a dumped file '''
@@ -8760,8 +8766,8 @@ if __name__ == '__main__':
8760
8766
  #%% test
8761
8767
  smallmodel = '''
8762
8768
  frml <> a = c + b $
8763
- frml <> d1 = x + 3 * a(-1)+ c **2 +a $
8764
- frml <> d3 = x + 3 * a(-1)+c **3 $
8769
+ frml <> d1 = x + 3 * a(-1)+ c **2 +a+ d3 $
8770
+ frml <> d3 = x + 3 * a(-1)+c **3 +d1 + d3 $
8765
8771
  Frml <> xx = 0.5 * c +a$
8766
8772
  frml <CALC_ADJUST> a_a = a-(c+b)$
8767
8773
  frml <CALC_ADJUST> b_a = a-(c+b)$'''
@@ -8769,24 +8775,27 @@ frml <CALC_ADJUST> b_a = a-(c+b)$'''
8769
8775
  'X': 'Eksport <æøåÆØÅ>;',
8770
8776
  'C': 'Forbrug'}
8771
8777
  mmodel = model(smallmodel, var_description=des, svg=1, browser=1)
8772
- df = pd.DataFrame(
8773
- {'X': [0.2, 0.2, 0.2], 'C': [2.0, 3., 5.],'R': [2., 1., 0.4],
8774
- 'PPP': [0.4, 0., 0.4]})
8775
- df2 = df.copy()
8776
- df2.loc[:,'C'] = [5, 10, 20]
8777
-
8778
- xx = mmodel(df)
8779
- yy = mmodel(df2)
8780
-
8781
- # zz = model.modelload(r'https://raw.githubusercontent.com/IbHansen/Modelflow2/master/Examples/ADAM/baseline.pcim')
8782
- mpak,baseline = model.modelload(r'pak.pcim',run=1,use_fbmin=True)
8783
- alternative = baseline.upd("<2020 2100> PAKGGREVCO2CER PAKGGREVCO2GER PAKGGREVCO2OER = 30")
8784
- result = mpak(alternative,2020,2100,keep='Carbon tax nominal 30',silent=0) # simulates the model
8785
- diff_level, att_level, att_pct, diff_growth, att_growth = tup = mpak.dekomp('PAKNECONOTHRXN',lprint=False,start=2020,end=2027)
8786
-
8787
-
8788
- fb_nodes,dag_nodes = mpak.get_minimal_feedback_set(mpak.endograph)
8789
- print(f'Number of endogenous: {len(mpak.endogene)}, Number of variables in simultaneuous block {len(mpak.coreorder)}')
8790
- print(f'Number of variables in "minimum" feedback set: {len(fb_nodes)}')
8791
- print(f'Number of variables in "DAG" graph : {len(dag_nodes)}')
8792
- # mtest,bk = model.modelload(r'ibstestnozip')
8778
+ mmodel.check_endo_rhs()
8779
+ #%%
8780
+ if 1:
8781
+ df = pd.DataFrame(
8782
+ {'X': [0.2, 0.2, 0.2], 'C': [2.0, 3., 5.],'R': [2., 1., 0.4],
8783
+ 'PPP': [0.4, 0., 0.4]})
8784
+ df2 = df.copy()
8785
+ df2.loc[:,'C'] = [5, 10, 20]
8786
+
8787
+ xx = mmodel(df)
8788
+ yy = mmodel(df2)
8789
+
8790
+ # zz = model.modelload(r'https://raw.githubusercontent.com/IbHansen/Modelflow2/master/Examples/ADAM/baseline.pcim')
8791
+ mpak,baseline = model.modelload(r'pak.pcim',run=1,use_fbmin=True)
8792
+ alternative = baseline.upd("<2020 2100> PAKGGREVCO2CER PAKGGREVCO2GER PAKGGREVCO2OER = 30")
8793
+ result = mpak(alternative,2020,2100,keep='Carbon tax nominal 30',silent=0) # simulates the model
8794
+ diff_level, att_level, att_pct, diff_growth, att_growth = tup = mpak.dekomp('PAKNECONOTHRXN',lprint=False,start=2020,end=2027)
8795
+
8796
+
8797
+ fb_nodes,dag_nodes = mpak.get_minimal_feedback_set(mpak.endograph)
8798
+ print(f'Number of endogenous: {len(mpak.endogene)}, Number of variables in simultaneuous block {len(mpak.coreorder)}')
8799
+ print(f'Number of variables in "minimum" feedback set: {len(fb_nodes)}')
8800
+ print(f'Number of variables in "DAG" graph : {len(dag_nodes)}')
8801
+ # mtest,bk = model.modelload(r'ibstestnozip')
@@ -613,10 +613,12 @@ class DisplayDef:
613
613
 
614
614
  # Combine options using the existing __add__ method of DisplaySpec
615
615
  new_spec = self.spec + other.spec
616
-
616
+ # print(f'{self.spec=}')
617
+ # print(f'{new_spec=}')
617
618
  # Merge names if they differ, separated by a comma
618
619
  new_name = self.name if self.name == other.name else f"{self.name}_{other.name}"
619
-
620
+ # print(f'{new_name=}')
621
+
620
622
  # Create a new DisplayDef with the combined specifications
621
623
  return self.__class__(mmodel=self.mmodel, spec=new_spec, name=new_name)
622
624
 
@@ -1271,6 +1273,7 @@ class DisplayKeepFigDef(DisplayDef):
1271
1273
  # textdf = pd.DataFrame(float('nan'), index=self.mmodel.current_per, columns=[line.centertext]).T
1272
1274
  outlist = []
1273
1275
  else:
1276
+ # print(f'{line.pat=}')
1274
1277
  locallinedfdict = self.mmodel.keep_get_plotdict_new(
1275
1278
  pat=line.pat,
1276
1279
  showtype=line.showtype,
@@ -7,7 +7,7 @@ where = ["."]
7
7
 
8
8
  [project]
9
9
  name = "ModelFlowIb"
10
- version = "2.54"
10
+ version = "2.56"
11
11
  description = "A tool to solve and manage dynamic economic models"
12
12
  authors = [{name = "Ib Hansen", email = "your@email.com"}]
13
13
  license = { text = "MIT" }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes