Beispiel #1
0
 def test_new_errors(self,
                     number=0,
                     candidates=lambda: [_dummy_candidate()],
                     estimator_spec=tu.dummy_estimator_spec(),
                     best_candidate_index=0,
                     subnetwork_reports=lambda: []):
     with self.assertRaises(ValueError):
         _Iteration(number=number,
                    candidates=candidates(),
                    subnetwork_specs=None,
                    estimator_spec=estimator_spec,
                    best_candidate_index=best_candidate_index,
                    summaries=[],
                    subnetwork_reports=subnetwork_reports(),
                    train_manager=_TrainManager([], [],
                                                self.test_subdirectory,
                                                is_chief=True))
Beispiel #2
0
 def test_new_errors(self,
                     number=0,
                     candidates=lambda: [_dummy_candidate()],
                     estimator_spec=tu.dummy_estimator_spec(),
                     best_candidate_index=0,
                     is_over_fn=lambda: True,
                     subnetwork_reports=lambda: []):
     with self.test_session():
         with self.assertRaises(ValueError):
             _Iteration(number=number,
                        candidates=candidates(),
                        subnetwork_specs=None,
                        estimator_spec=estimator_spec,
                        best_candidate_index=best_candidate_index,
                        summaries=[],
                        is_over_fn=is_over_fn,
                        subnetwork_reports=subnetwork_reports())
