dgorissen / pycel

A library for compiling excel spreadsheets to python code & visualizing them as a graph
GNU General Public License v3.0
570 stars 149 forks source link

TypeError on iterative models #71

Closed tactycHQ closed 5 years ago

tactycHQ commented 5 years ago

I have tested this issue on multiple complex models that use iterations and keep coming up against this error.

  File "C:\Users\a\.conda\envs\pycel\lib\site-packages\pycel\excelutil.py", line 1317, in done
    return (self.ns.iteration_number >= self.ns.iterations or
TypeError: '>=' not supported between instances of 'int' and 'NoneType

Any advice or suggestions would be helpful on why this error occurs,

tactycHQ commented 5 years ago

After investigating this further, could this be because the iterations param is set to None in the __call__ function of the _IterativeEvalTracker class? Once I change that param to 100 or some number, this error goes away.

Should the default param be changed from None to 100 (or some number)

JSv4 commented 3 years ago

FYI, for anyone else facing the same issue, the solution is here: https://github.com/dgorissen/pycel/pull/58. Some workbooks don't have iterative calculations enabled and, as noted above, this causes an error if you try to run an evaluation unless you override the workbook's default iterative solver settings.

Per the comments to the merge I linked to above:

1) When you instantiate the compiler, set cycles=True:

ExcelCompiler(..., cycles=True)

2) Then you have to add two new parameters to evaluate( ):

ExcelCompiler.evaluate(..., iterations=100, tolerance=0.001)

This worked for me as of 8/26/2021 using Pycel v 1.0b27