google-colaboratoryoptuna

Launching optuna-dashboard in Google Colaboratory


Is there a way to start optuna-dashboard in Google Colaboratory?

When running !optuna-dashboard --port 1234 sqlite:////content/drive/MyDrive/optimization.db the link is invalid


Solution

  • Author of optuna-dashboard here. Thank you for trying to use optuna-dashboard.

    You need to use google.colab.output like below:

        import time
        import threading
        from optuna_dashboard import wsgi
        import optuna
        from wsgiref.simple_server import make_server
    
    
        port = 1234
        storage = optuna.storages.RDBStorage("sqlite:////content/drive/MyDrive/optimization.db")
        app = wsgi(storage)
        httpd = make_server("localhost", port, app)
        thread = threading.Thread(target=httpd.serve_forever)
        thread.start()
        time.sleep(3) # Wait until the server startup
        
        from google.colab import output
        output.serve_kernel_port_as_window(port, path='/dashboard/')
    

    The the link to optuna-dashboard will be printed. Please click to open.