Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gillespy2/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions gillespy2/solvers/cpp/build/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 8 additions & 4 deletions gillespy2/solvers/cpp/c_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand All @@ -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):
Expand Down Expand Up @@ -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.

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions gillespy2/solvers/cpp/ssa_c_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
return Results.build_from_solver_results(self, live_output_options)