Skip to content

Commit

Permalink
Don't modify sys.path for amici model imports (#1522)
Browse files Browse the repository at this point in the history
Not necessary when using `amici.import_model_module`.
  • Loading branch information
dweindl authored Nov 27, 2024
1 parent 1eb61d7 commit 2ed5f8f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 14 deletions.
5 changes: 0 additions & 5 deletions pypesto/petab/objective_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import re
import shutil
import sys
import warnings
from abc import ABC, abstractmethod
from collections.abc import Iterable, Sequence
Expand Down Expand Up @@ -145,10 +144,6 @@ def create_model(
f"compilation: Not a folder."
)

# add module to path
if self.output_folder not in sys.path:
sys.path.insert(0, self.output_folder)

# compile
if self._must_compile(force_compile):
logger.info(
Expand Down
6 changes: 0 additions & 6 deletions test/petab/test_amici_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
import shutil
import sys

import amici
import libsbml
Expand Down Expand Up @@ -34,13 +33,10 @@ def conversion_reaction_model():

# try to import the exisiting model, if possible
try:
sys.path.insert(0, os.path.abspath(model_output_dir))
model_module = amici.import_model_module(model_name, model_output_dir)
model = model_module.getModel()
except ValueError:
# read in and adapt the sbml slightly
if os.path.abspath(model_output_dir) in sys.path:
sys.path.remove(os.path.abspath(model_output_dir))
sbml_importer = amici.SbmlImporter(sbml_file)

# add observables to sbml model
Expand Down Expand Up @@ -95,7 +91,6 @@ def create_intial_assignment(sbml_model, spec_id):
)

# Importing the module and loading the model
sys.path.insert(0, os.path.abspath(model_output_dir))
model_module = amici.import_model_module(model_name, model_output_dir)
model = model_module.getModel()
except RuntimeError as err:
Expand All @@ -107,7 +102,6 @@ def create_intial_assignment(sbml_model, spec_id):
"Delete the conversion_reaction_enhanced model from your python "
"path and retry. Your python path is currently:"
)
print(sys.path)
print("Original error message:")
raise err

Expand Down
3 changes: 0 additions & 3 deletions test/petab/test_sbml_conversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import re
import sys
import unittest
import warnings

Expand All @@ -11,8 +10,6 @@

from ..util import load_amici_objective

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

optimizers = {
"scipy": [
"Nelder-Mead",
Expand Down

0 comments on commit 2ed5f8f

Please sign in to comment.