-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Use tslib's PlotIntermediateValue in optuna-dashboard #900
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,22 @@ | ||
import { Box, Card, CardContent, Typography, useTheme } from "@mui/material" | ||
import * as plotly from "plotly.js-dist-min" | ||
import React, { FC, useEffect } from "react" | ||
import { Card, CardContent } from "@mui/material" | ||
import { PlotIntermediateValues } from "@optuna/react" | ||
import React, { FC } from "react" | ||
import { Trial } from "ts/types/optuna" | ||
import { usePlotlyColorTheme } from "../state" | ||
|
||
const plotDomId = "graph-intermediate-values" | ||
|
||
export const GraphIntermediateValues: FC<{ | ||
trials: Trial[] | ||
includePruned: boolean | ||
logScale: boolean | ||
}> = ({ trials, includePruned, logScale }) => { | ||
const theme = useTheme() | ||
const colorTheme = usePlotlyColorTheme(theme.palette.mode) | ||
|
||
useEffect(() => { | ||
plotIntermediateValue(trials, colorTheme, false, !includePruned, logScale) | ||
}, [trials, colorTheme, includePruned, logScale]) | ||
|
||
return ( | ||
<Card> | ||
<CardContent> | ||
<Typography | ||
variant="h6" | ||
sx={{ margin: "1em 0", fontWeight: theme.typography.fontWeightBold }} | ||
> | ||
Intermediate values | ||
</Typography> | ||
<Box component="div" id={plotDomId} sx={{ height: "450px" }} /> | ||
<PlotIntermediateValues | ||
trials={trials} | ||
includePruned={includePruned} | ||
logScale={logScale} | ||
/> | ||
</CardContent> | ||
</Card> | ||
) | ||
} | ||
|
||
const plotIntermediateValue = ( | ||
trials: Trial[], | ||
colorTheme: Partial<Plotly.Template>, | ||
filterCompleteTrial: boolean, | ||
filterPrunedTrial: boolean, | ||
logScale: boolean | ||
) => { | ||
if (document.getElementById(plotDomId) === null) { | ||
return | ||
} | ||
|
||
const layout: Partial<plotly.Layout> = { | ||
margin: { | ||
l: 50, | ||
t: 0, | ||
r: 50, | ||
b: 0, | ||
}, | ||
yaxis: { | ||
title: "Objective Value", | ||
type: logScale ? "log" : "linear", | ||
}, | ||
xaxis: { | ||
title: "Step", | ||
type: "linear", | ||
}, | ||
uirevision: "true", | ||
template: colorTheme, | ||
legend: { | ||
x: 1.0, | ||
y: 0.95, | ||
}, | ||
} | ||
if (trials.length === 0) { | ||
plotly.react(plotDomId, [], layout) | ||
return | ||
} | ||
|
||
const filteredTrials = trials.filter( | ||
(t) => | ||
(!filterCompleteTrial && t.state === "Complete") || | ||
(!filterPrunedTrial && | ||
t.state === "Pruned" && | ||
t.values && | ||
t.values.length > 0) || | ||
t.state === "Running" | ||
) | ||
const plotData: Partial<plotly.PlotData>[] = filteredTrials.map((trial) => { | ||
const isFeasible = trial.constraints.every((c) => c <= 0) | ||
return { | ||
x: trial.intermediate_values.map((iv) => iv.step), | ||
y: trial.intermediate_values.map((iv) => iv.value), | ||
marker: { maxdisplayed: 10 }, | ||
mode: "lines+markers", | ||
type: "scatter", | ||
name: `trial #${trial.number} ${ | ||
trial.state === "Running" | ||
? "(running)" | ||
: !isFeasible | ||
? "(infeasible)" | ||
: "" | ||
}`, | ||
...(!isFeasible && { line: { color: "#CCCCCC" } }), | ||
} | ||
}) | ||
Comment on lines
-84
to
-99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The branch by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
plotly.react(plotDomId, plotData, layout) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,10 @@ const plotIntermediateValue = ( | |
}, | ||
uirevision: "true", | ||
template: mode === "dark" ? plotlyDarkTemplate : {}, | ||
legend: { | ||
x: 1.0, | ||
y: 0.95, | ||
}, | ||
} | ||
if (trials.length === 0) { | ||
plotly.react(plotDomId, [], layout) | ||
|
@@ -79,23 +83,23 @@ const plotIntermediateValue = ( | |
t.values.length > 0) || | ||
t.state === "Running" | ||
) | ||
|
||
const plotData: Partial<plotly.PlotData>[] = filteredTrials.map((trial) => { | ||
const values = trial.intermediate_values.filter( | ||
(iv) => | ||
iv.value !== Infinity && | ||
iv.value !== -Infinity && | ||
!Number.isNaN(iv.value) | ||
) | ||
Comment on lines
-83
to
-88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed those lines because they do not exist in optuna-dashbaord. But, if you feel we should revert them, tell me that, please. |
||
const isFeasible = trial.constraints.every((c) => c <= 0) | ||
return { | ||
x: values.map((iv) => iv.step), | ||
y: values.map((iv) => iv.value), | ||
x: trial.intermediate_values.map((iv) => iv.step), | ||
y: trial.intermediate_values.map((iv) => iv.value), | ||
marker: { maxdisplayed: 10 }, | ||
mode: "lines+markers", | ||
type: "scatter", | ||
name: | ||
trial.state !== "Running" | ||
? `trial #${trial.number}` | ||
: `trial #${trial.number} (running)`, | ||
name: `trial #${trial.number} ${ | ||
trial.state === "Running" | ||
? "(running)" | ||
: !isFeasible | ||
? "(infeasible)" | ||
: "" | ||
}`, | ||
...(!isFeasible && { line: { color: "#CCCCCC" } }), | ||
} | ||
}) | ||
plotly.react(plotDomId, plotData, layout) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add this property on
tslib
side?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added