Ejemplo n.º 1
0
def _process_dashboard_args(database_paths, no_browser, port):
    """Check arguments and find free port if none was given.

    The no_browser and port arguments override settings from the databases if not None.

    Args:
        database_paths (str or pathlib.Path or list of them): Path(s) to an sqlite3
            file which typically has the file extension ``.db``. See :ref:`logging` for
            details.
        no_browser (bool or None): Whether or not to open the dashboard in the browser.
        port (int or None): Port where to display the dashboard.

    Returns:
        database_paths (str or pathlib.Path or list of them):
            Path(s) to an sqlite3 file which typically has the file extension ``.db``.
            See :ref:`logging` for details.
        no_browser (bool):
            Whether or not to open the dashboard in the browser.
        port (int): port where to display the dashboard.

    """
    if not isinstance(database_paths, (list, tuple)):
        database_paths = [database_paths]

    for single_database_path in database_paths:
        if not isinstance(single_database_path, (str, pathlib.Path)):
            raise TypeError(
                f"database_paths must be string or pathlib.Path. ",
                "You supplied {type(single_database_path)}.",
            )
    database_name_to_path = create_short_database_names(path_list=database_paths)

    all_options = []
    for single_database_path in database_paths:
        database = load_database(single_database_path)
        dash_options = read_scalar_field(database, "dash_options")
        all_options.append(dash_options)

    if port is None:
        ports = {d.pop("port", None) for d in all_options}
        ports = {p for p in ports if p is not None}
        if len(ports) == 0:
            port = find_free_port()
        else:
            port = ports.pop()
            if len(ports) > 1:
                warnings.warn(f"You supplied more than one port. {port} will be used.")
    if not isinstance(port, int):
        raise TypeError(f"port must be an integer. You supplied {type(port)}.")

    if no_browser is None:
        no_browser_vals = {d.pop("no_browser", False) for d in all_options}
        no_browser = no_browser_vals.pop()
        if len(no_browser_vals) > 1:
            no_browser = False
            warnings.warn(
                "You supplied both True and False for no_browser. It is set to False."
            )

    return database_name_to_path, no_browser, port
Ejemplo n.º 2
0
def monitoring_app(doc, database_name, session_data):
    """Create plots showing the development of the criterion and parameters.

    Options are loaded from the database. Supported options are:
        - rollover (int): How many iterations to keep before discarding.

    Args:
        doc (bokeh.Document): Argument required by bokeh.
        database_name (str): Short and unique name of the database.
        session_data (dict): Infos to be passed between and within apps.
            Keys of this app's entry are:
            - last_retrieved (int): last iteration currently in the ColumnDataSource.
            - database_path (str or pathlib.Path)
            - callbacks (dict): dictionary to be populated with callbacks.

    """
    database = load_database(session_data["database_path"])
    start_params = read_scalar_field(database, "start_params")
    dash_options = read_scalar_field(database, "dash_options")
    rollover = dash_options["rollover"]

    tables = ["criterion_history", "params_history"]
    criterion_history, params_history = _create_bokeh_data_sources(
        database=database, tables=tables
    )
    session_data["last_retrieved"] = 1

    # create initial bokeh elements without callbacks
    initial_convergence_plots = _create_initial_convergence_plots(
        criterion_history=criterion_history,
        params_history=params_history,
        start_params=start_params,
    )

    activation_button = Toggle(
        active=False,
        label="Start Updating from Database",
        button_type="danger",
        width=50,
        height=30,
        name="activation_button",
    )

    # add elements to bokeh Document
    bokeh_convergence_elements = [Row(activation_button)] + initial_convergence_plots
    convergence_tab = Panel(
        child=Column(*bokeh_convergence_elements), title="Convergence Tab"
    )
    tabs = Tabs(tabs=[convergence_tab])
    doc.add_root(tabs)

    # add callbacks
    activation_callback = partial(
        _activation_callback,
        button=activation_button,
        doc=doc,
        database=database,
        session_data=session_data,
        rollover=rollover,
        tables=tables,
    )
    activation_button.on_change("active", activation_callback)
Ejemplo n.º 3
0
def test_gradient_status_table(database):
    assert read_scalar_field(database, "gradient_status") == 0
Ejemplo n.º 4
0
def test_optimization_status_table(database):
    assert read_scalar_field(database, "optimization_status") == "success"
Ejemplo n.º 5
0
def test_start_params_table(database):
    params = pd.DataFrame()
    params["name"] = list("abc")
    assert_frame_equal(read_scalar_field(database, "start_params"), params)
Ejemplo n.º 6
0
def test_update_scalar_field(database):
    upd_db.update_scalar_field(database=database,
                               table="optimization_status",
                               value="failure")
    assert read_scalar_field(database, "optimization_status") == "failure"
Ejemplo n.º 7
0
def test_db_options_table(database):
    assert read_scalar_field(database, "db_options") == {"a": 3}