"""Abstract base simulation."""
import abc
from abc import ABC
from typing import Dict, List
from sbmlutils import log
from sbmlsim.simulation.algorithm import Algorithm
from sbmlsim.simulation.base import BaseObject
from sbmlsim.simulation.range import Dimension
from sbmlsim.units import UnitsInformation
[docs]logger = log.get_logger(__name__)
[docs]class Simulation(BaseObject):
"""Simulation class.
A simulation is the execution of some defined algorithm(s). Simulations are
described differently depending on the type of simulation experiment to be
performed.
Simulation is an abstract class and serves as parent class for the different
types of simulations.
"""
def __init__(self, sid: str, algorithm: Algorithm, name: str = None):
"""Construct Simulation.
The mandatory attribute algorithm defines the simulation algorithms used
for the execution of the simulation. The algorithms are defined
via the Algorithm class.
"""
super(Simulation, self).__init__(sid=sid, name=name)
self.algorithm: Algorithm = algorithm
[docs] def __repr__(self) -> str:
"""Get string representation."""
return f"Simulation({self.sid}, {self.name}, {self.algorithm}"
[docs]class Analysis(Simulation):
"""Analysis class.
The Analysis represents any sort of analysis or simulation of a Model, entirely defined by its child
Algorithm.
"""
[docs] def __repr__(self) -> str:
"""Get string representation."""
return f"Analysis({self.sid}, {self.name}, {self.algorithm}"
[docs]class SteadyState(Simulation):
"""SteadyState class.
The SteadyState represents a steady state computation (as for example
implemented by NLEQ or Kinsolve).
"""
[docs] def __repr__(self) -> str:
"""Get string representation."""
return f"SteadyState({self.sid}, {self.name}, {self.algorithm}"
[docs]class OneStep(Simulation):
"""OneStep class.
The OneStep class calculates one further output step for the model from its
current state.
"""
[docs] def __repr__(self) -> str:
"""Get string representation."""
return f"OneStep({self.sid}, {self.name}, {self.algorithm}"
def __init__(self, sid: str, step: float, algorithm: Algorithm, name: str = None):
"""Construct OneStep."""
super(OneStep, self).__init__(sid=sid, name=name, algorithm=algorithm)
self.step: float = step
[docs]class AbstractSim(ABC):
"""AbstractSim.
Base class of simulations.
"""
@abc.abstractmethod
[docs] def dimensions(self) -> List[Dimension]:
"""Get dimension of the simulation."""
raise NotImplementedError
@abc.abstractmethod
[docs] def normalize(self, uinfo: UnitsInformation) -> None:
"""Normalize simulation."""
raise NotImplementedError
@abc.abstractmethod
[docs] def add_model_changes(self, changes: Dict) -> None:
"""Add model changes to model."""
raise NotImplementedError
[docs] def to_dict(self) -> Dict[str, str]:
"""Convert to dictionary."""
d = {
"type": self.__class__.__name__,
}
return d