Skip to content

run_optuna_dashboard

Functions:

  • main

    Run a password-protected Optuna Dashboard HTTP server.

main

main()

Run a password-protected Optuna Dashboard HTTP server.

This function parses command-line arguments, wraps the Optuna Dashboard WSGI app with basic-auth middleware using the OPTUNA_USER and OPTUNA_PASSWD environment variables, and starts a simple WSGI HTTP server serving the dashboard.

Parameters:

  • None

    This function is intended to be used as a script entry point and reads all configuration from command-line arguments and environment variables.

Command Line Arguments
  • storage : str Optuna storage URL (for example, sqlite:///example.db).
  • --port : int, optional Port to bind the server to. Defaults to 12345.
  • --host : str, optional Host interface to bind to. Defaults to "0.0.0.0".
Environment Variables
  • OPTUNA_USER : str Username required for HTTP basic authentication.
  • OPTUNA_PASSWD : str Password required for HTTP basic authentication.
Source code in src/fpga_profile_reco/utils/run_optuna_dashboard.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def main():
    """Run a password-protected Optuna Dashboard HTTP server.

    This function parses command-line arguments, wraps the Optuna Dashboard
    WSGI app with basic-auth middleware using the ``OPTUNA_USER`` and
    ``OPTUNA_PASSWD`` environment variables, and starts a simple WSGI
    HTTP server serving the dashboard.

    Parameters
    ----------
    None
        This function is intended to be used as a script entry point and
        reads all configuration from command-line arguments and
        environment variables.

    Command Line Arguments
    ----------------------
    - `storage` : str
        Optuna storage URL (for example, ``sqlite:///example.db``).
    - `--port` : int, optional
        Port to bind the server to. Defaults to ``12345``.
    - `--host` : str, optional
        Host interface to bind to. Defaults to ``"0.0.0.0"``.

    Environment Variables
    ---------------------
    - `OPTUNA_USER` : str
        Username required for HTTP basic authentication.
    - `OPTUNA_PASSWD` : str
        Password required for HTTP basic authentication.
    """
    import argparse
    from wsgiref.simple_server import make_server

    parser = argparse.ArgumentParser(description="Run a secure Optuna Dashboard. Make sure to set OPTUNA_USER and OPTUNA_PASSWD environment variables before running.")
    parser.add_argument("storage", type=str, help="Path to the Optuna storage file (e.g., sqlite:///example.db)")
    parser.add_argument("--port", type=int, default=12345, help="Port to run the dashboard on (default: 12345)")
    parser.add_argument("--host", type=str, default="0.0.0.0", help="Host to bind the server (default: 0.0.0.0)")

    args = parser.parse_args()

    app = AuthMiddleware(wsgi(storage=args.storage))

    server = make_server(args.host, args.port, app)
    print("Serving on http://{}:{}".format(args.host, args.port))
    # Run the server
    server.serve_forever()