jfowkes / pycutest

Python interface to CUTEst
https://jfowkes.github.io/pycutest/
GNU General Public License v3.0
27 stars 10 forks source link

System state isn't restored after loading failure (`FileNotFoundError`) #54

Closed ragonneau closed 1 year ago

ragonneau commented 1 year ago

Describe the bug Failures may happen when loading problems. However, the previous state of the system, and in particular the current working directory, is not restored. See the example below

To Reproduce

import os, pycutest

try:
    prob = pycutest.import_problem('SCURLY20', sifParams={'N': 10})
except RuntimeError:
    print("Loading failed.")
print(os.getcwd())

This code returns the following error.

 Problem name: SCURLY20

 Double precision version will be formed

 ** Exit from INTERPRET_gpsmps - index parameter name S-9        not recognised 

 From within do loop ending on line    68, current line is 
  ZN Q-9       X-9         0.0000D+00   S-9         0.0000D+00

 Return from INTERPRET_gpsmps, status = 3
 Decoding failure, status = 3

 ERROR: Error exit from decoding stage. terminating execution.

Loading failed.
Traceback (most recent call last):
  File "mytest.py", line 8, in <module>
    print(os.getcwd())
FileNotFoundError: [Errno 2] No such file or directory
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 76, in apport_excepthook
    binary = os.path.realpath(os.path.join(os.getcwd(), sys.argv[0]))
FileNotFoundError: [Errno 2] No such file or directory

Original exception was:
Traceback (most recent call last):
  File "mytest.py", line 8, in <module>
    print(os.getcwd())
FileNotFoundError: [Errno 2] No such file or directory

Information about your installation:

jfowkes commented 1 year ago

Thanks @ragonneau, looks like we need to handle decoding errors from SIFDecode more gracefully and restore the current working directory on exit. I will investigate.

ragonneau commented 1 year ago

Hi @jfowkes,

It's what I think, but I am not familiar with the code structure of PyCUTEst. I believe you'd patch the problem much faster than I would :-)

Thanks, Tom.