BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization
https://machinelearning.byu.edu
Other
569 stars 102 forks source link

FileNotFoundError and strange behavior depending on the rundir #167

Closed PerplexedFox closed 10 months ago

PerplexedFox commented 10 months ago

I've started a new model by implementing some of the fluid data from CoolProp. All worked fine as long as I was in the same RunDirectory as my previous (similar) model was. However, when I clear the temp files and/or switch directories, the code, which previously worked, starts throwing an error

m = GEKKO(remote=False)
#m._path = os.path.abspath(rd)
D_data = np.arange(3,800,150)
u_data = np.arange(-150*1000,150*1000,80000) #in J/kg
T_data=[]
u1,D1 = m.Array(m.Var,2,value=13)
T1 = m.Var()
for n in D_data:
    rowT = []
    for i in u_data:
        try:
            T = CP.PropsSI('T','U',i,'D',n,"Nitrogen")
            rowT.append(T)
        except ValueError as e:
            rowT.append(None)
    T_data.append(rowT)
m.bspline(D1,u1,T1,D_data,u_data,T_data)
m.options.SOLVER = 3 # solver (IPOPT) 
m.solve()

Error: Exception: Access Violation At line 832 of file bspline.f90 Traceback: not available, compile with -ftrace=frame or -ftrace=full Error: 'results.json' not found. Check above for additional error details

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\...\AppData\Local\Temp\tmphnytmwt7gk_model91\options.json'

image

Could the None values in the data have been the problem? However, as soon as I change to the directory of another model, it works.

image image image The spline converges despite having None values where the physical ones are unavailable and all seem to work nicely image

And yet, when staying in the same "successful" directory and adding another variable the solver won't calculate it.

Error: Exception: Access Violation At line 832 of file bspline.f90 Traceback: not available, compile with -ftrace=frame or -ftrace=full v4 not found in results file

On this note also a request: It would be surely great, if bspline could handle the None values

APMonitor commented 10 months ago

The first error is that FileNotFoundError: [Errno 2] No such file or directory for options.json. With successive solves, Gekko is trying to locate files in the run directory that define options. I recommend that you define the directory before the first solve and stay with that directory. If you need to remove the run directory, use m.cleanup() to delete the temporary directory.

Also, Gekko isn't designed to solve and then modify the variables to the model. In this case, use the m.cleanup() and redefine the model again if new variables need to be added.

What should be the behavior if None is encountered in the bspline data? Please create a new Feature Request if you'd like to see this added to a future release. Also, please describe the intended behavior with None data.