def test_profile(): sc.heading('Test profiling functions') def slow_fn(): n = 10000 int_list = [] int_dict = {} for i in range(n): int_list.append(i) int_dict[i] = i return def big_fn(): n = 1000 int_list = [] int_dict = {} for i in range(n): int_list.append([i] * n) int_dict[i] = [i] * n return class Foo: def __init__(self): self.a = 0 return def outer(self): for i in range(100): self.inner() return def inner(self): for i in range(1000): self.a += 1 return foo = Foo() try: sc.mprofile( big_fn) # NB, cannot re-profile the same function at the same time except TypeError as E: # This happens when re-running this script print( f'Unable to re-profile memory function; this is usually not cause for concern ({E})' ) sc.profile(run=foo.outer, follow=[foo.outer, foo.inner]) lp = sc.profile(slow_fn) return lp
def cova(): sc.tic() s1 = cv.Sim(pop_size=ps2, pop_type='random') s1.initialize() sc.toc() sc.tic() s2 = cv.Sim(pop_size=ps2, pop_type='hybrid') s2.initialize() sc.toc() sc.tic() s3 = cv.Sim(pop_size=ps2, pop_type='synthpops') s3.initialize() sc.toc() sc.tic() s4 = cv.Sim(pop_size=ps1, pop_type='synthpops') s4.initialize() sc.toc() return [s1, s2, s3, s4] ps = synth() sc.mprofile(run=synth, follow=synth)
sim.run() popsize = popsizes[1] print(f'Working on {popsize} for {cv.defaults.default_int}...') sim = cv.Sim(pop_size=popsize, verbose=0) sim.run() popsize = popsizes[2] print(f'Working on {popsize} for {cv.defaults.default_int}...') sim = cv.Sim(pop_size=popsize, verbose=0) sim.run() return sim sc.mprofile(mrun, mrun) #%% Now check timings timings = [] for popsize in popsizes: for r in range(repeats): print( f'Working on {popsize} for {cv.defaults.default_int}, iteration {r}...' ) T = sc.tic() sim = cv.Sim(pop_size=popsize, verbose=0) sim.run() out = sc.toc(T, output=True) timings.append({'popsize': popsize, 'elapsed': out}) df = pd.DataFrame.from_dict(timings)
# ) # sim = cv.Sim(pars=pars) # sim.run() # h = hpy() # print(h.heap()) # Benchmark the simulation import sciris as sc import covasim as cv def make_run_sim(): sim = cv.Sim(n_days=180, verbose=0) sim.init_people() sim.initialize() sim.run() del sim.people.contacts del sim.people del sim.popdict return sim sim = make_run_sim() to_profile = 'run' # Must be one of the options listed below...currently only 1 sc.mprofile(run=make_run_sim, follow=make_run_sim)