Пример #1
0
 def test_verbose(self):
     solver = CupSodaSimulator(model, tspan=self.tspan, verbose=True,
                               integrator_options={'atol': 1e-12,
                                                   'rtol': 1e-12,
                                                   'vol': 1e-5,
                                                   'max_steps': 20000})
     solver.run()
Пример #2
0
 def test_verbose(self):
     solver = CupSodaSimulator(model, tspan=self.tspan, verbose=True,
                               vol=1e-5,
                               integrator_options={'atol': 1e-12,
                                                   'rtol': 1e-12,
                                                   'max_steps': 20000})
     solver.run()
Пример #3
0
 def test_multi_chunks(self):
     sim = CupSodaSimulator(model, tspan=self.tspan, verbose=False,
                            initials=self.y0,
                            integrator_options={'atol': 1e-12,
                                                'rtol': 1e-12,
                                                'chunksize': 25,
                                                'max_steps': 20000})
     res = sim.run()
     assert res.nsims == self.n_sims
Пример #4
0
 def test_multi_chunks(self):
     sim = CupSodaSimulator(model,
                            tspan=self.tspan,
                            verbose=False,
                            initials=self.y0,
                            integrator_options={
                                'atol': 1e-12,
                                'rtol': 1e-12,
                                'chunksize': 25,
                                'max_steps': 20000
                            })
     res = sim.run()
     assert res.nsims == self.n_sims
Пример #5
0
 def setUp(self):
     self.n_sims = 50
     self.tspan = np.linspace(0, 500, 101)
     self.solver = CupSodaSimulator(model, tspan=self.tspan, verbose=False,
                                    integrator_options={'atol': 1e-12,
                                                        'rtol': 1e-12,
                                                        'max_steps': 20000})
     len_model_species = len(model.species)
     y0 = np.zeros((self.n_sims, len_model_species))
     for ic in model.initial_conditions:
         for j in range(len_model_species):
             if str(ic[0]) == str(model.species[j]):
                 y0[:, j] = ic[1].value
                 break
     self.y0 = y0
Пример #6
0
def run():
    n_sims = 100
    vol = model.parameters['vol'].value
    tspan = np.linspace(0, 500, 501)
    sim = CupSodaSimulator(model,
                           tspan,
                           vol=vol,
                           verbose=True,
                           integrator_options={
                               'atol': 1e-12,
                               'rtol': 1e-6,
                               'max_steps': 20000
                           })

    # Rate constants
    param_values = np.ones((n_sims, len(model.parameters)))
    for i in range(len(param_values)):
        for j in range(len(param_values[i])):
            param_values[i][j] *= model.parameters[j].value

    # Initial concentrations
    initials = np.zeros((n_sims, len(model.species)))
    for i in range(len(initials)):
        for ic in model.initial_conditions:
            for j in range(len(initials[i])):
                if str(ic[0]) == str(model.species[j]):
                    initials[i][j] = ic[1].value
                    break

    x = sim.run(initials=initials, param_values=param_values)

    # Plot results of the first simulation
    t = x.tout[0]
    plt.plot(t, x.all[0]['CT'], lw=2, label='CT')  # should be constant
    plt.plot(t, x.all[0]['YT'], lw=2, label='YT')
    plt.plot(t, x.all[0]['M'], lw=2, label='M')

    plt.xlabel('time')
    plt.ylabel('population')
    plt.legend(loc=0)

    plt.show()
Пример #7
0
def run():
    n_sims = 100
    vol = model.parameters['vol'].value
    tspan = np.linspace(0, 500, 501)
    sim = CupSodaSimulator(model, tspan, verbose=True,
                           integrator_options={'atol' : 1e-12,
                                               'rtol' : 1e-6,
                                               'vol': vol,
                                               'max_steps' :20000})

    # Rate constants
    param_values = np.ones((n_sims, len(model.parameters)))
    for i in range(len(param_values)):
        for j in range(len(param_values[i])):
            param_values[i][j] *= model.parameters[j].value

    # Initial concentrations
    initials = np.zeros((n_sims, len(model.species)))
    for i in range(len(initials)):
        for ic in model.initials:
            for j in range(len(initials[i])):
                if str(ic.pattern) == str(model.species[j]):
                    initials[i][j] = ic.value.value
                    break

    x = sim.run(initials=initials, param_values=param_values)

    # Plot results of the first simulation
    t = x.tout[0]
    plt.plot(t, x.all[0]['CT'], lw=2, label='CT')  # should be constant
    plt.plot(t, x.all[0]['YT'], lw=2, label='YT')
    plt.plot(t, x.all[0]['M'],  lw=2, label='M')

    plt.xlabel('time')
    plt.ylabel('population')
    plt.legend(loc=0)

    plt.show()
