Exemplo n.º 1
0
    def test_read_in_savedir_files_unknown(self):
        mcstat = gf.setup_case()
        savedir = gf.generate_temp_folder()
        mcstat.simulation_options.savedir = savedir
        mcstat.simulation_options.save_to_txt = True
        mcstat._MCMC__save_to_log_file(chains=mcstat._MCMC__chains,
                                       start=0,
                                       end=100)
        mcstat._MCMC__save_to_log_file(chains=[
            dict(mtx=np.dot(mcstat._covariance._R.transpose(),
                            mcstat._covariance._R))
        ],
                                       start=0,
                                       end=100,
                                       covmtx=True)

        out = CP.read_in_savedir_files(savedir, extension='unknown')
        self.assertEqual(out, None, msg='Expect None')
        shutil.rmtree(savedir)
Exemplo n.º 2
0
    def test_read_in_savedir_files_txt(self):
        mcstat = gf.setup_case()
        savedir = gf.generate_temp_folder()
        mcstat.simulation_options.savedir = savedir
        mcstat.simulation_options.save_to_txt = True
        mcstat._MCMC__save_to_log_file(chains=mcstat._MCMC__chains,
                                       start=0,
                                       end=100)
        mcstat._MCMC__save_to_log_file(chains=[
            dict(mtx=np.dot(mcstat._covariance._R.transpose(),
                            mcstat._covariance._R))
        ],
                                       start=0,
                                       end=100,
                                       covmtx=True)

        out = CP.read_in_savedir_files(savedir, extension='txt')
        StandardCheck(out, mcstat)
        shutil.rmtree(savedir)
Exemplo n.º 3
0
    def test_print_log_files(self):
        mcstat = gf.setup_case()
        savedir = gf.generate_temp_folder()
        mcstat.simulation_options.savedir = savedir

        mcstat.simulation_options.save_to_bin = True

        chains = mcstat._MCMC__chains
        mcstat._MCMC__save_to_log_file(chains=chains, start=0, end=100)

        capturedOutput = io.StringIO()
        sys.stdout = capturedOutput
        CP.print_log_files(savedir)
        sys.stdout = sys.__stdout__

        self.assertTrue(isinstance(capturedOutput.getvalue(), str),
                        msg='Should contain a string')
        self.assertTrue('Display log file:' in capturedOutput.getvalue(),
                        msg='Expect string to contain these words')
        shutil.rmtree(savedir)
Exemplo n.º 4
0
 def test_covmtx_save_to_log_file(self):
     mcstat = gf.setup_case()
     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'
     tmptxtfile = tmpfolder + os.sep + 'covchainfile.txt'
     savecount, lastbin = mcstat._MCMC__save_to_log_file(chains=[
         dict(mtx=np.dot(mcstat._covariance._R.transpose(),
                         mcstat._covariance._R))
     ],
                                                         start=0,
                                                         end=100,
                                                         covmtx=True)
     self.assertEqual(savecount, 0, msg='Expect 0')
     self.assertEqual(lastbin, 100, msg='Expect lastbin = end = 100')
     self.assertTrue(os.path.isfile(tmpfile),
                     msg=str('File exists: {}'.format(tmpfile)))
     self.assertTrue(os.path.isfile(tmptxtfile),
                     msg=str('File exists: {}'.format(tmptxtfile)))
     mcstat.simulation_options.save_to_bin = True
     mcstat.simulation_options.save_to_txt = False
     tmpfile = tmpfolder + os.sep + 'binlogfile.txt'
     tmpbinfile = tmpfolder + os.sep + 'covchainfile.h5'
     savecount, lastbin = mcstat._MCMC__save_to_log_file(chains=[
         dict(mtx=np.dot(mcstat._covariance._R.transpose(),
                         mcstat._covariance._R))
     ],
                                                         start=0,
                                                         end=100,
                                                         covmtx=True)
     self.assertEqual(savecount, 0, msg='Expect 0')
     self.assertEqual(lastbin, 100, msg='Expect lastbin = end = 100')
     self.assertTrue(os.path.isfile(tmpfile),
                     msg=str('File exists: {}'.format(tmpfile)))
     self.assertTrue(os.path.isfile(tmpbinfile),
                     msg=str('File exists: {}'.format(tmpbinfile)))
     shutil.rmtree(tmpfolder)
Exemplo n.º 5
0
        mcstat._MCMC__save_to_log_file(chains=[
            dict(mtx=np.dot(mcstat._covariance._R.transpose(),
                            mcstat._covariance._R))
        ],
                                       start=0,
                                       end=100,
                                       covmtx=True)

        out = CP.read_in_savedir_files(savedir, extension='unknown')
        self.assertEqual(out, None, msg='Expect None')
        shutil.rmtree(savedir)


# -------------------
def setup_problem(parallel_dir, case='binary'):
    mcstat = gf.setup_case()
    for ii in range(3):
        chain_dir = str('chain_{}'.format(ii))
        mcstat.simulation_options.savedir = str('{}{}{}'.format(
            parallel_dir, os.sep, chain_dir))
        if case == 'binary':
            mcstat.simulation_options.save_to_bin = True
            mcstat.simulation_options.save_to_txt = False
            mcstat._MCMC__save_to_log_file(chains=mcstat._MCMC__chains,
                                           start=0,
                                           end=100)
            mcstat._MCMC__save_to_log_file(chains=[
                dict(mtx=np.dot(mcstat._covariance._R.transpose(),
                                mcstat._covariance._R))
            ],
                                           start=0,