Example #1
0
 def testDeserialize(self):
     if IGNORE_TEST:
         return
     fitter = self.getFitter()
     fitter.serialize(FILE_SERIALIZE)
     deserializedFitter = ModelFitter.deserialize(FILE_SERIALIZE)
     self.assertEqual(fitter.modelSpecification,
           deserializedFitter.modelSpecification)
     self.assertEqual(len(fitter.bootstrapResult.fittedStatistic.meanTS),
           len(deserializedFitter.bootstrapResult.fittedStatistic.meanTS))
Example #2
0
 def __init__(self,
              modelSpecification,
              dataSources,
              dirStudyPath=None,
              instanceNames=None,
              logger=Logger(),
              useSerialized=True,
              doSerialize=True,
              isPlot=True,
              **kwargs):
     """
     Parameters
     ---------
     modelSpecification: ExtendedRoadRunner/str
         roadrunner model or antimony model
     dataSources: list-NamedTimeseries/list-str or dict of either
         str: path to CSV file
     dirStudyPath: str
         Path to the output directory containing the serialized fitters
         for the study.
     instanceNames: list-str
         Names of study instances corresponds to the list of dataSources
     useSerialized: bool
         Use the serialization of each ModelFitter, if it exists
     doSerialized: bool
         Serialize each ModelFitter
     isPlot: bool
         Do plots
     kwargs: dict
         arguments passed to ModelFitter
     """
     self.dirStudyPath = dirStudyPath  # Path to the directory serialized ModelFitter
     if self.dirStudyPath is None:
         length = len(inspect.stack())
         absPath = os.path.abspath((inspect.stack()[length - 1])[1])
         dirCaller = os.path.dirname(absPath)
         self.dirStudyPath = os.path.join(dirCaller, DIR_NAME)
     self.isPlot = isPlot
     self.doSerialize = doSerialize
     self.useSerialized = useSerialized
     self.instanceNames, self.dataSourceDct = self._mkInstanceData(
         instanceNames, dataSources)
     self.fitterPathDct = {
     }  # Path to serialized fitters; key is instanceName
     self.fitterDct = {}  # Fitters: key is instanceName
     self.logger = logger
     # Ensure that the directory exists
     if not os.path.isdir(self.dirStudyPath):
         os.makedirs(self.dirStudyPath)
     # Construct the fitters
     for name, dataSource in self.dataSourceDct.items():
         filePath = self._getSerializePath(name)
         self.fitterPathDct[name] = filePath
         if os.path.isfile(filePath) and useSerialized:
             self.fitterDct[name] = ModelFitter.deserialize(filePath)
         else:
             self.fitterDct[name] = ModelFitter(modelSpecification,
                                                dataSource,
                                                logger=self.logger,
                                                isPlot=self.isPlot,
                                                **kwargs)
             self._serializeFitter(name)