コード例 #1
0
ファイル: test_spark.py プロジェクト: niumeng07/hyperopt
    def test_trial_run_info(self):
        spark_trials = SparkTrials(parallelism=4)

        with patch_logger("hyperopt-spark") as output:
            fmin(
                fn=fn_succeed_within_range,
                space=hp.uniform("x", -5, 5),
                algo=anneal.suggest,
                max_evals=8,
                return_argmin=False,
                trials=spark_trials,
                rstate=np.random.RandomState(99),
            )
            self.check_run_status(spark_trials,
                                  output,
                                  num_total=8,
                                  num_success=7,
                                  num_failure=1)

        expected_result = {"loss": 1.0, "status": "ok"}
        for trial in spark_trials._dynamic_trials:
            if trial["state"] == base.JOB_STATE_DONE:
                self.assertEqual(
                    trial["result"],
                    expected_result,
                    "Wrong result has been saved: Expected {e} but got {r}.".
                    format(e=expected_result, r=trial["result"]),
                )
            elif trial["state"] == base.JOB_STATE_ERROR:
                err_message = trial["misc"]["error"][1]
                self.assertIn(
                    "RuntimeError",
                    err_message,
                    "Missing {e} in {r}.".format(e="RuntimeError",
                                                 r=err_message),
                )
                self.assertIn(
                    "Traceback (most recent call last)",
                    err_message,
                    "Missing {e} in {r}.".format(e="Traceback", r=err_message),
                )

        num_success = spark_trials.count_by_state_unsynced(base.JOB_STATE_DONE)
        self.assertEqual(
            num_success,
            7,
            "Wrong number of successful trial runs: Expected {e} but got {r}.".
            format(e=7, r=num_success),
        )
        num_failure = spark_trials.count_by_state_unsynced(
            base.JOB_STATE_ERROR)
        self.assertEqual(
            num_failure,
            1,
            "Wrong number of failed trial runs: Expected {e} but got {r}.".
            format(e=1, r=num_failure),
        )
コード例 #2
0
    def test_trial_run_info(self):
        spark_trials = SparkTrials(parallelism=4)

        with patch_logger('hyperopt-spark') as output:
            fmin(fn=fn_succeed_within_range,
                 space=hp.uniform('x', -5, 5),
                 algo=anneal.suggest,
                 max_evals=8,
                 return_argmin=False,
                 trials=spark_trials)
            self.check_run_status(spark_trials,
                                  output,
                                  num_total=8,
                                  num_success=7,
                                  num_failure=1)

        expected_result = {'loss': 1.0, 'status': 'ok'}
        for trial in spark_trials._dynamic_trials:
            if trial['state'] == base.JOB_STATE_DONE:
                self.assertEqual(
                    trial['result'], expected_result,
                    "Wrong result has been saved: Expected {e} but got {r}.".
                    format(e=expected_result, r=trial['result']))
            elif trial['state'] == base.JOB_STATE_ERROR:
                err_message = trial['misc']['error'][1]
                self.assertIn(
                    "RuntimeError", err_message,
                    "Missing {e} in {r}.".format(e="RuntimeError",
                                                 r=err_message))

        num_success = spark_trials.count_by_state_unsynced(base.JOB_STATE_DONE)
        self.assertEqual(
            num_success, 7,
            "Wrong number of successful trial runs: Expected {e} but got {r}.".
            format(e=7, r=num_success))
        num_failure = spark_trials.count_by_state_unsynced(
            base.JOB_STATE_ERROR)
        self.assertEqual(
            num_failure, 1,
            "Wrong number of failed trial runs: Expected {e} but got {r}.".
            format(e=1, r=num_failure))