1

I'm writing some code to perform markov chain monte carlo (MCMC) in python for parameter estimation of SBML based ODEs. The implementation is complete and works until I try and perform more than 126 iterations. The error I get when using more than 126 iterations is:

  File "insert_copasi_parameters.py", line 68, in _read_copasiML_as_string
    with open(self.copasi_file) as f:

IOError: [Errno 24] Too many open files: 'D:\\MPhil\\Model_Building\\Models\\Exercises\\COPASI_API\\_temp.cps'

The integration of ODE's is computed using some software called COPASI. This software requires an xml. The module 'insert_copasi_parameters' takes some randomly sampled parameters and puts them into the xml (which is the .cps file being complained about above).

The actual method the algorithm fails on ('_read_copasiML_as_string') is a simple with block. i.e.

def _read_copasiML_as_string(self):
    with open(self.copasi_file) as f:
        return f.read()

An ODE trajectory is then calculated by the software and parsed back into python to continue with the algorithm. Since I'm using a with block these files should be getting opened and then closed again after every iteration. Not only this, the `temp.cps' file above is actually a copy of the original that gets deleted between runs. I appreciate its hard without seeing the actual code (which is too long for SO) but can anybody suggest where this error coming from?

Thanks in advance

CiaranWelsh
  • 7,014
  • 10
  • 53
  • 106
  • You can start with [this answer](http://stackoverflow.com/a/28212496/2011147) – Selcuk May 16 '16 at 15:09
  • unfortunately I get an import error with `import win32file` and the module cannot be downloaded with `pip` – CiaranWelsh May 16 '16 at 15:14
  • The package name is `pywin32` and you can download the whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32 – Selcuk May 16 '16 at 15:16
  • Maybe some other files are opened on each iteration after the successful execution of `_read_copasiML_as_string`? Try searching for `open` in your codebase. – Vasiliy Faronov May 16 '16 at 17:11

0 Answers0