def __init__(self, model: Model = None, output_directory: str = None, delete_directory: bool = True, resume=None, variable: bool = False): if model is None: raise gillespyError.SimulationError("A model is required to run the simulation.") if len(BuildEngine.get_missing_dependencies()) > 0: raise gillespyError.SimulationError( "Please install/configure 'g++' and 'make' on your system, to ensure that GillesPy2 C solvers will run properly." ) if platform.system() == "Windows" and " " in gillespy2.__file__: raise gillespy2Error.SimulationError("GillesPy2 does not support spaces in its path on Windows systems.") self.delete_directory = False self.model = copy.deepcopy(model) self.resume = resume self.variable = variable self.build_engine: BuildEngine = None # Validate output_directory, ensure that it doesn't already exist if isinstance(output_directory, str): output_directory = os.path.abspath(output_directory) if os.path.exists(output_directory): raise gillespyError.DirectoryError( f"Could not write to specified output directory: {output_directory}" " (already exists)" ) self.output_directory = output_directory self.delete_directory = delete_directory if self.model is not None: self._set_model() self.is_instantiated = True
def __init__(self, makefile: str, output_dir: str, obj_dir: str = None): self.makefile = Path(makefile).resolve() self.self_dir = Path(__file__).parent self.cbase_dir = self.self_dir.joinpath("../c_base").resolve() self.output_dir = Path(output_dir).resolve() # obj_dir is, presumably, only supplied if caching is enabled. # If not supplied, it should be assumed ethereal and cleaned up # with the rest of the tmp directory. if obj_dir is None: self.obj_dir = self.output_dir.joinpath("gillespy2_obj").resolve() else: self.obj_dir = Path(obj_dir).resolve() for path in [self.output_dir, self.obj_dir]: if path.is_file(): raise gillespyError.DirectoryError( f"Error while attempting to open directory:\n" f"- {path} is actually a file." ) if not path.is_dir(): path.mkdir() self.output_file = "GillesPy2_Simulation.out" if os.name == "nt": self.output_file = "GillesPy2_Simulation.exe" self.output_file = Path(self.output_dir, self.output_file)
def __init__(self, model=None, output_directory=None, delete_directory=True, resume=None): super(SSACSolver, self).__init__() self.__compiled = False self.delete_directory = False self.model = model self.resume = resume if self.model is not None: # Create constant, ordered lists for reactions/species/ self.species_mappings = self.model.sanitized_species_names() self.species = list(self.species_mappings.keys()) self.parameter_mappings = self.model.sanitized_parameter_names() self.parameters = list(self.parameter_mappings.keys()) self.reactions = list(self.model.listOfReactions.keys()) if isinstance(output_directory, str): output_directory = os.path.abspath(output_directory) if isinstance(output_directory, str): if not os.path.isfile(output_directory): self.output_directory = output_directory self.delete_directory = delete_directory if not os.path.isdir(output_directory): os.makedirs(self.output_directory) else: raise gillespyError.DirectoryError( "File exists with the same path as directory.") else: self.temporary_directory = tempfile.TemporaryDirectory() self.output_directory = self.temporary_directory.name if not os.path.isdir(self.output_directory): raise gillespyError.DirectoryError( "Errors encountered while setting up directory for Solver C++ files." ) cutils._copy_files(self.output_directory, GILLESPY_C_DIRECTORY) self.__write_template() self.__compile()