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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slice plot does not support boolean parameter values #977

Open
cartisan opened this issue Oct 2, 2024 · 3 comments
Open

Slice plot does not support boolean parameter values #977

cartisan opened this issue Oct 2, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@cartisan
Copy link

cartisan commented Oct 2, 2024

Description

Observed behavior:
When I select a categorical parameter that contains boolean values in the slice plot (first plot shown in the analytics page) then both values on the x-axis are represented as [Object object].
image

Expected behavior:
The plot shows the actual values, True and False on the x-axis.

Observations:
This seems a problem with optuna-dashbord and not optuna, when I create a slice plot in optuna (code below) I see the values represented correctly in the plotly graph.
image

I'm not familiar with React, but the problem seems to be here:

  const feasibleValues = feasibleTrials.map(
    (t) => selectedParamTarget.getTargetValue(t) as number
  )

where the code assumes the values of the x-axis are numbers, which is not the case for boolean hyperspace parameters. I would guess that this also breaks for string values of categorical parameters.

Code to reproduce optuna plot

import optuna
from plotly.io import show
def objective(trial):
    x = trial.suggest_float("x", -100, 100)
    y = trial.suggest_categorical("y", [True, False])
    if y:
        return x**2
    else:
        return x*2
sampler = optuna.samplers.TPESampler(seed=10)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=10)
fig = optuna.visualization.plot_slice(study, params=["x", "y"])
show(fig)

How to Reproduce

  1. Optuna's objective function is not relevant here, but search space needs to contain a categorical parameter that contains boolean values.
  2. Run optuna-dashboard.
  3. Open analytics page, then select a boolean parameter in the slice plot.
  4. An error occurs.

Python version

3.11

Optuna version

3.6.1

optuna-dashboard version or git revision

0.16.2

Web browser

Google Chrome

@cartisan cartisan added the bug Something isn't working label Oct 2, 2024
@wassname
Copy link

wassname commented Oct 6, 2024

Ah I think I found it. It seems that the way categorical as stored has changed.

So

 (c) => c?.toString() ?? "null"

to

 (c) => c?.value?.toString() ?? "null"

everywhere it occurs

image

But I haven't run unit tests on it to check if this fix causes unintended problems, so I can't make it a PR yet

wassname added a commit to wassname/optuna-dashboard that referenced this issue Oct 6, 2024
@Spider-netizen
Copy link

@wassname Thanks for this.
Can you tell what the last working version would be?

@wassname
Copy link

I'm not sure sorry, I've only recently starting using it, so I don't know if it was ever working. But that's normal, it's a active volunteer project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants