Created
January 16, 2021 21:28
-
-
Save jmuhlich/d72c23dcd965f39ede3811fc451e6e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
import importlib | |
import time | |
from pysb.simulator import ScipyOdeSimulator | |
import pysb.bng | |
import numpy as np | |
def benchmark(model, sim_kwargs): | |
tspan = np.linspace(0, 10000, 1000) | |
start = time.time() | |
sim = ScipyOdeSimulator(model, tspan, **sim_kwargs) | |
end = time.time() | |
print(" simulator init: %.3g" % (end-start)) | |
start = time.time() | |
sim.run() | |
end = time.time() | |
print(" first sim: %.3g" % (end-start)) | |
times = [] | |
for i in range(10): | |
start = time.time() | |
sim.run() | |
end = time.time() | |
times.append(end-start) | |
# Discard worst two times. | |
times = sorted(times)[:-2] | |
mean = np.mean(times) | |
std = np.std(times) | |
print(" subsequent sims: %.3g +/- %.3g" % (mean, std)) | |
model = importlib.import_module(sys.argv[1]).model | |
print(f"Model: {model.name}") | |
ge_kwargs = {} | |
sim_kwargs = {} | |
if model.name.endswith('.egfr_extended'): | |
print("==> egfr_extended detected") | |
ge_kwargs['max_iter'] = 5 | |
elif model.name == 'MARM1': | |
print("==> MARM1 detected") | |
import pandas as pd | |
param_sets = pd.read_csv('parameter_sets.csv', index_col=0) | |
param_sets = param_sets.drop('chi2', axis=1) | |
params = param_sets.iloc[0].to_dict() | |
sim_kwargs['param_values'] = params | |
model.initials = [ | |
ic for i, ic in enumerate(model.initials) if i not in (0, 1) | |
] | |
for arg in sys.argv[2:]: | |
k, v = arg.split("=") | |
if v == "True": | |
v = True | |
elif v == "False": | |
v = False | |
elif not re.search(r'[^0-9]', v): | |
v = int(v) | |
else: | |
try: | |
v = float(v) | |
except ValueError: | |
pass | |
sim_kwargs[k] = v | |
if not model.reactions: | |
print("Generating equations...") | |
pysb.bng.generate_equations(model, **ge_kwargs) | |
print() | |
print("Running benchmark...") | |
benchmark(model, sim_kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment