Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ Implementation of the Tau Hybrid solver #557

Merged
merged 100 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
6d680a7
hybrid_compile
mdip226 Mar 1, 2021
e5e6242
copying
mdip226 Mar 7, 2021
a096ec6
share tau library
mdip226 Mar 15, 2021
3818e85
quicksave
mdip226 Mar 15, 2021
7678c9b
try to compile
mdip226 Mar 15, 2021
821b6e9
tau.h
mdip226 Mar 15, 2021
5f36565
merge
mdip226 Mar 15, 2021
397388a
settings
mdip226 Mar 22, 2021
2b7b4a5
compilation things
mdip226 Mar 29, 2021
614cafc
compilation things
mdip226 Mar 29, 2021
d041f76
checking type of simulation
mdip226 Mar 29, 2021
42343f1
finish simulationINIT
mdip226 Mar 29, 2021
3486915
add mode to species
mdip226 Apr 5, 2021
618cb0f
account for discrete/continuous modes in Species
mdip226 Apr 5, 2021
bb7faeb
naming simplification
mdip226 Apr 12, 2021
d46320a
partition species
mdip226 Apr 12, 2021
2f2ec83
init_species_mode()
mdip226 Apr 12, 2021
054c41f
create hybrid state vector
mdip226 Apr 19, 2021
46a682f
correct state initialization
mdip226 Apr 19, 2021
0ff2ecb
initalize means in partition
mdip226 Apr 19, 2021
4b3e434
initialize standard deviations
mdip226 Apr 19, 2021
de5a100
Merge branch 'develop' into Hybrid_C
jtcooper10 Apr 19, 2021
ab0c849
Init platform utils helper script
jtcooper10 Apr 19, 2021
4215b6c
Platform util function for `os.killpg`
jtcooper10 Apr 19, 2021
1661e94
Abstracts sim reader into custom class
jtcooper10 Apr 19, 2021
c6b8c6b
Platform-independent signal handlers in C solvers
jtcooper10 Apr 19, 2021
d35e32f
calculate means and sd for dynamic species in rxn
mdip226 Apr 26, 2021
9ba5f38
Merge branch 'Hybrid_C' of https://github.com/StochSS/GillesPy2 into …
mdip226 Apr 26, 2021
da4fbce
hybrid_state union typedef
mdip226 Apr 26, 2021
90cd6a5
start coefficient of variation calculation
mdip226 Apr 26, 2021
a34680d
indentation
mdip226 Apr 26, 2021
9e343c4
add switch_min, switch_tol to species
mdip226 Apr 26, 2021
2e5bde0
default values
mdip226 Apr 26, 2021
d412f92
flag species according to computed CV
mdip226 Apr 26, 2021
b9e57de
Merge branch 'develop' into Hybrid_C
jtcooper10 May 10, 2021
7a1369a
fix travis complaint
mdip226 May 10, 2021
ca6aef3
Merge branch 'Hybrid_C' of github.com:StochSS/GillesPy2 into Hybrid_C
jtcooper10 May 10, 2021
e80179c
Revert platform utils
jtcooper10 May 10, 2021
6532a48
add tau_args to simulation
mdip226 May 10, 2021
1cebaa0
Fix missing import in __init__.py
jtcooper10 May 10, 2021
afca4dd
URN initialization for reaction states
jtcooper10 May 14, 2021
664d054
Post-integration stochastic update
jtcooper10 May 14, 2021
b138f6e
Pure ODE implementation of hybrid solver
jtcooper10 May 14, 2021
b5bb180
TauHybridCSolver runnable
jtcooper10 May 18, 2021
bc3f8a6
Pure ODE solution for hybrid solver
jtcooper10 May 18, 2021
4afce39
Branchless propensity update in integrator
jtcooper10 May 18, 2021
fc8699b
Add reaction offsets to integration vector
jtcooper10 May 20, 2021
713f2ea
Move solver statistics helpers to a separate file
jtcooper10 Jun 1, 2021
88f5ffd
draft of flag_det_rxns()
mdip226 Jun 1, 2021
1627713
Fix segmentation faults in integrator RHS
jtcooper10 Jun 1, 2021
0337292
Hybrid simulation/model inheritance changes
jtcooper10 Jun 2, 2021
2432d76
Hybrid propensity function on hybrid simulation class
jtcooper10 Jun 2, 2021
52b1042
Separate base classes from runtime mutable state
jtcooper10 Jun 7, 2021
8b77eac
change maps to vectors
mdip226 Jun 8, 2021
a982203
calculate means and sd with tauArgs
mdip226 Jun 8, 2021
e05b3ce
Root-finding implementation
jtcooper10 Jun 9, 2021
3827c5f
Merge branch 'Hybrid_C' of https://github.com/StochSS/gillespy2 into …
jtcooper10 Jun 9, 2021
74b0327
Update hybrid solver with its own Makefile target
jtcooper10 Jun 9, 2021
d564439
Debug targets for makefile
jtcooper10 Jun 9, 2021
70aa132
Propensity updates during integration
jtcooper10 Jun 9, 2021
c334892
Update population values in integrator
jtcooper10 Jun 9, 2021
239a8b5
Update Makefile debug targets
jtcooper10 Jun 9, 2021
bae0c2c
Organize integrator's user data separately
jtcooper10 Jun 12, 2021
6be142c
Initial `Integrator` class
jtcooper10 Jun 12, 2021
e4871eb
Move N_Vector initialization into `integrator.cpp`
jtcooper10 Jun 14, 2021
7439dd8
Merge branch 'develop' of github.com:StochSS/GillesPy2 into hybrid-c
jtcooper10 Jun 15, 2021
fcbf474
Partition check in integrator RHS
jtcooper10 Jun 15, 2021
b6c17cc
Add `reset` function to integrator
jtcooper10 Jun 15, 2021
3250210
Clean up hybrid simulation definitions
jtcooper10 Jun 16, 2021
d923831
Invalid state loop
jtcooper10 Jun 16, 2021
804e05c
Hybrid output moved to float-only
jtcooper10 Jun 17, 2021
ec12374
"Valid" integrator reset + add Tau propensities
jtcooper10 Jun 17, 2021
8bd79dc
Primitive integrator reset
jtcooper10 Jun 18, 2021
ef546e2
Merge branch 'develop' into hybrid-c
jtcooper10 Jun 23, 2021
1da3d5a
Update hybrid solver to reflect build changes
jtcooper10 Jun 23, 2021
f441c14
Updates to save time computations
jtcooper10 Jun 23, 2021
937a5cd
Transition to differential equations for deterministic RHS
jtcooper10 Jun 23, 2021
b345142
Merge branch 'develop' into hybrid-c
jtcooper10 Jun 23, 2021
5962f28
Differential equations clear fix
jtcooper10 Jun 24, 2021
504c568
Update propensity evaluation for Tau select
jtcooper10 Jun 24, 2021
5ce96f9
Basic layout for Hybrid-specific templating
jtcooper10 Jun 24, 2021
1b42246
Write Hybrid options to `template_opts.h`
jtcooper10 Jun 24, 2021
ad38c5b
Working implementation of options injection
jtcooper10 Jun 25, 2021
47ca002
Fix tests so GitHub will stop sending emails telling me my tests failed
jtcooper10 Jun 25, 2021
7d7e272
Merge branch 'hybrid_c_utils' of https://github.com/StochSS/gillespy2…
jtcooper10 Jun 25, 2021
be941f6
Add flagging functions to solvers
jtcooper10 Jun 29, 2021
290af73
Fix ordering for reactions/products in utils
jtcooper10 Jul 1, 2021
58c6bba
Cleanup prep and consolidation
jtcooper10 Jul 1, 2021
9da3983
Update test suite to include hybrid solver
jtcooper10 Jul 1, 2021
8a810b6
Merge prep from develop
jtcooper10 Jul 1, 2021
3561f5f
Merge branch 'develop' into hybrid-c
jtcooper10 Jul 1, 2021
f57f81c
Add license headers to hybrid files
jtcooper10 Jul 1, 2021
155c122
Merge branch 'develop' into hybrid-c
jtcooper10 Jul 2, 2021
5d3df8b
PR review
jtcooper10 Jul 4, 2021
5c79b45
Fix for multi-trajectory simulations
jtcooper10 Jul 6, 2021
934a30c
Fix for continuous output on certain dynamic models
jtcooper10 Jul 6, 2021
a0c0a54
Add error handling for CVODE methods
jtcooper10 Jul 6, 2021
a86935b
Update ODE solver's initial populations to use `double`
jtcooper10 Jul 8, 2021
9487a45
Bug fixes in integrator
jtcooper10 Jul 14, 2021
49710b7
Add integrator guard to prevent infinite loops
jtcooper10 Jul 15, 2021
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
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, cusotm_definitions: "dict[str, str]" = None) -> str:
jtcooper10 marked this conversation as resolved.
Show resolved Hide resolved
"""
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 cusotm_definitions is not None:
options_file = self.template_dir.joinpath(self.template_options_name)
options_file.unlink()
template_gen.write_definitions(str(options_file), cusotm_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
7 changes: 7 additions & 0 deletions gillespy2/solvers/cpp/build/template_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def write_template(path: str, model: Model, variable=False):
# Get a dictionary of model defines and transform into a list of strings in
# `#define KEY VALUE` format.
defines = get_model_defines(model, variable)
write_definitions(path, defines)

def write_definitions(path: str, defines: "dict[str, str]"):
"""
"""
# Definition dict is transformed into a list of C++ macro definitions, with:
# `#define KEY VALUE` format.
template_lines = [(f"#define {key} {value}\n") for key, value in defines.items()]

# Write generated lines to the template file.
Expand Down
28 changes: 24 additions & 4 deletions gillespy2/solvers/cpp/c_base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ CXXFLAGS := -std=c++14 -Wall -O3
GPY_SOLVER ?= ssa
GPY_EXE_ARGS ?= --trajectories 1 --timesteps 21 --end 20
#######################################
.PHONY: run clean build profile ode ssa tau_leap
.PHONY: run clean build profile ode ssa tau_leap hybrid

### Input directories ###
CBASE_DIR ?= .
TEMPLATE_DIR ?= $(CBASE_DIR)/template
TEMPLATE_CPP := $(TEMPLATE_DIR)/template.cpp
SUNDIALS_SRC := $(CBASE_DIR)/Sundials/src
SUNDIALS_INC := $(CBASE_DIR)/Sundials/include
TAU_DIR := $(CBASE_DIR)/Tau
ODE_SOLVER_PATH := $(CBASE_DIR)/ode_cpp_solver
SSA_SOLVER_PATH := $(CBASE_DIR)/ssa_cpp_solver
TAU_LEAPING_SOLVER_PATH := $(CBASE_DIR)/tau_leaping_cpp_solver
TAU_HYBRID_SOLVER_PATH := $(CBASE_DIR)/tau_hybrid_cpp_solver
#########################

### Output directories ###
OBJ_DIR ?= $(CBASE_DIR)
INCLUDES := -I$(CBASE_DIR) -I$(SUNDIALS_INC) -I$(TEMPLATE_DIR)
INCLUDES := -I$(CBASE_DIR) -I$(SUNDIALS_INC) -I$(TEMPLATE_DIR) -I$(TAU_DIR)
SUNDIALS_OBJ ?= $(OBJ_DIR)
OUTPUT_DIR ?= $(CBASE_DIR)
ifeq ($(OS),Windows_NT)
Expand All @@ -42,10 +44,19 @@ SUNOBJ_PATHS := $(SUNOBJ:%.o=$(SUNDIALS_OBJ)/%.o)
GPY_SRC = model.cpp arg_parser.cpp
GPY_OBJ := $(GPY_SRC:%.cpp=$(OBJ_DIR)/%.o)

### DEPENDENCIES FOR TAU-LEAPING BASED SOLVERS ###
GPY_SRC_TAUBASE = tau.cpp
GPY_OBJ_TAUBASE := $(GPY_SRC_TAUBASE:%.cpp=$(OBJ_DIR)/%.o)

### DEPENDENCIES FOR ODE SOLVER ###
GPY_SRC_ODE = ODESimulation.cpp ODESolver.cpp
GPY_OBJ_ODE := $(GPY_SRC_ODE:%.cpp=$(OBJ_DIR)/%.o)

### DEPENDENCIES FOR HYBRID SOLVER ###
GPY_SRC_HYBRID = TauHybridSimulation.cpp TauHybridSolver.cpp HybridModel.cpp \
hybrid_template.cpp integrator.cpp
GPY_OBJ_HYBRID := $(GPY_SRC_HYBRID:%.cpp=$(OBJ_DIR)/%.o)

### DEPENDENCIES FOR SSA SOLVER ###
GPY_SRC_SSA = SSASimulation.cpp SSASolver.cpp
GPY_OBJ_SSA := $(GPY_SRC_SSA:%.cpp=$(OBJ_DIR)/%.o)
Expand All @@ -57,6 +68,9 @@ GPY_OBJ_TAU := $(GPY_SRC_TAU:%.cpp=$(OBJ_DIR)/%.o)
$(GPY_OBJ): $(OBJ_DIR)/%.o: $(CBASE_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

$(GPY_OBJ_HYBRID): $(OBJ_DIR)/%.o: $(TAU_HYBRID_SOLVER_PATH)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

$(GPY_OBJ_ODE): $(OBJ_DIR)/%.o: $(ODE_SOLVER_PATH)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

Expand All @@ -66,6 +80,9 @@ $(GPY_OBJ_SSA): $(OBJ_DIR)/%.o: $(SSA_SOLVER_PATH)/%.cpp
$(GPY_OBJ_TAU): $(OBJ_DIR)/%.o: $(TAU_LEAPING_SOLVER_PATH)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

$(GPY_OBJ_TAUBASE): $(OBJ_DIR)/%.o: $(TAU_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)

$(SUNOBJ_PATHS): $(SUNDIALS_OBJ)/%.o: $(SUNDIALS_SRC)/%.c
$(CXX) -c -o $@ $< $(CFLAGS) -I$(SUNDIALS_INC)
sundials: $(SUNOBJ_PATHS) ;
Expand All @@ -80,10 +97,13 @@ ode: $(GPY_ALL_DEPS) $(GPY_OBJ_ODE) $(SUNOBJ_PATHS)
ssa: $(GPY_ALL_DEPS) $(GPY_OBJ_SSA)
$(CXX) $(CXXFLAGS) -o $(OUTPUT_FILE) $^ $(INCLUDES)

tau_leap: $(GPY_ALL_DEPS) $(GPY_OBJ_TAU) $(TEMPLATE_CPP)
tau_leap: $(GPY_ALL_DEPS) $(GPY_OBJ_TAU) $(GPY_OBJ_TAUBASE)
$(CXX) $(CXXFLAGS) -o $(OUTPUT_FILE) $^ $(INCLUDES)

hybrid: $(GPY_ALL_DEPS) $(GPY_OBJ_HYBRID) $(GPY_OBJ_TAUBASE) $(SUNOBJ_PATHS)
$(CXX) $(CXXFLAGS) -o $(OUTPUT_FILE) $^ $(INCLUDES)

build: $(GPY_ALL_DEPS) $(GPY_OBJ_SSA) $(GPY_OBJ_ODE) $(GPY_OBJ_TAU) ;
build: $(GPY_ALL_DEPS) $(GPY_OBJ_TAUBASE) $(GPY_OBJ_SSA) $(GPY_OBJ_ODE) $(GPY_OBJ_TAU) $(GPY_OBJ_HYBRID)) ;

run: $(GPY_SOLVER)
$(OUTPUT_FILE) $(GPY_EXE_ARGS)
Expand Down
Loading