KarrLab / wc_sim

A multi-algorithmic simulator for whole-cell models
MIT License
6 stars 2 forks source link

Implement Monte Carlo simulations #66

Open artgoldberg opened 4 years ago

artgoldberg commented 4 years ago

Finish writing simulation.run_batch(). Can reuse this code to make subdirs for results.

        # make a time-stamped sub-dir for this run
        time_stamped_sub_dir = os.path.join(results_sup_dir, datetime.datetime.now().strftime(
            '%Y-%m-%d-%H-%M-%S'))
        if os.path.exists(time_stamped_sub_dir):
            raise MultialgorithmError("timestamped sub-directory of results_dir ({}) already exists".format(
                time_stamped_sub_dir))
        else:
            os.makedirs(time_stamped_sub_dir)
        # update results_dir
        args['results_dir'] = time_stamped_sub_dir
artgoldberg commented 4 years ago

This test code can be reused

def test_ckpt_dir_processing_2(self):
    # checkpoints_dir exists, and is empty
    root_dir = self.args['results_dir']
    self.simulation.process_and_validate_args(self.args)
    # process_and_validate_args creates 1 timestamped sub-dir
    self.assertEqual(len(os.listdir(root_dir)), 1)

def test_ckpt_dir_processing_4(self):
    # timestamped sub-directory of checkpoints-dir already exists
    root_dir = self.args['results_dir']
    self.simulation.process_and_validate_args(self.args)
    # given the chance, albeit small, that the second has advanced and
    # a different timestamped sub-directory is made, try repeatedly to create the error
    # the for loop takes about 0.01 sec
    raised = False
    for i in range(10):
        self.args['results_dir'] = root_dir
        try:
            self.simulation.process_and_validate_args(self.args)
        except:
            raised = True
    self.assertTrue(raised)