Beispiel #3
0
class IterationTest(parameterized.TestCase, tf.test.TestCase):

    # pylint: disable=g-long-lambda
    @parameterized.named_parameters(
        {
            "testcase_name": "single_candidate",
            "number": 0,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "is_over_fn": lambda: True,
        }, {
            "testcase_name": "two_candidates",
            "number": 0,
            "candidates": [_dummy_candidate(),
                           _dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "is_over_fn": lambda: True,
        }, {
            "testcase_name": "positive_number",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "is_over_fn": lambda: True,
        }, {
            "testcase_name": "false_is_over",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "is_over_fn": lambda: False,
        }, {
            "testcase_name": "zero_best_predictions",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "is_over_fn": lambda: True,
        }, {
            "testcase_name": "zero_best_loss",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "is_over_fn": lambda: True,
        }, {
            "testcase_name": "pass_subnetwork_report",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "is_over_fn": lambda: True,
            "subnetwork_reports_fn": lambda: {
                "foo":
                SubnetworkReport(hparams={"dropout": 1.0},
                                 attributes={"aoo": tf.constant("aoo")},
                                 metrics={
                                     "moo":
                                     (tf.constant("moo1"), tf.constant("moo2"))
                                 })
            },
        })
    def test_new(self,
                 number,
                 candidates,
                 estimator_spec,
                 best_candidate_index,
                 is_over_fn,
                 subnetwork_reports_fn=None,
                 step=0):
        if subnetwork_reports_fn is None:
            subnetwork_reports = {}
        else:
            subnetwork_reports = subnetwork_reports_fn()
        with self.test_session():
            iteration = _Iteration(number=number,
                                   candidates=candidates,
                                   estimator_spec=estimator_spec,
                                   best_candidate_index=best_candidate_index,
                                   summaries=[],
                                   is_over_fn=is_over_fn,
                                   subnetwork_reports=subnetwork_reports,
                                   step=step)
            self.assertEqual(iteration.number, number)
            self.assertEqual(iteration.candidates, candidates)
            self.assertEqual(iteration.estimator_spec, estimator_spec)
            self.assertEqual(iteration.best_candidate_index,
                             best_candidate_index)
            self.assertEqual(iteration.is_over_fn(), is_over_fn())
            self.assertEqual(iteration.subnetwork_reports, subnetwork_reports)
            self.assertEqual(iteration.step, step)

    @parameterized.named_parameters(
        {
            "testcase_name": "negative_number",
            "number": -1,
        }, {
            "testcase_name": "float_number",
            "number": 1.213,
        }, {
            "testcase_name": "none_number",
            "number": None,
        }, {
            "testcase_name": "empty_candidates",
            "candidates": lambda: [],
        }, {
            "testcase_name": "none_candidates",
            "candidates": lambda: None,
        }, {
            "testcase_name": "non_list_candidates",
            "candidates": lambda: {
                "foo": _dummy_candidate()
            },
        }, {
            "testcase_name": "none_estimator_spec",
            "estimator_spec": None,
        }, {
            "testcase_name": "none_best_candidate_index",
            "best_candidate_index": None,
        }, {
            "testcase_name": "none_subnetwork_reports",
            "subnetwork_reports": lambda: None,
        }, {
            "testcase_name": "none_step",
            "step": None,
        })
    def test_new_errors(self,
                        number=0,
                        candidates=lambda: [_dummy_candidate()],
                        estimator_spec=tu.dummy_estimator_spec(),
                        best_candidate_index=0,
                        is_over_fn=lambda: True,
                        subnetwork_reports=lambda: [],
                        step=0):
        with self.test_session():
            with self.assertRaises(ValueError):
                _Iteration(number=number,
                           candidates=candidates(),
                           estimator_spec=estimator_spec,
                           best_candidate_index=best_candidate_index,
                           summaries=[],
                           is_over_fn=is_over_fn,
                           subnetwork_reports=subnetwork_reports(),
                           step=step)
Beispiel #4
0
class IterationTest(tu.AdanetTestCase):

    # pylint: disable=g-long-lambda
    @parameterized.named_parameters(
        {
            "testcase_name": "single_candidate",
            "number": 0,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
        }, {
            "testcase_name": "two_candidates",
            "number": 0,
            "candidates": [_dummy_candidate(),
                           _dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
        }, {
            "testcase_name": "positive_number",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
        }, {
            "testcase_name": "zero_best_predictions",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
        }, {
            "testcase_name": "zero_best_loss",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
        }, {
            "testcase_name": "pass_subnetwork_report",
            "number": 1,
            "candidates": [_dummy_candidate()],
            "estimator_spec": tu.dummy_estimator_spec(),
            "best_candidate_index": 0,
            "subnetwork_reports_fn": lambda: {
                "foo":
                SubnetworkReport(hparams={"dropout": 1.0},
                                 attributes={"aoo": tf.constant("aoo")},
                                 metrics={
                                     "moo":
                                     (tf.constant("moo1"), tf.constant("moo2"))
                                 })
            },
        })
    @test_util.run_in_graph_and_eager_modes
    def test_new(self,
                 number,
                 candidates,
                 estimator_spec,
                 best_candidate_index,
                 subnetwork_reports_fn=None):
        if subnetwork_reports_fn is None:
            subnetwork_reports = {}
        else:
            subnetwork_reports = subnetwork_reports_fn()
        iteration = _Iteration(number=number,
                               candidates=candidates,
                               subnetwork_specs=None,
                               estimator_spec=estimator_spec,
                               best_candidate_index=best_candidate_index,
                               summaries=[],
                               subnetwork_reports=subnetwork_reports,
                               train_manager=_TrainManager(
                                   [], [],
                                   self.test_subdirectory,
                                   is_chief=True))
        self.assertEqual(iteration.number, number)
        self.assertEqual(iteration.candidates, candidates)
        self.assertEqual(iteration.estimator_spec, estimator_spec)
        self.assertEqual(iteration.best_candidate_index, best_candidate_index)
        self.assertEqual(iteration.subnetwork_reports, subnetwork_reports)

    @parameterized.named_parameters(
        {
            "testcase_name": "negative_number",
            "number": -1,
        }, {
            "testcase_name": "float_number",
            "number": 1.213,
        }, {
            "testcase_name": "none_number",
            "number": None,
        }, {
            "testcase_name": "empty_candidates",
            "candidates": lambda: [],
        }, {
            "testcase_name": "none_candidates",
            "candidates": lambda: None,
        }, {
            "testcase_name": "non_list_candidates",
            "candidates": lambda: {
                "foo": _dummy_candidate()
            },
        }, {
            "testcase_name": "none_estimator_spec",
            "estimator_spec": None,
        }, {
            "testcase_name": "none_best_candidate_index",
            "best_candidate_index": None,
        }, {
            "testcase_name": "none_subnetwork_reports",
            "subnetwork_reports": lambda: None,
        })
    @test_util.run_in_graph_and_eager_modes
    def test_new_errors(self,
                        number=0,
                        candidates=lambda: [_dummy_candidate()],
                        estimator_spec=tu.dummy_estimator_spec(),
                        best_candidate_index=0,
                        subnetwork_reports=lambda: []):
        with self.assertRaises(ValueError):
            _Iteration(number=number,
                       candidates=candidates(),
                       subnetwork_specs=None,
                       estimator_spec=estimator_spec,
                       best_candidate_index=best_candidate_index,
                       summaries=[],
                       subnetwork_reports=subnetwork_reports(),
                       train_manager=_TrainManager([], [],
                                                   self.test_subdirectory,
                                                   is_chief=True))