Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing Custom User Widget #370

Merged
merged 11 commits into from
Jan 27, 2023
Merged

Introducing Custom User Widget #370

merged 11 commits into from
Jan 27, 2023

Conversation

c-bata
Copy link
Member

@c-bata c-bata commented Jan 26, 2023

Contributor License Agreement

This repository (optuna-dashboard) and Goptuna share common code.
This pull request may therefore be ported to Goptuna.
Make sure that you understand the consequences concerning licenses and check the box below if you accept the term before creating this pull request.

  • I agree this patch may be ported to Goptuna by other Goptuna contributors.

Reference Issues/PRs

What does this implement/fix? Explain your changes.

Preferential Optimization

Screenshot 2023-01-26 16 48 34

import optuna
from optuna.distributions import CategoricalDistribution
from optuna.distributions import FloatDistribution
from optuna_dashboard import ObjectiveChoiceWidget
from optuna_dashboard import register_objective_form_widgets
from optuna_dashboard import set_objective_names
from optuna_dashboard._app import create_app


host = "127.0.0.1"
port = 8080


def create_optuna_storage() -> optuna.storages.InMemoryStorage:
    storage = optuna.storages.InMemoryStorage()

    study = optuna.create_study(study_name="Preferential Optimization", storage=storage, directions=["minimize"])
    set_objective_names(study, ["Human Perception"])
    register_objective_form_widgets(study, widgets=[
        ObjectiveChoiceWidget(
            choices=["Good 馃憤", "Bad 馃憥"],
            values=[-1, 1],
            description="Choose Good 馃憤 or Bad 馃憥.",
        ),
    ])

    # Sample new parameters
    study.ask({"x": FloatDistribution(0, 10), "y": CategoricalDistribution(["Foo", "Bar"])})

    return storage


def main() -> None:
    storage = create_optuna_storage()
    app = create_app(storage, debug=True)
    app.run(host=host, port=port, reloader=True)


if __name__ == "__main__":
    main()

More complex example

Screenshot 2023-01-27 12 38 28

import optuna
from optuna.distributions import CategoricalDistribution
from optuna.distributions import FloatDistribution
from optuna_dashboard import ObjectiveChoiceWidget, ObjectiveTextInputWidget, ObjectiveSliderWidget, \
    ObjectiveUserAttrRef
from optuna_dashboard import register_objective_form_widgets
from optuna_dashboard import set_objective_names
from optuna_dashboard._app import create_app


host = "127.0.0.1"
port = 8080


def create_optuna_storage() -> optuna.storages.InMemoryStorage:
    storage = optuna.storages.InMemoryStorage()

    study = optuna.create_study(study_name="objective-form-widgets", storage=storage, directions=["minimize", "minimize", "minimize", "minimize"])
    set_objective_names(study, ["Slider Objective", "Good or Bad", "Text Input Objective", "Validation Loss"])
    register_objective_form_widgets(study, widgets=[
        ObjectiveSliderWidget(
            min=0.0,
            max=1.0,
            step=0.1,
            #labels=[(0.0, "Better"), (0.5, "0.5"), (1.0, "Worse")],
            labels=[],
            description="Select a value.",
        ),
        ObjectiveChoiceWidget(
            choices=["Good 馃憤", "Bad 馃憥"],
            values=[-1, 1],
            description="Choose Good 馃憤 or Bad 馃憥.",
        ),
        ObjectiveTextInputWidget(
            description="Enter the objective value via TextInput.",
        ),
        ObjectiveUserAttrRef(
            key="val_loss",
        ),
    ])
    trial = study.ask({"x": FloatDistribution(0, 10), "y": CategoricalDistribution(["Foo", "Bar"])})
    trial.set_user_attr("val_loss", 0.2)
    study.ask({"x": FloatDistribution(0, 10), "y": CategoricalDistribution(["Foo", "Bar"])})
    trial.set_user_attr("val_loss", 0.5)

    return storage


def main() -> None:
    storage = create_optuna_storage()
    app = create_app(storage, debug=True)
    app.run(host=host, port=port, reloader=True)


if __name__ == "__main__":
    main()

@c-bata c-bata changed the title WIP: Introducing Custom User Widget Introducing Custom User Widget Jan 27, 2023
@c-bata c-bata marked this pull request as ready for review January 27, 2023 03:50
@c-bata c-bata merged commit 5bf6c38 into optuna:main Jan 27, 2023
@c-bata c-bata deleted the custom-widget branch January 27, 2023 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant