Skip to content

Commit

Permalink
Clear previously-loaded models in Antimony when getting a new one.
Browse files Browse the repository at this point in the history
Repeated calls to 'loada' were causing steady increases in used memory because the Antimony library was storing every model.  This clears them out each time, since a tellurium user doesn't care about retrieving old models.

Also clean up a couple of warnings.
  • Loading branch information
luciansmith committed Dec 1, 2021
1 parent 1587ce9 commit 07f29e7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tellurium/tellurium.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from __future__ import print_function, division, absolute_import

import sys
import os
import random
import warnings
Expand Down Expand Up @@ -185,6 +184,7 @@ def getPlottingEngine(engine=None):
import sbol
except ImportError as e:
sbol = None
roadrunner.Logger.log(roadrunner.Logger.LOG_WARNING, str(e))
warnings.warn("'pySBOL' could not be imported, cannot import/export SBOL files", ImportWarning, stacklevel=2)

try:
Expand Down Expand Up @@ -405,7 +405,7 @@ def spark_sensitivity_analysis(model_with_parameters):
sa_model.simulation = user_defined_simulator()

if(sa_model.sbml):
model_roadrunner = te.loadAntimonyModel(te.sbmlToAntimony(sa_model.model))
model_roadrunner = te.loadSBMLModel(sa_model.model)
else:
model_roadrunner = te.loadAntimonyModel(sa_model.model)

Expand Down Expand Up @@ -464,7 +464,7 @@ def spark_sensitivity_analysis(model_with_parameters):

samples = perform_sampling(np.meshgrid(*params))
samples = zip([senitivity_analysis_model]*len(samples),samples)
if(calculation is "avg"):
if(calculation == "avg"):
group_rdd = sc.parallelize(samples,len(samples)).map(spark_sensitivity_analysis).\
flatMap(lambda x: x[1].items()).groupByKey()

Expand Down Expand Up @@ -589,6 +589,7 @@ def antimonyToSBML(ant):
:return: SBML
:rtype: str
"""
antimony.clearPreviousLoads()
try:
isfile = os.path.isfile(ant)
except ValueError:
Expand All @@ -611,6 +612,7 @@ def antimonyToCellML(ant):
:return: CellML
:rtype: str
"""
antimony.clearPreviousLoads()
if os.path.isfile(ant):
code = antimony.loadAntimonyFile(ant)
else:
Expand All @@ -628,6 +630,7 @@ def sbmlToAntimony(sbml):
:return: Antimony
:rtype: str
"""
antimony.clearPreviousLoads()
isfile = False
try:
isfile = os.path.isfile(sbml)
Expand All @@ -651,6 +654,7 @@ def sbmlToCellML(sbml):
"""
if not hasattr(antimony, "loadCellMLString"):
raise NotImplementedError("CellML support was not compiled into Antimony, so conversion is not available.")
antimony.clearPreviousLoads()
if os.path.isfile(sbml):
code = antimony.loadSBMLFile(sbml)
else:
Expand All @@ -668,6 +672,7 @@ def cellmlToAntimony(cellml):
"""
if not hasattr(antimony, "loadCellMLString"):
raise NotImplementedError("CellML support was not compiled into Antimony, so conversion is not available.")
antimony.clearPreviousLoads()
if os.path.isfile(cellml):
code = antimony.loadCellMLFile(cellml)
else:
Expand All @@ -686,6 +691,7 @@ def cellmlToSBML(cellml):
"""
if not hasattr(antimony, "loadCellMLString"):
raise NotImplementedError("CellML support was not compiled into Antimony, so conversion is not available.")
antimony.clearPreviousLoads()
if os.path.isfile(cellml):
code = antimony.loadCellMLFile(cellml)
else:
Expand Down Expand Up @@ -751,7 +757,7 @@ def extractFileFromCombineArchive(archive_path, entry_location):
if not archive.initializeFromArchive(archive_path):
raise RuntimeError('Failed to initialize archive')
try:
entry = archive.getEntryByLocation(entry_location)
archive.getEntryByLocation(entry_location)
except:
raise RuntimeError('Could not find entry {}'.format(entry_location))
return archive.extractEntryToString(entry_location)
Expand Down

0 comments on commit 07f29e7

Please sign in to comment.