예제 #1
0
    def test_workflow(self):
        # Test `pre_execute` to ensure that all stats are properly initialized.
        # Then test the core disaggregation function.
        self.calc.pre_execute()
        engine.save_job_stats(self.job)
        job_stats = models.JobStats.objects.get(oq_job=self.job.id)
        self.assertEqual(2, job_stats.num_sites)

        # To test the disagg function, we first need to compute the hazard
        # curves:
        for args in self.calc.task_arg_gen(1):
            cls_core.compute_hazard_curves(*args)
        self.calc.finalize_hazard_curves()

        diss1, diss2, diss3, diss4 = list(self.calc.disagg_task_arg_gen(1))

        base_path = 'openquake.engine.calculators.hazard.disaggregation.core'

        disagg_calc_func = (
            'openquake.hazardlib.calc.disagg.disaggregation_poissonian'
        )
        with mock.patch(disagg_calc_func) as disagg_mock:
            disagg_mock.return_value = (None, None)
            with mock.patch('%s.%s' % (base_path, '_save_disagg_matrix')
                            ) as save_mock:
                # Some of these tasks will not compute anything, since the
                # hazard  curves for these few are all 0.0s.

                # Here's what we expect:
                # diss1: compute
                # diss2: skip
                # diss3: compute
                # diss4: skip

                disagg_core.compute_disagg(*diss1)
                # 2 poes * 2 imts * 1 site = 4
                self.assertEqual(4, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated

                disagg_core.compute_disagg(*diss2)
                self.assertEqual(4, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated

                disagg_core.compute_disagg(*diss3)
                self.assertEqual(8, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated

                disagg_core.compute_disagg(*diss4)
                self.assertEqual(8, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated
예제 #2
0
    def test_workflow(self):
        # Test `pre_execute` to ensure that all stats are properly initialized.
        # Then test the core disaggregation function.
        self.calc.pre_execute()

        job_stats = models.JobStats.objects.get(oq_job=self.job.id)
        self.assertEqual(2, job_stats.num_realizations)
        self.assertEqual(2, job_stats.num_sites)
        self.assertEqual(12, job_stats.num_tasks)

        self.assertEqual(
            {'hc_computed': 0, 'total': 12, 'hc_total': 8, 'computed': 0,
             'in_queue': 0},
            self.calc.progress
        )

        # To test the disagg function, we first need to compute the hazard
        # curves:
        for args in self.calc.task_arg_gen(1):
            # drop the calc_type from the args:
            cls_core.compute_hazard_curves(*args[0:-1])
        self.calc.finalize_hazard_curves()

        diss1, diss2, diss3, diss4 = list(self.calc.disagg_task_arg_gen(1))

        base_path = 'openquake.engine.calculators.hazard.disaggregation.core'

        disagg_calc_func = (
            'openquake.hazardlib.calc.disagg.disaggregation_poissonian'
        )
        with mock.patch(disagg_calc_func) as disagg_mock:
            disagg_mock.return_value = (None, None)
            with mock.patch('%s.%s' % (base_path, '_save_disagg_matrix')
                            ) as save_mock:
                # Some of these tasks will not compute anything, since the
                # hazard  curves for these few are all 0.0s.

                # Here's what we expect:
                # diss1: compute
                # diss2: skip
                # diss3: compute
                # diss4: skip

                disagg_core.compute_disagg(*diss1[0:-1])
                # 2 poes * 2 imts * 1 site = 4
                self.assertEqual(4, disagg_mock.call_count)
                self.assertEqual(4, save_mock.call_count)

                disagg_core.compute_disagg(*diss2[0:-1])
                self.assertEqual(4, disagg_mock.call_count)
                self.assertEqual(4, save_mock.call_count)

                disagg_core.compute_disagg(*diss3[0:-1])
                self.assertEqual(8, disagg_mock.call_count)
                self.assertEqual(8, save_mock.call_count)

                disagg_core.compute_disagg(*diss4[0:-1])
                self.assertEqual(8, disagg_mock.call_count)
                self.assertEqual(8, save_mock.call_count)

        # Finally, test that realization data is up to date and correct:
        rlzs = models.LtRealization.objects.filter(
            hazard_calculation=self.calc.hc)

        for rlz in rlzs:
            self.assertEqual(6, rlz.total_items)
            self.assertEqual(6, rlz.completed_items)
            self.assertTrue(rlz.is_complete)
예제 #3
0
    def test_workflow(self):
        # Test `pre_execute` to ensure that all stats are properly initialized.
        # Then test the core disaggregation function.
        self.calc.pre_execute()

        job_stats = models.JobStats.objects.get(oq_job=self.job.id)
        self.assertEqual(2, job_stats.num_realizations)
        self.assertEqual(2, job_stats.num_sites)
        self.assertEqual(12, job_stats.num_tasks)

        self.assertEqual(
            {'hc_computed': 0, 'total': 12, 'hc_total': 8, 'computed': 0,
             'in_queue': 0},
            self.calc.progress
        )

        # To test the disagg function, we first need to compute the hazard
        # curves:
        for args in self.calc.task_arg_gen(1):
            # drop the calc_type from the args:
            cls_core.compute_hazard_curves(*args[0:-1])
        self.calc.finalize_hazard_curves()

        diss1, diss2, diss3, diss4 = list(self.calc.disagg_task_arg_gen(1))

        base_path = 'openquake.engine.calculators.hazard.disaggregation.core'

        disagg_calc_func = (
            'openquake.hazardlib.calc.disagg.disaggregation_poissonian'
        )
        with mock.patch(disagg_calc_func) as disagg_mock:
            disagg_mock.return_value = (None, None)
            with mock.patch('%s.%s' % (base_path, '_save_disagg_matrix')
                            ) as save_mock:
                # Some of these tasks will not compute anything, since the
                # hazard  curves for these few are all 0.0s.

                # Here's what we expect:
                # diss1: compute
                # diss2: skip
                # diss3: compute
                # diss4: skip

                disagg_core.compute_disagg(*diss1[0:-1])
                # 2 poes * 2 imts * 1 site = 4
                self.assertEqual(4, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated

                disagg_core.compute_disagg(*diss2[0:-1])
                self.assertEqual(4, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated

                disagg_core.compute_disagg(*diss3[0:-1])
                self.assertEqual(8, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated

                disagg_core.compute_disagg(*diss4[0:-1])
                self.assertEqual(8, disagg_mock.call_count)
                self.assertEqual(0, save_mock.call_count)  # no rupt generated

        # Finally, test that realization data is up to date and correct:
        rlzs = models.LtRealization.objects.filter(
            hazard_calculation=self.calc.hc)

        for rlz in rlzs:
            self.assertEqual(6, rlz.total_items)
            self.assertEqual(6, rlz.completed_items)
            self.assertTrue(rlz.is_complete)