Skip to content

Commit

Permalink
Merge pull request #580 from StochSS/develop
Browse files Browse the repository at this point in the history
Release v1.6.3
  • Loading branch information
ethangreen-dev authored Jul 20, 2021
2 parents dc4c744 + 97dbd57 commit 664194a
Show file tree
Hide file tree
Showing 46 changed files with 2,159 additions and 482 deletions.
2 changes: 1 addition & 1 deletion gillespy2/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# =============================================================================


__version__ = '1.6.2'
__version__ = '1.6.3'

__title__ = 'GillesPy2'
__description__ = 'Python interface for Gillespie-style biochemical simulations'
Expand Down
23 changes: 12 additions & 11 deletions gillespy2/core/functiondefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,31 @@ class FunctionDefinition(SortableObject, Jsonify):
"""

def __init__(self, name="", function=None, args=[]):

import math
eval_globals = math.__dict__
if function is None:
raise TypeError("Function string provided for FunctionDefinition cannot be None")

self.name = name
self.function_string = function

self.args = ', '.join(args)
self.function = eval('lambda ' + self.args + ': ' + function, eval_globals)

if self.function is None:
raise TypeError
self.args = args


def __str__(self):
return f"self.name: Args: {self.args}, Expression: {self.function_string}"
return f"{self.name}: Args: {self.args}, Expression: {self.function_string}"

def get_arg_string(self) -> str:
"""
Convert function's argument list into a comma-separated formatted string.
:returns: Argument list as a comma-separated formatted string.
"""
return ','.join(self.args)

def sanitized_function(self, species_mappings, parameter_mappings):
names = sorted(list(species_mappings.keys()) + list(parameter_mappings.keys()), key=lambda x: len(x),
reverse=True)
replacements = [parameter_mappings[name] if name in parameter_mappings else species_mappings[name]
for name in names]
sanitized_function = self.function
sanitized_function = self.function_string
for id, name in enumerate(names):
sanitized_function = sanitized_function.replace(name, "{" + str(id) + "}")
return sanitized_function.format(*replacements)
2 changes: 1 addition & 1 deletion gillespy2/sbml/SBMLexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __add_function_definitions(function_definition_list, model):
for name, function_def in function_definition_list.items():
func_def = model.createFunctionDefinition()
func_def.setId(name)
func_str = f"lambda({func_def.args}, {func_def.function_string})"
func_str = f"lambda({function_def.get_arg_string()}, {function_def.function_string})"
function = __get_math(func_str)
func_def.setMath(function)

Expand Down
3 changes: 2 additions & 1 deletion gillespy2/solvers/cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from gillespy2.solvers.cpp.ode_c_solver import ODECSolver
from gillespy2.solvers.cpp.tau_leaping_c_solver import TauLeapingCSolver
from gillespy2.solvers.cpp.variable_ssa_c_solver import VariableSSACSolver
from gillespy2.solvers.cpp.tau_hybrid_c_solver import TauHybridCSolver

# Check to see if we're missing any dependencies.
from .build.build_engine import BuildEngine
Expand All @@ -34,4 +35,4 @@
)

__all__ = ['SSACSolver', 'VariableSSACSolver']
__all__ = ['SSACSolver', 'ODECSolver', 'TauLeapingCSolver', 'VariableSSACSolver']
__all__ = ['SSACSolver', 'ODECSolver', 'TauLeapingCSolver', 'VariableSSACSolver', 'TauHybridCSolver']
7 changes: 6 additions & 1 deletion gillespy2/solvers/cpp/build/build_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

class BuildEngine():
template_definitions_name = "template_definitions.h"
template_options_name = "template_opts.h"

def __init__(self, debug: bool = False, output_dir: str = None):
self.self_dir = Path(__file__).parent
Expand Down Expand Up @@ -68,7 +69,7 @@ def get_missing_dependencies(cls) -> "list[str]":

return missing

def prepare(self, model: Model, variable=False) -> str:
def prepare(self, model: Model, variable=False, custom_definitions: "dict[str, str]" = None) -> str:
"""
Prepare the template directory for compilation.
The following operations will be performed:
Expand Down Expand Up @@ -109,6 +110,10 @@ def prepare(self, model: Model, variable=False) -> str:
template_file = self.template_dir.joinpath(self.template_definitions_name)
template_file.unlink()
template_gen.write_template(str(template_file), model, variable)
if custom_definitions is not None:
options_file = self.template_dir.joinpath(self.template_options_name)
options_file.unlink()
template_gen.write_definitions(str(options_file), custom_definitions)

# With all required information gathered, create a Make instance.
self.make = Make(str(self.makefile), str(self.output_dir), str(self.obj_dir))
Expand Down
8 changes: 1 addition & 7 deletions gillespy2/solvers/cpp/build/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,11 @@ def __init__(self, makefile: str, output_dir: str, obj_dir: str = None):
self.output_file = Path(self.output_dir, self.output_file)

def prebuild(self):
self.__execute("prebuild")
self.__execute("build")

def build_simulation(self, simulation_name: str, **kwargs):
self.__execute(simulation_name, **kwargs)

def clean(self):
self.__execute("clean")

def clean_all(self):
self.__execute("clean_all")

def __execute(self, target: str, **kwargs):
# Default make arguments.
args_dict = {
Expand Down
Loading

0 comments on commit 664194a

Please sign in to comment.