예제 #1
0
 def test_prior_validity(self):
     if not TestLevel.test_enabled(
             level = TestLevel.EXHAUSTIVE,
             log = _LOG,
             module_name = '.'.join([self.__class__.__name__,
                     sys._getframe().f_code.co_name])):
         return
     n = 100
     sample_size = 100
     nprocessors = 4
     self._load_workers(sample_size, n)
     managers = []
     for i in range(nprocessors):
         m = Manager(work_queue = self.workq,
             result_queue = self.resultq)
         managers.append(m)
         m.start()
     workers = []
     for i in range(n):
         workers.append(self.resultq.get())
     for m in managers:
         m.join()
     for w in workers:
         self._assert_success(w, 4, sample_size)
     self.assertPriorIsValid(workers, 0)
예제 #2
0
 def test_simple_serial(self):
     n = 4
     self._load_workers(n=n)
     m = Manager(work_queue = self.workq,
             result_queue = self.resultq)
     self.assertFalse(m.is_alive())
     m.start()
     self.assertTrue(m.is_alive())
     w = self.resultq.get()
     m.join()
     self.assertFalse(m.is_alive())
     self.assertEqual(m.exitcode, 0)
     self._assert_success(w, 4, 10)
예제 #3
0
 def test_simple_parallel(self):
     n = 10
     sample_size = 10
     nprocessors = 4
     self._load_workers(sample_size, n)
     managers = []
     for i in range(nprocessors):
         m = Manager(work_queue = self.workq,
             result_queue = self.resultq)
         managers.append(m)
         m.start()
     workers = []
     for i in range(n):
         workers.append(self.resultq.get())
     for m in managers:
         m.join()
     for w in workers:
         self._assert_success(w, 4, sample_size)
예제 #4
0
 def test_rejection_workers(self):
     """
     Real-world scale number of simulations. This test will hopefully
     catch problems with running into limit of too many open files if
     there are file handle 'leaks'.
     """
     if not TestLevel.test_enabled(
             level = TestLevel.EXHAUSTIVE,
             log = _LOG,
             module_name = '.'.join([self.__class__.__name__,
                     sys._getframe().f_code.co_name])):
         return
     n = 200
     sample_size = 10
     nprocessors = 4
     # get prior
     self._load_workers(sample_size, n)
     managers = []
     for i in range(nprocessors):
         m = Manager(work_queue = self.workq,
             result_queue = self.resultq)
         managers.append(m)
         m.start()
     workers = []
     for i in range(n):
         workers.append(self.resultq.get())
     for m in managers:
         m.join()
     prior_path = self.get_test_path(prefix='test-prior-')
     header_path = self.get_test_path(prefix='test-prior-header-')
     merge_priors(workers=workers, prior_path=prior_path,
             header_path=header_path)
     # get observed
     self._load_workers(sample_size, n, include_header=True)
     managers = []
     for i in range(nprocessors):
         m = Manager(work_queue = self.workq,
             result_queue = self.resultq)
         managers.append(m)
         m.start()
     workers = []
     for i in range(n):
         workers.append(self.resultq.get())
     for m in managers:
         m.join()
     obs_path = self.get_test_path(prefix='test-obs-')
     obs_header_path = self.get_test_path(prefix='test-obs-header-')
     merge_priors(workers=workers, prior_path=obs_path,
             header_path=obs_header_path, include_header=True)
     results_dir = self.get_test_subdir(prefix='test-rejection-results-')
     msreject_workers = assemble_rejection_workers(
             temp_fs = self.temp_fs,
             observed_sims_file = obs_path,
             prior_path = prior_path,
             tolerance = 0.1,
             results_dir = results_dir,
             posterior_prefix = self.test_id + '-posterior-',
             regress = False,
             rejection_tool = 'msreject')
     self.assertEqual(len(msreject_workers), 2000)
     for w in msreject_workers:
         self.workq.put(w)
     managers = []
     for i in range(nprocessors):
         m = Manager(work_queue = self.workq,
             result_queue = self.resultq)
         managers.append(m)
         m.start()
     workers = []
     for i in range(len(msreject_workers)):
         workers.append(self.resultq.get())
     for m in managers:
         m.join()
     for w in workers:
         self.assertTrue(w.finished)
         self.assertEqual(w.exit_code, 0)
         self.assertTrue(os.path.isfile(w.posterior_path))
         self.assertTrue(self.get_number_of_lines(w.posterior_path) > 2)