Пример #8
0
 def setUp(self):
     self.n_sims = 50
     self.tspan = np.linspace(0, 500, 101)
     self.solver = CupSodaSimulator(model, tspan=self.tspan, verbose=False,
                                    integrator_options={'atol': 1e-12,
                                                        'rtol': 1e-12,
                                                        'max_steps': 20000})
     len_model_species = len(model.species)
     y0 = np.zeros((self.n_sims, len_model_species))
     for ic in model.initials:
         for j in range(len_model_species):
             if str(ic.pattern) == str(model.species[j]):
                 y0[:, j] = ic.value.value
                 break
     self.y0 = y0
Пример #9
0
class TestCupSODASimulatorSingle(object):
    def setUp(self):
        self.n_sims = 50
        self.tspan = np.linspace(0, 500, 101)
        self.solver = CupSodaSimulator(model, tspan=self.tspan, verbose=False,
                                       integrator_options={'atol': 1e-12,
                                                           'rtol': 1e-12,
                                                           'max_steps': 20000})
        len_model_species = len(model.species)
        y0 = np.zeros((self.n_sims, len_model_species))
        for ic in model.initials:
            for j in range(len_model_species):
                if str(ic.pattern) == str(model.species[j]):
                    y0[:, j] = ic.value.value
                    break
        self.y0 = y0

    def test_use_of_volume(self):
        # Initial concentrations
        self.solver.run(initials=self.y0)
        print(self.solver.vol)
        assert self.solver.vol is None
        self.solver.vol = 1e-20
        assert self.solver.vol == 1e-20

    def test_integrator_options(self):
        assert self.solver.opts['atol'] == 1e-12
        assert self.solver.opts['rtol'] == 1e-12
        assert self.solver.opts['max_steps'] == 20000

    def test_arguments(self):
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', "Neither 'param_values' nor "
                                              "'initials' were supplied.")
            self.solver.run(param_values=None, initials=None)

    def test_memory_usage(self):
        assert self.solver.opts['memory_usage'] == 'sharedconstant'
        self.solver.run(initials=self.y0)  # memory_usage='sharedconstant'
        self.solver.opts['memory_usage'] = 'global'
        self.solver.run(initials=self.y0)
        self.solver.opts['memory_usage'] = 'shared'
        self.solver.run(initials=self.y0)

    def test_n_blocks(self):
        print(self.solver.n_blocks)
        self.solver.n_blocks = 128
        assert self.solver.n_blocks == 128
        self.solver.run(initials=self.y0)

    @raises(ValueError)
    def test_set_nblocks_str(self):
        self.solver.n_blocks = 'fail'

    @raises(ValueError)
    def test_set_nblocks_0(self):
        self.solver.n_blocks = 0

    def test_run_tyson(self):
        # Rate constants
        len_parameters = len(model.parameters)
        param_values = np.ones((self.n_sims, len_parameters))
        for j in range(len_parameters):
            param_values[:, j] *= model.parameters[j].value
        simres = self.solver.run(initials=self.y0)
        print(simres.observables)
        self.solver.run(param_values=None, initials=self.y0)
        self.solver.run(param_values=param_values, initials=self.y0)
        self.solver.run(param_values=param_values, initials=self.y0)

    def test_verbose(self):
        solver = CupSodaSimulator(model, tspan=self.tspan, verbose=True,
                                  integrator_options={'atol': 1e-12,
                                                      'rtol': 1e-12,
                                                      'vol': 1e-5,
                                                      'max_steps': 20000})
        solver.run()

    def test_run_cupsoda_instance(self):
        run_cupsoda(model, tspan=self.tspan)

    @raises(ValueError)
    def test_invalid_init_kwarg(self):
        CupSodaSimulator(model, tspan=self.tspan, spam='eggs')

    @raises(ValueError)
    def test_invalid_integrator_option(self):
        CupSodaSimulator(model, tspan=self.tspan,
                         integrator_options={'spam': 'eggs'})
