def test_check_options_output_with_both_false(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.save_to_bin = False
     mcstat.simulation_options.save_to_txt = False
     options = check_options_output(options=mcstat.simulation_options)
     self.assertTrue(options.save_to_bin, msg='Expect True')
     self.assertFalse(options.save_to_txt, msg='Expect False')
 def test_check_options_output(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.save_to_bin = True
     mcstat.simulation_options.save_to_txt = True
     options = check_options_output(options=mcstat.simulation_options)
     self.assertTrue(options.save_to_bin, msg='Expect True')
     self.assertTrue(options.save_to_txt, msg='Expect True')
 def test_run_serial_simulation(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.nsimu = 100
     mcstat.simulation_options.save_to_bin = False
     mcstat.simulation_options.save_to_txt = False
     simulation_results = run_serial_simulation(mcstat)
     results = simulation_results.results
     self.assertTrue(isinstance(results, dict),
                     msg='Expect dictionary return item')
     self.assertEqual(results['nsimu'], 100, msg='Expect 100 simulations')
Example #4
0
 def test_run_simulation(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.nsimu = 100
     mcstat.simulation_options.save_to_bin = False
     mcstat.simulation_options.save_to_txt = False
     mcstat.custom_samplers.append(gf.CustomSampler(nsimu=100))
     tmpfolder = gf.generate_temp_folder()
     mcstat.simulation_options.savedir = tmpfolder
     mcstat.run_simulation()
     self.assertTrue(mcstat._mcmc_status,
                     msg='Expect True if successfully run')
 def test_unpack_mcmc_set(self):
     mcstat = gf.basic_mcmc()
     data, options, model, parameters = unpack_mcmc_set(mcset=mcstat)
     self.assertEqual(data, mcstat.data, msg='Expect structures to match')
     self.assertEqual(options,
                      mcstat.simulation_options,
                      msg='Expect structures to match')
     self.assertEqual(model,
                      mcstat.model_settings,
                      msg='Expect structures to match')
     self.assertEqual(parameters,
                      mcstat.parameters,
                      msg='Expect structures to match')
Example #6
0
 def test_run_simulation(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.nsimu = 100
     mcstat.simulation_options.save_to_bin = False
     mcstat.simulation_options.save_to_txt = False
     tmpfolder = gf.generate_temp_folder()
     mcstat.simulation_options.savedir = tmpfolder
     mcstat.run_simulation()
     self.assertTrue(mcstat._mcmc_status,
                     msg='Expect True if successfully run')
     check_these = ['mcmcplot', 'PI', 'chainstats']
     for ci in check_these:
         self.assertTrue(hasattr(mcstat, ci),
                         msg=str('object has attribute: {}'.format(ci)))
Example #7
0
 def test_save_to_log_file_txt(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.save_to_bin = False
     mcstat.simulation_options.save_to_txt = True
     tmpfolder = gf.generate_temp_folder()
     mcstat.simulation_options.savedir = tmpfolder
     chains = []
     chains.append(
         dict(file='chain', mtx=np.random.random_sample((1000, 3))))
     savecount, lastbin = mcstat._MCMC__save_to_log_file(chains=chains,
                                                         start=0,
                                                         end=100)
     self.assertEqual(savecount, 0, msg='Expect 0')
     self.assertEqual(lastbin, 100, msg='Expect lastbin = end = 100')
     shutil.rmtree(tmpfolder)
Example #8
0
    def test_save_to_log_file_txt_no_append(self):
        mcstat = gf.basic_mcmc()
        mcstat.simulation_options.save_to_bin = False
        mcstat.simulation_options.save_to_txt = True

        tmpfolder = gf.generate_temp_folder()
        mcstat.simulation_options.savedir = tmpfolder
        tmpfile = tmpfolder + os.sep + 'txtlogfile.txt'
        chains = []
        chains.append(
            dict(file='chain', mtx=np.random.random_sample((1000, 3))))
        savecount, lastbin = mcstat._MCMC__save_to_log_file(
            chains=chains, start=0, end=100, append_to_log=False)
        self.assertFalse(os.path.isfile(tmpfile),
                         msg=str('File exists: {}'.format(tmpfile)))
        shutil.rmtree(tmpfolder)
Example #9
0
 def test_no_save_to_log_file(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.save_to_bin = False
     mcstat.simulation_options.save_to_txt = False
     tmpfolder = gf.generate_temp_folder()
     mcstat.simulation_options.savedir = tmpfolder
     chains = []
     chains.append(
         dict(file='chain', mtx=np.random.random_sample((1000, 3))))
     savecount, lastbin = mcstat._MCMC__save_to_log_file(chains=chains,
                                                         start=0,
                                                         end=100)
     self.assertEqual(savecount, 0, msg='Expect 0')
     self.assertEqual(lastbin, 100, msg='Expect lastbin = end = 100')
     self.assertFalse(os.path.isdir(tmpfolder),
                      msg=str('Folder exists: {}'.format(tmpfolder)))
Example #10
0
 def test_run_simulation_with_json(self):
     mcstat = gf.basic_mcmc()
     mcstat.simulation_options.nsimu = 100
     mcstat.simulation_options.save_to_bin = False
     mcstat.simulation_options.save_to_txt = False
     tmpfile = gf.generate_temp_file(extension='json')
     tmpfolder = gf.generate_temp_folder()
     os.mkdir(tmpfolder)
     mcstat.simulation_options.savedir = tmpfolder
     mcstat.simulation_options.results_filename = tmpfile
     mcstat.simulation_options.save_to_json = True
     mcstat.run_simulation()
     self.assertTrue(mcstat._mcmc_status,
                     msg='Expect True if successfully run')
     check_these = ['mcmcplot', 'PI', 'chainstats']
     for ci in check_these:
         self.assertTrue(hasattr(mcstat, ci),
                         msg=str('object has attribute: {}'.format(ci)))
     shutil.rmtree(tmpfolder)
def setup_par_mcmc_basic():
    mcstat = gf.basic_mcmc()
    tmpfolder = gf.generate_temp_folder()
    mcstat.simulation_options.savedir = tmpfolder
    return mcstat, tmpfolder