diff --git a/gillespy2/core/model.py b/gillespy2/core/model.py index 1ff76dfb..b29437fa 100644 --- a/gillespy2/core/model.py +++ b/gillespy2/core/model.py @@ -1295,6 +1295,8 @@ def run(self, solver=None, timeout=0, t=None, increment=None, algorithm=None, ** if "CSolver" in solver.name and \ ("resume" in solver_args or "variables" in solver_args or "live_output" in solver_args): sol_kwargs['variable'] = True + if "build_definitions" in solver_args: + sol_kwargs['build_definitions'] = solver_args['build_definitions'] solver = solver(**sol_kwargs) except Exception as err: raise SimulationError(f"{solver} is not a valid solver. Reason Given: {err}.") from err diff --git a/gillespy2/solvers/cpp/build/SConstruct b/gillespy2/solvers/cpp/build/SConstruct index f5b4eb65..18712e9d 100644 --- a/gillespy2/solvers/cpp/build/SConstruct +++ b/gillespy2/solvers/cpp/build/SConstruct @@ -51,6 +51,9 @@ env = Environment( # When MSVC (or any other compilers) are supported, update this to be a compiler-specific flag CXXFLAGS=['-std=c++14'], ) +extra_cxxflags = ARGUMENTS.get('EXTRA_CXXFLAGS', '') +if extra_cxxflags: + env.Append(CXXFLAGS=extra_cxxflags.split()) libdepends = [ f'gpy{solver}', 'gpystd' diff --git a/gillespy2/solvers/cpp/c_solver.py b/gillespy2/solvers/cpp/c_solver.py index 30d1b612..79578d07 100644 --- a/gillespy2/solvers/cpp/c_solver.py +++ b/gillespy2/solvers/cpp/c_solver.py @@ -59,10 +59,13 @@ class CSolver: :param variable: Indicates whether the simulation should be variable. :type variable: bool + + :param build_definitions: Dictionary of definitions to be passed to the build engine (e.g. {'cxxflags':'-O3'}) + :type build_definitions: "dict[str, str]" """ rc = 0 - def __init__(self, model: Model = None, output_directory: str = None, delete_directory: bool = True, resume=None, variable: bool = False): + def __init__(self, model: Model = None, output_directory: str = None, delete_directory: bool = True, resume=None, variable: bool = False, build_definitions: "dict[str, str]" = None): if model is None: raise gillespyError.SimulationError("A model is required to run the simulation.") @@ -79,6 +82,7 @@ def __init__(self, model: Model = None, output_directory: str = None, delete_dir self.resume = resume self.variable = variable self.build_engine: BuildEngine = None + self.build_definitions: "dict[str, str]" = build_definitions # Validate output_directory, ensure that it doesn't already exist if isinstance(output_directory, str): @@ -106,7 +110,7 @@ def __del__(self): self.build_engine.clean() - def _build(self, model: "Union[Model, SanitizedModel]", simulation_name: str, variable: bool, debug: bool = False) -> str: + def _build(self, model: "Union[Model, SanitizedModel]", simulation_name: str, variable: bool, debug: bool = False, build_definitions: "dict[str, str]" = None) -> str: """ Generate and build the simulation from the specified Model and solver_name into the output_dir. @@ -128,7 +132,7 @@ def _build(self, model: "Union[Model, SanitizedModel]", simulation_name: str, va self.build_engine = BuildEngine(debug=debug, output_dir=self.output_directory) self.build_engine.prepare(model, variable) # Compile the simulation, returning the path of the executable. - return self.build_engine.build_simulation(simulation_name) + return self.build_engine.build_simulation(simulation_name, build_definitions) # Assume that the simulation has already been built. return self.build_engine.get_executable_path() @@ -336,7 +340,7 @@ def _set_model(self, model=None): if model is not None: self.model = copy.deepcopy(model) - self._build(self.model, self.target, self.variable, False) + self._build(self.model, self.target, self.variable, False, self.build_definitions) self.species_mappings = self.model.sanitized_species_names() self.species = list(self.species_mappings.keys()) self.parameter_mappings = self.model.sanitized_parameter_names() diff --git a/gillespy2/solvers/cpp/ssa_c_solver.py b/gillespy2/solvers/cpp/ssa_c_solver.py index 098d2d38..f0f6befd 100644 --- a/gillespy2/solvers/cpp/ssa_c_solver.py +++ b/gillespy2/solvers/cpp/ssa_c_solver.py @@ -43,7 +43,8 @@ def get_solver_settings(cls): def run(self=None, model: Model = None, t: int = None, number_of_trajectories: int = 1, timeout: int = 0, increment: int = None, seed: int = None, debug: bool = False, profile: bool = False, variables={}, - resume=None, live_output: str = None, live_output_options: dict = {}, **kwargs): + resume=None, live_output: str = None, live_output_options: dict = {}, + build_definitions: "dict[str, str]" = None, **kwargs): from gillespy2 import log @@ -182,4 +183,4 @@ def run(self=None, model: Model = None, t: int = None, number_of_trajectories: i self.result = simulation_data self.rc = int(sim_status) - return Results.build_from_solver_results(self, live_output_options) \ No newline at end of file + return Results.build_from_solver_results(self, live_output_options)