From 69e74dc928f2201ffd969efad163040925d83ffb Mon Sep 17 00:00:00 2001 From: c-bata Date: Sat, 10 Apr 2021 02:51:20 +0900 Subject: [PATCH] Fast union search space on GraphSlice --- .../static/components/GraphSlice.tsx | 46 ++++++------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/optuna_dashboard/static/components/GraphSlice.tsx b/optuna_dashboard/static/components/GraphSlice.tsx index 9b840bd7..b504e3a6 100644 --- a/optuna_dashboard/static/components/GraphSlice.tsx +++ b/optuna_dashboard/static/components/GraphSlice.tsx @@ -25,33 +25,17 @@ const useStyles = makeStyles((theme: Theme) => }) ) -const getParamNames = (trials: Trial[]): string[] => { - const paramSet = new Set( - ...trials.map((t) => t.params.map((p) => p.name)) - ) - return Array.from(paramSet) -} - export const GraphSlice: FC<{ study: StudyDetail | null }> = ({ study = null }) => { const classes = useStyles() const trials: Trial[] = study !== null ? study.trials : [] - const [paramNames, setParamNames] = useState([]) const [objectiveId, setObjectiveId] = useState(0) const [selected, setSelected] = useState(null) - - useEffect(() => { - if (trials.length === 0 || paramNames.length !== 0) { - return - } - - const p = getParamNames(trials) - setParamNames(p) - if (selected === null && p.length !== 0) { - setSelected(p[0]) - } - }, [trials]) + const paramNames = study?.union_search_space.map(s => s.name) + if (selected === null && paramNames && paramNames.length > 0) { + setSelected(paramNames[0]) + } useEffect(() => { plotSlice(trials, objectiveId, selected) @@ -86,18 +70,16 @@ export const GraphSlice: FC<{ ) : null} - {paramNames.length !== 0 && selected !== null ? ( - - Parameter - - - ) : null} + + Parameter + +