ICB-DCM / pyPESTO

python Parameter EStimation TOolbox
https://pypesto.readthedocs.io
BSD 3-Clause "New" or "Revised" License
224 stars 47 forks source link

Example model not compiling to AMICI: conversion_reaction.ipynb #210

Closed matthiaskoenig closed 4 years ago

matthiaskoenig commented 4 years ago

I am trying to run the example notebooks, but the AMICI model cannot be compiled. On linux, Amici 0.10.17, latest pypesto pip install and also when installing from source.

# import sbml model, compile and generate amici module
sbml_importer = amici.SbmlImporter(sbml_file)
sbml_importer.sbml2amici(model_name,
                         model_output_dir,
                         verbose=False)
running build_ext
building 'model_conversion_reaction._model_conversion_reaction' extension
swigging swig/model_conversion_reaction.i to swig/model_conversion_reaction_wrap.cpp
swig -python -c++ -modern -outdir model_conversion_reaction -I/home/mkoenig/envs/mcp/lib/python3.7/site-packages/amici/swig -I/home/mkoenig/envs/mcp/lib/python3.7/site-packages/amici/include -o swig/model_conversion_reaction_wrap.cpp swig/model_conversion_reaction.i
error: command 'swig' failed with exit status 1

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-2-8e63ddafa7f1> in <module>
      3 sbml_importer.sbml2amici(model_name,
      4                          model_output_dir,
----> 5                          verbose=False)

~/envs/mcp/lib/python3.7/site-packages/amici/sbml_import.py in sbml2amici(self, modelName, output_dir, observables, constantParameters, sigmas, noise_distributions, verbose, assume_pow_positivity, compiler, allow_reinit_fixpar_initcond, compile)
    272                 warnings.warn('AMICI C++ extensions have not been built. '
    273                               'Generated model code, but unable to compile.')
--> 274             exporter.compileModel()
    275 
    276     def processSBML(self, constantParameters: List[str] = None):

~/envs/mcp/lib/python3.7/site-packages/amici/logging.py in wrapper_timer(*args, **kwargs)
    142         def wrapper_timer(*args, **kwargs):
    143             tstart = time.perf_counter()
--> 144             rval = func(*args, **kwargs)
    145             tend = time.perf_counter()
    146             spacers = ' ' * max(55 - len(description) - len(logger.name), 0)

