def test_short_run(self):
     """Are the MH sampler basic functionalities working?"""
     # Check that a file with the proper name was created
     output_file = os.path.join(
         self.folder, self.date+'_%d__1.txt' % self.number)
     self.assertTrue(os.path.exists(output_file))
     # Recover the data in it
     data = np.loadtxt(output_file)
     # Check that the sum of the first column adds up to the desired number
     self.assertEqual(np.sum(data[:, 0]), self.number)
     # Check that the analyze module works for this
     custom_command = 'info %s' % self.folder
     run(custom_command)
     ## verify that this command created the appropriate files
     expected_files = [
         'test_' + self.date + '.' + elem
         for elem in ['bestfit', 'covmat', 'h_info', 'v_info',
                      'info', 'log', 'tex']]
     for output_file in os.listdir(self.folder):
         if os.path.isfile(output_file):
             if output_file.find('.txt') == -1:
                 self.assertIn(output_file, expected_files)
     ## check if the plot folder was created, with the two pdf files
     self.assertTrue(os.path.isdir(
         os.path.join(self.folder, 'plots')))
     for pdf_file in os.listdir(
             os.path.join(self.folder, 'plots')):
         self.assertTrue(
             pdf_file.find('_triangle') != -1 or pdf_file.find('_1d') != -1)
