Skip to content

Commit

Permalink
Merge pull request optuna#773 from knshnb/plotlypy-dependency
Browse files Browse the repository at this point in the history
Resolve plotly.py dependency issue
  • Loading branch information
knshnb authored Jan 26, 2024
2 parents 24b3e05 + b74cdda commit 460ca24
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions optuna_dashboard/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import csv
import functools
import importlib
import io
from itertools import chain
import logging
Expand Down Expand Up @@ -95,6 +96,7 @@ def dashboard() -> BottleViewReturn:
def api_meta() -> dict[str, Any]:
return {
"artifact_is_available": artifact_store is not None,
"plotlypy_is_available": importlib.util.find_spec("plotly") is not None,
}

@app.get("/api/studies")
Expand Down
5 changes: 5 additions & 0 deletions optuna_dashboard/ts/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
paramImportanceState,
isFileUploading,
artifactIsAvailable,
plotlypyIsAvailableState,
reloadIntervalState,
trialsUpdatingState,
studySummariesLoadingState,
Expand All @@ -47,6 +48,9 @@ export const actionCreator = () => {
const setUploading = useSetRecoilState<boolean>(isFileUploading)
const setTrialsUpdating = useSetRecoilState(trialsUpdatingState)
const setArtifactIsAvailable = useSetRecoilState<boolean>(artifactIsAvailable)
const setPlotlypyIsAvailable = useSetRecoilState<boolean>(
plotlypyIsAvailableState
)
const setStudySummariesLoading = useSetRecoilState<boolean>(
studySummariesLoadingState
)
Expand Down Expand Up @@ -215,6 +219,7 @@ export const actionCreator = () => {
const updateAPIMeta = () => {
getMetaInfoAPI().then((r) => {
setArtifactIsAvailable(r.artifact_is_available)
setPlotlypyIsAvailable(r.plotlypy_is_available)
})
}

Expand Down
1 change: 1 addition & 0 deletions optuna_dashboard/ts/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const axiosInstance = axios.create({ baseURL: API_ENDPOINT })

type APIMeta = {
artifact_is_available: boolean
plotlypy_is_available: boolean
}

export const getMetaInfoAPI = (): Promise<APIMeta> => {
Expand Down
12 changes: 11 additions & 1 deletion optuna_dashboard/ts/components/GraphContour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,25 @@ import { useMergedUnionSearchSpace } from "../searchSpace"
import { getAxisInfo } from "../graphUtil"
import { useQuery } from "../urlQuery"
import { getPlotAPI, PlotType } from "../apiClient"
import { useRecoilValue } from "recoil"
import { plotlypyIsAvailableState } from "../state"

const plotDomId = "graph-contour"

export const Contour: FC<{
study: StudyDetail | null
}> = ({ study = null }) => {
const query = useQuery()
const plotlypyIsAvailable = useRecoilValue<boolean>(plotlypyIsAvailableState)
if (query.get("plotlypy_rendering") === "true") {
return <ContourBackend study={study} />
if (plotlypyIsAvailable) {
return <ContourBackend study={study} />
} else {
console.warn(
"Use frontend rendering because plotlypy is specified but not available."
)
return <ContourFrontend study={study} />
}
} else {
return <ContourFrontend study={study} />
}
Expand Down
5 changes: 5 additions & 0 deletions optuna_dashboard/ts/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export const artifactIsAvailable = atom<boolean>({
default: false,
})

export const plotlypyIsAvailableState = atom<boolean>({
key: "plotlypyIsAvailable",
default: true,
})

export const studySummariesLoadingState = atom<boolean>({
key: "studySummariesLoadingState",
default: false,
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ preferential = [
"botorch>=0.8.1",
]

plotlypy = [
"plotly",
]

[project.scripts]
optuna-dashboard = "optuna_dashboard._cli:main"

Expand Down

0 comments on commit 460ca24

Please sign in to comment.