~/envs/mcp/lib/python3.7/site-packages/amici/ode_export.py in compileModel(self)
   1923         """
   1924         self._compileCCode(compiler=self.compiler,
-> 1925                            verbose=self.verbose <= logging.DEBUG)
   1926 
   1927     def _prepareModelFolder(self):

~/envs/mcp/lib/python3.7/site-packages/amici/ode_export.py in _compileCCode(self, verbose, compiler)
   2008                                     stdout=subprocess.PIPE,
   2009                                     stderr=subprocess.STDOUT,
-> 2010                                     check=True)
   2011         except subprocess.CalledProcessError as e:
   2012             print(e.output.decode('utf-8'))

/usr/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    510         if check and retcode:
    511             raise CalledProcessError(retcode, process.args,
--> 512                                      output=stdout, stderr=stderr)
    513     return CompletedProcess(process.args, retcode, stdout, stderr)
    514 

CalledProcessError: Command '['/home/mkoenig/envs/mcp/bin/python3.7', '/home/mkoenig/git/pyPESTO/doc/example/tmp/model_conversion_reaction/setup.py', '--verbose', 'build_ext', '--build-lib=/home/mkoenig/git/pyPESTO/doc/example/tmp/model_conversion_reaction']' returned non-zero exit status 1.
FFroehlich commented 4 years ago

That's odd, it doesn't show any error message. What version of swig are you using (swig -version)?

matthiaskoenig commented 4 years ago

This was solved by installing swig. Did not know I need the dependency.

yannikschaelte commented 4 years ago

you find all dependencies of AMICI here: https://github.com/ICB-DCM/AMICI/blob/master/INSTALL.md#dependencies

FFroehlich commented 4 years ago

I'm actually surprised you were able to install amici without swig, if thats the case we should definitely have a closer look and throw an error message earlier on.

mhhoog commented 4 years ago

I ran into a similar problem. I checked my SWIG installation swig -version but it states that it is installed.

SWIG Version 3.0.12

Compiled with g++ [x86_64-pc-linux-gnu]

Configured options: +pcre

I work on Ubuntu 18.04.3 LTS. Would you know how to solve this problem?

The full output:

importer = pypesto.PetabImporter(petab_problem)

model = importer.create_model()

print("Model parameters:", list(model.getParameterIds()), '\n')
print("Model const parameters:", list(model.getFixedParameterIds()), '\n')
print("Model outputs:   ", list(model.getObservableIds()), '\n')
print("Model states:    ", list(model.getStateIds()), '\n')
running build_ext
building 'Burger._Burger' extension
swigging swig/Burger.i to swig/Burger_wrap.cpp
swig -python -c++ -modern -outdir Burger -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/swig -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/include -o swig/Burger_wrap.cpp swig/Burger.i
creating build
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/swig
gcc -pthread -B /home/maartje/anaconda3/envs/envICB/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/maartje/Documents/Helmholtz_ICB/amici_models/Burger -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/include -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ThirdParty/gsl -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ThirdParty/sundials/include -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ThirdParty/SuiteSparse/include -I/home/maartje/anaconda3/envs/envICB/include/python3.8 -c swig/Burger_wrap.cpp -o build/temp.linux-x86_64-3.8/swig/Burger_wrap.o -std=c++11
gcc -pthread -B /home/maartje/anaconda3/envs/envICB/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/maartje/Documents/Helmholtz_ICB/amici_models/Burger -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/include -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ThirdParty/gsl -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ThirdParty/sundials/include -I/home/maartje/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ThirdParty/SuiteSparse/include -I/home/maartje/anaconda3/envs/envICB/include/python3.8 -c Burger_xdot.cpp -o build/temp.linux-x86_64-3.8/Burger_xdot.o -std=c++11
Burger_xdot.cpp: In function ‘void xdot_Burger(realtype*, realtype, const realtype*, const realtype*, const realtype*, const realtype*, const realtype*)’:
Burger_xdot.cpp:15:1: error: ‘zoo’ was not declared in this scope
 zoo*flux_r0 + zoo*flux_r1;
 ^~~
error: command 'gcc' failed with exit status 1

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-22-3dd687df82e6> in <module>
      4 petab_problem.sbml_document.convert(converter_config)
      5 
----> 6 obj = importer.create_objective()
      7 
      8 # for some models, hyperparamters need to be adjusted

~/src/pypesto/pypesto/objective/petab_import.py in create_objective(self, model, solver, edatas, force_compile)
    247         # create model
    248         if model is None:
--> 249             model = self.create_model(force_compile=force_compile)
    250         # create solver
    251         if solver is None:

~/src/pypesto/pypesto/objective/petab_import.py in create_model(self, force_compile, *args, **kwargs)
    135             logger.info(f"Compiling amici model to folder "
    136                         f"{self.output_folder}.")
--> 137             self.compile_model(*args, **kwargs)
    138         else:
    139             logger.info(f"Using existing amici model in folder "

~/src/pypesto/pypesto/objective/petab_import.py in compile_model(self, **kwargs)
    193             shutil.rmtree(self.output_folder)
    194 
--> 195         import_model(sbml_model=self.petab_problem.sbml_model,
    196                      condition_table=self.petab_problem.condition_df,
    197                      observable_table=self.petab_problem.observable_df,

~/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/logging.py in wrapper_timer(*args, **kwargs)
    142         def wrapper_timer(*args, **kwargs):
    143             tstart = time.perf_counter()
--> 144             rval = func(*args, **kwargs)
    145             tend = time.perf_counter()
    146             spacers = ' ' * max(55 - len(description) - len(logger.name), 0)

~/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/petab_import.py in import_model(sbml_model, condition_table, observable_table, model_name, model_output_dir, verbose, allow_reinit_fixpar_initcond, **kwargs)
    457 
    458     # Create Python module from SBML model
--> 459     sbml_importer.sbml2amici(
    460         modelName=model_name,
    461         output_dir=model_output_dir,

~/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/sbml_import.py in sbml2amici(self, modelName, output_dir, observables, constantParameters, sigmas, noise_distributions, verbose, assume_pow_positivity, compiler, allow_reinit_fixpar_initcond, compile)
    272                 warnings.warn('AMICI C++ extensions have not been built. '
    273                               'Generated model code, but unable to compile.')
--> 274             exporter.compileModel()
    275 
    276     def processSBML(self, constantParameters: List[str] = None):

~/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/logging.py in wrapper_timer(*args, **kwargs)
    142         def wrapper_timer(*args, **kwargs):
    143             tstart = time.perf_counter()
--> 144             rval = func(*args, **kwargs)
    145             tend = time.perf_counter()
    146             spacers = ' ' * max(55 - len(description) - len(logger.name), 0)

~/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ode_export.py in compileModel(self)
   1922 
   1923         """
-> 1924         self._compileCCode(compiler=self.compiler,
   1925                            verbose=self.verbose <= logging.DEBUG)
   1926 

~/anaconda3/envs/envICB/lib/python3.8/site-packages/amici/ode_export.py in _compileCCode(self, verbose, compiler)
   2004         # result easily
   2005         try:
-> 2006             result = subprocess.run(script_args,
   2007                                     cwd=moduleDir,
   2008                                     stdout=subprocess.PIPE,

~/anaconda3/envs/envICB/lib/python3.8/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    510         retcode = process.poll()
    511         if check and retcode:
--> 512             raise CalledProcessError(retcode, process.args,
    513                                      output=stdout, stderr=stderr)
    514     return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['/home/maartje/anaconda3/envs/envICB/bin/python', '/home/maartje/Documents/Helmholtz_ICB/amici_models/Burger/setup.py', '--verbose', 'build_ext', '--build-lib=/home/maartje/Documents/Helmholtz_ICB/amici_models/Burger']' returned non-zero exit status 1.
dweindl commented 4 years ago

Hi @mhhoog, your problem is unrelated to the one above. Unless your model actually contains an entity named zoo, this comes from complex infinity. Is there any chance you can share the model you tried to import there? (also fine with randomized names/values, as long as the error is reproducible)

mhhoog commented 4 years ago

It indeed doesn't contain the entity zoo. The model (from the .xml file): model.txt

dweindl commented 4 years ago

The model

Thanks.

The problem is, that your compartments are of size 0. Therefore, the right hand side of the ODEs is non-finite. Changing them to anything >0 should fix your problem.

mhhoog commented 4 years ago

Thank you that helped!

Sadly I ran into another problem, also testing for a benchmark problem. I opened a new issue for this. 'g++' failed with exit status 1