Esempio n. 2
0
 def test_short_run(self):
     """Are the MH and IS sampler basic functionalities working?"""
     # Check that a file with the proper name was created
     output_chain = self.date+'_%d__1.txt' % self.number
     self.assertTrue(os.path.exists(
         os.path.join(self.folder, output_chain)))
     # Recover the data in it
     data = np.loadtxt(os.path.join(self.folder, output_chain))
     # Check that the sum of the first column adds up to the desired number
     self.assertEqual(np.sum(data[:, 0]), self.number)
     # Check that the analyze module works for this
     custom_command = 'info %s' % self.folder
     run(custom_command)
     ## verify that this command created the appropriate files
     expected_files = [
         'test_' + self.date + '.' + elem
         for elem in ['bestfit', 'covmat', 'h_info', 'v_info',
                      'info', 'log', 'tex']]
     for output_file in os.listdir(self.folder):
         if os.path.isfile(output_file):
             if output_file.find('.txt') == -1:
                 self.assertIn(output_file, expected_files)
     ## check if the plot folder was created, with the two pdf files
     self.assertTrue(os.path.isdir(
         os.path.join(self.folder, 'plots')))
     for pdf_file in os.listdir(
             os.path.join(self.folder, 'plots')):
         self.assertTrue(
             pdf_file.find('_triangle') != -1 or pdf_file.find('_1d') != -1)
     # Reset the "Information._id"
     Information._ids = count(0)
     ## Run an Importance sampling run on this data
     is_folder = self.folder + '_is'
     custom_command = (
         'run -p input/test_is.param -o %s' % is_folder +
         ' -m IS --IS-starting-folder %s' % self.folder)
     run(custom_command)
     # Check that the file has been copied, and that both the likelihood and
     # the multiplicity has been changed
     self.assertIn(output_chain, os.listdir(is_folder),
                   "The IS did not create the right chain")
     # Use these two runs to test the several folders option
     custom_command = 'info %s %s' % (
         self.folder, is_folder)
     run(custom_command)
     # Check that all expected files were created
     short_folder = os.path.join(self.folder.split(os.path.sep)[-1])
     short_is_folder = os.path.join(is_folder.split(os.path.sep)[-1])
     expected_files = set([
         '%s-vs-%s_triangle.pdf' % (short_folder, short_is_folder),
         '%s-vs-%s_1d.pdf' % (short_folder, short_is_folder),
         '%s_triangle.pdf' % short_folder,
         '%s_1d.pdf' % short_folder])
     self.assertSetEqual(expected_files, set(
         os.listdir(os.path.join(self.folder, 'plots'))))
     shutil.rmtree('%s' % is_folder)
 def test_short_run(self):
     """Are the MH and IS sampler basic functionalities working?"""
     # Check that a file with the proper name was created
     output_chain = self.date+'_%d__1.txt' % self.number
     self.assertTrue(os.path.exists(
         os.path.join(self.folder, output_chain)))
     # Recover the data in it
     data = np.loadtxt(os.path.join(self.folder, output_chain))
     # Check that the sum of the first column adds up to the desired number
     self.assertEqual(np.sum(data[:, 0]), self.number)
     # Check that the analyze module works for this
     custom_command = 'info %s' % self.folder
     run(custom_command)
     ## verify that this command created the appropriate files
     expected_files = [
         'test_' + self.date + '.' + elem
         for elem in ['bestfit', 'covmat', 'h_info', 'v_info',
                      'info', 'log', 'tex']]
     for output_file in os.listdir(self.folder):
         if os.path.isfile(output_file):
             if output_file.find('.txt') == -1:
                 self.assertIn(output_file, expected_files)
     ## check if the plot folder was created, with the two pdf files
     self.assertTrue(os.path.isdir(
         os.path.join(self.folder, 'plots')))
     for pdf_file in os.listdir(
             os.path.join(self.folder, 'plots')):
         self.assertTrue(
             pdf_file.find('_triangle') != -1 or pdf_file.find('_1d') != -1)
     ## Run an Importance sampling run on this data
     is_folder = self.folder + '_is'
     custom_command = (
         'run -p test_is.param -o %s' % is_folder +
         ' -m IS --IS-starting-folder %s' % self.folder)
     run(custom_command)
     # Check that the file has been copied, and that both the likelihood and
     # the multiplicity has been changed
     self.assertIn(output_chain, os.listdir(is_folder),
                   "The IS did not create the right chain")
     # Use these two runs to test the "--comp" option
     custom_command = 'info %s --comp %s --plot-2d always' % (
         self.folder, is_folder)
     run(custom_command)
     # Check that all expected files were created
     short_folder = os.path.join(self.folder.split(os.path.sep)[-1])
     short_is_folder = os.path.join(is_folder.split(os.path.sep)[-1])
     expected_files = set([
         '%s-vs-%s_triangle.pdf' % (short_folder, short_is_folder),
         '%s-vs-%s_1d.pdf' % (short_folder, short_is_folder),
         '%s_triangle.pdf' % short_folder,
         '%s_1d.pdf' % short_folder])
     self.assertSetEqual(expected_files, set(
         os.listdir(os.path.join(self.folder, 'plots'))))
     shutil.rmtree('%s' % is_folder)
 def test_short_run(self):
     """Are the MH and IS sampler basic functionalities working?"""
     # Check that a file with the proper name was created
     output_chain = self.date + "_%d__1.txt" % self.number
     self.assertTrue(os.path.exists(os.path.join(self.folder, output_chain)))
     # Recover the data in it
     data = np.loadtxt(os.path.join(self.folder, output_chain))
     # Check that the sum of the first column adds up to the desired number
     self.assertEqual(np.sum(data[:, 0]), self.number)
     # Check that the analyze module works for this
     custom_command = "info %s" % self.folder
     run(custom_command)
     ## verify that this command created the appropriate files
     expected_files = [
         "test_" + self.date + "." + elem for elem in ["bestfit", "covmat", "h_info", "v_info", "info", "log", "tex"]
     ]
     for output_file in os.listdir(self.folder):
         if os.path.isfile(output_file):
             if output_file.find(".txt") == -1:
                 self.assertIn(output_file, expected_files)
     ## check if the plot folder was created, with the two pdf files
     self.assertTrue(os.path.isdir(os.path.join(self.folder, "plots")))
     for pdf_file in os.listdir(os.path.join(self.folder, "plots")):
         self.assertTrue(pdf_file.find("_triangle") != -1 or pdf_file.find("_1d") != -1)
     # Reset the "Information._id"
     Information._ids = count(0)
     ## Run an Importance sampling run on this data
     is_folder = self.folder + "_is"
     custom_command = "run -p test_is.param -o %s" % is_folder + " -m IS --IS-starting-folder %s" % self.folder
     run(custom_command)
     # Check that the file has been copied, and that both the likelihood and
     # the multiplicity has been changed
     self.assertIn(output_chain, os.listdir(is_folder), "The IS did not create the right chain")
     # Use these two runs to test the several folders option
     custom_command = "info %s %s" % (self.folder, is_folder)
     run(custom_command)
     # Check that all expected files were created
     short_folder = os.path.join(self.folder.split(os.path.sep)[-1])
     short_is_folder = os.path.join(is_folder.split(os.path.sep)[-1])
     expected_files = set(
         [
             "%s-vs-%s_triangle.pdf" % (short_folder, short_is_folder),
             "%s-vs-%s_1d.pdf" % (short_folder, short_is_folder),
             "%s_triangle.pdf" % short_folder,
             "%s_1d.pdf" % short_folder,
         ]
     )
     self.assertSetEqual(expected_files, set(os.listdir(os.path.join(self.folder, "plots"))))
     shutil.rmtree("%s" % is_folder)