def run_cupsoda(tspan, model, simulations, vol, name, mem):
    tpb = 32

    solver = CupSodaSimulator(model, tspan, atol=ATOL, rtol=RTOL, gpu=0,
                              max_steps=mxstep, verbose=False, vol=vol,
                              obs_species_only=True,
                              memory_usage=mem_dict[mem])

    cols = ['model', 'nsims', 'tpb', 'mem', 'cupsodatime', 'cupsoda_io_time',
            'pythontime', 'rtol', 'atol', 'mxsteps', 't_end', 'n_steps', 'vol',
            'card']
    generate_equations(model)
    nominal_values = np.array([p.value for p in model.parameters])
    all_output = []
    for num_particles in simulations:
        # set the number of blocks to make it 16 threads per block
        n_blocks = int(np.ceil(1. * num_particles / tpb))
        solver.n_blocks = n_blocks

        # create a matrix of initial conditions
        c_matrix = np.zeros((num_particles, len(nominal_values)))
        c_matrix[:, :] = nominal_values
        y0 = np.zeros((num_particles, len(model.species)))
        for ic in model.initial_conditions:
            for j in range(len(model.species)):
                if str(ic[0]) == str(model.species[j]):
                    y0[:, j] = ic[1].value
                    break

        # setup a unique log output file to extract timing from
        log_file = 'logfile_{}.log'.format(num_particles)
        # remove it if it already exists (happens if rerunning simulation)
        if os.path.exists(log_file):
            os.remove(log_file)

        setup_logger(logging.INFO, file_output=log_file, console_output=True)
        start_time = time.time()

        # run the simulations
        x = solver.run(param_values=c_matrix, initials=y0)

        end_time = time.time()

        # create an emtpy list to put all data for this run
        out_list = list()
        out_list.append(name)
        out_list.append(num_particles)
        out_list.append(str(tpb))
        out_list.append(mem)
        cupsoda_time = 'error'
        total_time = 'error'
        with open(log_file, 'r') as f:
            for line in f:
                if 'reported time' in line:
                    good_line = line.split(':')[-1].split()[0]
                    cupsoda_time = float(good_line)
                if 'I/O time' in line:
                    good_line = line.split(':')[-1].split()[0]
                    total_time = float(good_line)
            f.close()

        out_list.append(cupsoda_time)
        out_list.append(total_time)
        out_list.append(end_time - start_time)
        out_list.append(RTOL)
        out_list.append(ATOL)
        out_list.append(len(tspan))
        out_list.append(mxstep)
        out_list.append(np.max(tspan))
        out_list.append(vol)
        out_list.append(card)
        all_output.append(out_list)
        print(" ".join(str(i) for i in out_list))
        print('out==')
        print(x.observables[0][0])
        print(x.observables[0][-1])
        print('==out\n')

    df = pd.DataFrame(all_output, columns=cols)
    print(df)
    df.to_csv('{}_cupsoda_timings_{}.csv'.format(name, mem), index=False)
    return df
Пример #11
0
 def test_invalid_integrator_option(self):
     CupSodaSimulator(model,
                      tspan=self.tspan,
                      integrator_options={'spam': 'eggs'})
Пример #12
0
 def test_invalid_init_kwarg(self):
     CupSodaSimulator(model, tspan=self.tspan, spam='eggs')
