def main() -> None:
    os.makedirs(args.output_dir, exist_ok=True)

    storage: optuna.storages.BaseStorage
    if not args.storage:
        storage = create_dummy_storage()
    elif args.storage.startswith("redis"):
        storage = optuna.storages.RedisStorage(args.storage)
    else:
        storage = optuna.storages.RDBStorage(args.storage)

    app = create_app(storage)
    httpd = make_server(args.host, args.port, app)
    thread = threading.Thread(target=httpd.serve_forever)
    thread.start()

    loop = asyncio.get_event_loop()
    error_messages = loop.run_until_complete(take_screenshots(storage))
    for msg in error_messages:
        print(msg)

    httpd.shutdown()
    httpd.server_close()
    thread.join()

    if error_messages:
        sys.exit(1)
Beispiel #2
0
    def test_create_study(self) -> None:
        for name, directions, expected_status in [
            ("single-objective success", ["minimize"], 201),
            ("multi-objective success", ["minimize", "maximize"], 201),
            ("invalid direction name", ["invalid-direction", "maximize"], 400),
        ]:
            with self.subTest(name):
                storage = optuna.storages.InMemoryStorage()
                self.assertEqual(len(storage.get_all_study_summaries()), 0)

                app = create_app(storage)
                request_body = {
                    "study_name": "foo",
                    "directions": directions,
                }
                status, _, _ = send_request(
                    app,
                    "/api/studies",
                    "POST",
                    content_type="application/json",
                    body=json.dumps(request_body),
                )
                self.assertEqual(status, expected_status)

                if expected_status == 201:
                    self.assertEqual(len(storage.get_all_study_summaries()), 1)
                else:
                    self.assertEqual(len(storage.get_all_study_summaries()), 0)
Beispiel #3
0
 def test_delete_study_not_found(self) -> None:
     storage = optuna.storages.InMemoryStorage()
     app = create_app(storage)
     status, _, _ = send_request(
         app,
         "/api/studies/1",
         "DELETE",
         content_type="application/json",
     )
     self.assertEqual(status, 404)
Beispiel #4
0
    def test_ignore_trailing_slashes(self) -> None:
        storage = optuna.storages.InMemoryStorage()
        app = create_app(storage)

        endpoints = ["/api/studies", "/api/studies/"]
        for endpoint in endpoints:
            with self.subTest(msg=endpoint):
                status, _, body = send_request(
                    app,
                    endpoint,
                    "GET",
                    content_type="application/json",
                )
                self.assertEqual(status, 200)
Beispiel #5
0
    def test_get_study_summaries(self) -> None:
        storage = optuna.storages.InMemoryStorage()
        storage.create_new_study("foo1")
        storage.create_new_study("foo2")

        app = create_app(storage)
        status, _, body = send_request(
            app,
            "/api/studies/",
            "GET",
            content_type="application/json",
        )
        self.assertEqual(status, 200)
        study_summaries = json.loads(body)["study_summaries"]
        self.assertEqual(len(study_summaries), 2)
Beispiel #6
0
    def test_delete_study(self) -> None:
        storage = optuna.storages.InMemoryStorage()
        storage.create_new_study("foo1")
        storage.create_new_study("foo2")
        self.assertEqual(len(storage.get_all_study_summaries()), 2)

        app = create_app(storage)
        status, _, _ = send_request(
            app,
            "/api/studies/1",
            "DELETE",
            content_type="application/json",
        )
        self.assertEqual(status, 204)
        self.assertEqual(len(storage.get_all_study_summaries()), 1)
Beispiel #7
0
    def test_create_study(self) -> None:
        storage = optuna.storages.InMemoryStorage()
        self.assertEqual(len(storage.get_all_study_summaries()), 0)

        app = create_app(storage)
        request_body = {
            "study_name": "foo",
            "direction": "minimize",
        }
        status, _, _ = send_request(
            app,
            "/api/studies",
            "POST",
            content_type="application/json",
            body=json.dumps(request_body),
        )
        self.assertEqual(status, 201)
        self.assertEqual(len(storage.get_all_study_summaries()), 1)