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

Use plot_param_importances in backend #683

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions optuna_dashboard/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@
response.status = 400 # Bad request
return {"reason": str(e)}

@app.get("/api/studies/<study_id:int>/param_importances_plot")
@json_api_view
def get_param_importances_plot(study_id: int) -> dict[str, Any]:
study = optuna.load_study(

Check warning on line 267 in optuna_dashboard/_app.py

View check run for this annotation

Codecov / codecov/patch

optuna_dashboard/_app.py#L267

Added line #L267 was not covered by tests
study_name=storage.get_study_name_from_id(study_id), storage=storage
)
fig = optuna.visualization.plot_param_importances(study)
return fig.to_json()

Check warning on line 271 in optuna_dashboard/_app.py

View check run for this annotation

Codecov / codecov/patch

optuna_dashboard/_app.py#L270-L271

Added lines #L270 - L271 were not covered by tests

@app.put("/api/studies/<study_id:int>/note")
@json_api_view
def save_study_note(study_id: int) -> dict[str, Any]:
Expand Down
12 changes: 12 additions & 0 deletions optuna_dashboard/ts/components/GraphHyperparameterImportances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { plotlyDarkTemplate } from "./PlotlyDarkMode"
import { actionCreator } from "../action"
import { useParamImportanceValue, useStudyDirections } from "../state"
const plotDomId = "graph-hyperparameter-importances"
const plotBackendDomId = "graph-hyperparameter-importances-backend"

export const GraphHyperparameterImportance: FC<{
studyId: number
Expand All @@ -27,6 +28,16 @@ export const GraphHyperparameterImportance: FC<{
action.updateParamImportance(studyId)
}, [numCompletedTrials])

useEffect(() => {
fetch(`/api/studies/${studyId}/param_importances_plot`, {mode: 'cors'})
.then((response) => response.json())
.then((figure) => {
plotly.react(plotBackendDomId, figure.data, figure.layout)
}).catch((err) => {
console.error(err);
})
}, [numCompletedTrials])

useEffect(() => {
if (importances !== null && nObjectives === importances.length) {
plotParamImportance(importances, objectiveNames, theme.palette.mode)
Expand All @@ -43,6 +54,7 @@ export const GraphHyperparameterImportance: FC<{
Hyperparameter Importance
</Typography>
<Box id={plotDomId} sx={{ height: graphHeight }} />
<Box id={plotBackendDomId} sx={{ height: graphHeight }} />
</CardContent>
</Card>
)
Expand Down
Loading