Пример #13
0
class TestCupSODASimulatorSingle(object):
    def setUp(self):
        self.n_sims = 50
        self.tspan = np.linspace(0, 500, 101)
        self.solver = CupSodaSimulator(model,
                                       tspan=self.tspan,
                                       verbose=False,
                                       integrator_options={
                                           'atol': 1e-12,
                                           'rtol': 1e-12,
                                           'max_steps': 20000
                                       })
        len_model_species = len(model.species)
        y0 = np.zeros((self.n_sims, len_model_species))
        for ic in model.initials:
            for j in range(len_model_species):
                if str(ic.pattern) == str(model.species[j]):
                    y0[:, j] = ic.value.value
                    break
        self.y0 = y0

    def test_use_of_volume(self):
        # Initial concentrations
        self.solver.run(initials=self.y0)
        print(self.solver.vol)
        assert self.solver.vol is None
        self.solver.vol = 1e-20
        assert self.solver.vol == 1e-20

    def test_integrator_options(self):
        assert self.solver.opts['atol'] == 1e-12
        assert self.solver.opts['rtol'] == 1e-12
        assert self.solver.opts['max_steps'] == 20000

    def test_arguments(self):
        with warnings.catch_warnings():
            warnings.filterwarnings(
                'ignore', "Neither 'param_values' nor "
                "'initials' were supplied.")
            self.solver.run(param_values=None, initials=None)

    def test_memory_usage(self):
        assert self.solver.opts['memory_usage'] == 'sharedconstant'
        self.solver.run(initials=self.y0)  # memory_usage='sharedconstant'
        self.solver.opts['memory_usage'] = 'global'
        self.solver.run(initials=self.y0)
        self.solver.opts['memory_usage'] = 'shared'
        self.solver.run(initials=self.y0)

    def test_n_blocks(self):
        print(self.solver.n_blocks)
        self.solver.n_blocks = 128
        assert self.solver.n_blocks == 128
        self.solver.run(initials=self.y0)

    @raises(ValueError)
    def test_set_nblocks_str(self):
        self.solver.n_blocks = 'fail'

    @raises(ValueError)
    def test_set_nblocks_0(self):
        self.solver.n_blocks = 0

    def test_run_tyson(self):
        # Rate constants
        len_parameters = len(model.parameters)
        param_values = np.ones((self.n_sims, len_parameters))
        for j in range(len_parameters):
            param_values[:, j] *= model.parameters[j].value
        simres = self.solver.run(initials=self.y0)
        print(simres.observables)
        self.solver.run(param_values=None, initials=self.y0)
        self.solver.run(param_values=param_values, initials=self.y0)
        self.solver.run(param_values=param_values, initials=self.y0)

    def test_verbose(self):
        solver = CupSodaSimulator(model,
                                  tspan=self.tspan,
                                  verbose=True,
                                  integrator_options={
                                      'atol': 1e-12,
                                      'rtol': 1e-12,
                                      'vol': 1e-5,
                                      'max_steps': 20000
                                  })
        solver.run()

    def test_run_cupsoda_instance(self):
        run_cupsoda(model, tspan=self.tspan)

    @raises(ValueError)
    def test_invalid_init_kwarg(self):
        CupSodaSimulator(model, tspan=self.tspan, spam='eggs')

    @raises(ValueError)
    def test_invalid_integrator_option(self):
        CupSodaSimulator(model,
                         tspan=self.tspan,
                         integrator_options={'spam': 'eggs'})
Пример #14
0
#    repeated_parameter_values[:, idx] = sample_lognormal(par, size=samples)
# np.save('earm_diff_IC_par0.npy', repeated_parameter_values)

repeated_parameter_values = np.load('earm_diff_IC_par0.npy')
rate_params = model.parameters_rules()
rate_idxs = [idx for idx, p in enumerate(model.parameters) if p in rate_params]
for par_idx in rate_idxs:
    repeated_parameter_values[:, par_idx] = par_clus4[par_idx]

t = np.linspace(0, 20000, 100)

vol = 1e-19
integrator_opt = {'rtol': 1e-6, 'atol': 1e-6, 'mxsteps': 20000}
sims = CupSodaSimulator(model,
                        tspan=t,
                        obs_species_only=False,
                        gpu=0,
                        memory_usage='shared_constant',
                        vol=vol,
                        integrator_options=integrator_opt).run(
                            param_values=repeated_parameter_values)
sims.save('earm_cupsoda_sims_ic_par1.h5')

signatures = run_tropical_multi(model=model,
                                simulations=sims,
                                cpu_cores=30,
                                verbose=True)

with open('earm_signatures_ic_par1.pickle', 'wb') as handle:
    pickle.dump(signatures, handle, protocol=pickle.HIGHEST_PROTOCOL)