Skip to content

Commit

Permalink
Merge pull request #940 from c-bata/remove-objective-names
Browse files Browse the repository at this point in the history
Rename objective_names to metric_names
  • Loading branch information
c-bata authored Aug 20, 2024
2 parents 7bdb338 + 9f1eb6e commit 01cbcf5
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions optuna_dashboard/ts/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface StudyDetailResponse {
has_intermediate_values: boolean
note: Note
is_preferential: boolean
// TODO(c-bata): Rename this to metric_names after releasing the new Jupyter Lab extension.
objective_names?: string[]
form_widgets?: FormWidgets
preferences?: [number, number][]
Expand Down
2 changes: 1 addition & 1 deletion optuna_dashboard/ts/axiosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AxiosClient extends APIClient {
union_user_attrs: res.data.union_user_attrs,
has_intermediate_values: res.data.has_intermediate_values,
note: res.data.note,
objective_names: res.data.objective_names,
metric_names: res.data.objective_names,
form_widgets: res.data.form_widgets,
is_preferential: res.data.is_preferential,
feedback_component_type: res.data.feedback_component_type,
Expand Down
6 changes: 3 additions & 3 deletions optuna_dashboard/ts/components/GraphContour.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const ContourFrontend: FC<{
const searchSpace = useMergedUnionSearchSpace(study?.union_search_space)
const [xParam, setXParam] = useState<SearchSpaceItem | null>(null)
const [yParam, setYParam] = useState<SearchSpaceItem | null>(null)
const objectiveNames: string[] = study?.objective_names || []
const metricNames: string[] = study?.metric_names || []

if (xParam === null && searchSpace.length > 0) {
setXParam(searchSpace[0])
Expand Down Expand Up @@ -182,8 +182,8 @@ const ContourFrontend: FC<{
<Select value={objectiveId} onChange={handleObjectiveChange}>
{study.directions.map((d, i) => (
<MenuItem value={i} key={i}>
{objectiveNames.length === study?.directions.length
? objectiveNames[i]
{metricNames.length === study?.directions.length
? metricNames[i]
: `${i}`}
</MenuItem>
))}
Expand Down
10 changes: 5 additions & 5 deletions optuna_dashboard/ts/components/GraphHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface HistoryPlotInfo {
study_name: string
trials: Optuna.Trial[]
directions: Optuna.StudyDirection[]
objective_names?: string[]
metric_names?: string[]
}

export const GraphHistory: FC<{
Expand Down Expand Up @@ -63,7 +63,7 @@ export const GraphHistory: FC<{
study_name: study?.name,
trials: trials[index],
directions: study?.directions,
objective_names: study?.objective_names,
metric_names: study?.metric_names,
}
return h
})
Expand Down Expand Up @@ -164,7 +164,7 @@ export const GraphHistory: FC<{
>
{targets.map((t, i) => (
<MenuItem value={t.identifier()} key={i}>
{t.toLabel(studies[0].objective_names)}
{t.toLabel(studies[0].metric_names)}
</MenuItem>
))}
</Select>
Expand Down Expand Up @@ -253,7 +253,7 @@ const plotHistory = (
b: 0,
},
yaxis: {
title: target.toLabel(historyPlotInfos[0].objective_names),
title: target.toLabel(historyPlotInfos[0].metric_names),
type: logScale ? "log" : "linear",
},
xaxis: {
Expand Down Expand Up @@ -293,7 +293,7 @@ const plotHistory = (
y: feasibleTrials.map(
(t: Optuna.Trial): number => target.getTargetValue(t) as number
),
name: `${target.toLabel(h.objective_names)} of ${h.study_name}`,
name: `${target.toLabel(h.metric_names)} of ${h.study_name}`,
marker: {
size: markerSize,
},
Expand Down
10 changes: 5 additions & 5 deletions optuna_dashboard/ts/components/GraphParetoFront.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const GraphParetoFrontFrontend: FC<{
const navigate = useNavigate()
const [objectiveXId, setObjectiveXId] = useState<number>(0)
const [objectiveYId, setObjectiveYId] = useState<number>(1)
const objectiveNames: string[] = study?.objective_names || []
const metricNames: string[] = study?.metric_names || []

const handleObjectiveXChange = (event: SelectChangeEvent<number>) => {
setObjectiveXId(event.target.value as number)
Expand Down Expand Up @@ -130,8 +130,8 @@ const GraphParetoFrontFrontend: FC<{
<Select value={objectiveXId} onChange={handleObjectiveXChange}>
{study.directions.map((d, i) => (
<MenuItem value={i} key={i}>
{objectiveNames.length === study?.directions.length
? objectiveNames[i]
{metricNames.length === study?.directions.length
? metricNames[i]
: `${i}`}
</MenuItem>
))}
Expand All @@ -142,8 +142,8 @@ const GraphParetoFrontFrontend: FC<{
<Select value={objectiveYId} onChange={handleObjectiveYChange}>
{study.directions.map((d, i) => (
<MenuItem value={i} key={i}>
{objectiveNames.length === study?.directions.length
? objectiveNames[i]
{metricNames.length === study?.directions.length
? metricNames[i]
: `${i}`}
</MenuItem>
))}
Expand Down
6 changes: 3 additions & 3 deletions optuna_dashboard/ts/components/GraphRank.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const GraphRankFrontend: FC<{
const searchSpace = useMergedUnionSearchSpace(study?.union_search_space)
const [xParam, setXParam] = useState<SearchSpaceItem | null>(null)
const [yParam, setYParam] = useState<SearchSpaceItem | null>(null)
const objectiveNames: string[] = study?.objective_names || []
const metricNames: string[] = study?.metric_names || []

if (xParam === null && searchSpace.length > 0) {
setXParam(searchSpace[0])
Expand Down Expand Up @@ -150,8 +150,8 @@ const GraphRankFrontend: FC<{
<Select value={objectiveId} onChange={handleObjectiveChange}>
{study.directions.map((d, i) => (
<MenuItem value={i} key={i}>
{objectiveNames.length === study?.directions.length
? objectiveNames[i]
{metricNames.length === study?.directions.length
? metricNames[i]
: `${i}`}
</MenuItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const CandidateTrial: FC<{
trial={trial}
isBestTrial={() => false}
directions={[]}
objectiveNames={[]}
metricNames={[]}
/>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export const PreferentialTrials: FC<{ studyDetail: StudyDetail | null }> = ({
?.state === "Complete" ?? false
}
directions={[]}
objectiveNames={[]}
metricNames={[]}
/>
</Box>
</Box>
Expand Down
8 changes: 4 additions & 4 deletions optuna_dashboard/ts/components/TrialFormWidgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type WidgetState = {

export const TrialFormWidgets: FC<{
trial: Trial
objectiveNames: string[]
metricNames: string[]
directions: Optuna.StudyDirection[]
formWidgets?: FormWidgets
}> = ({ trial, objectiveNames, directions, formWidgets }) => {
}> = ({ trial, metricNames, directions, formWidgets }) => {
if (
formWidgets === undefined ||
trial.state === "Pruned" ||
Expand All @@ -56,8 +56,8 @@ export const TrialFormWidgets: FC<{
: "Set Objective Value Form"
const widgetNames = formWidgets.widgets.map((widget, i) => {
if (formWidgets.output_type === "objective") {
if (objectiveNames.at(i) !== undefined) {
return objectiveNames[i]
if (metricNames.at(i) !== undefined) {
return metricNames[i]
}
return directions.length === 1 ? "Objective" : `Objective ${i}`
} else if (formWidgets.output_type === "user_attr") {
Expand Down
8 changes: 4 additions & 4 deletions optuna_dashboard/ts/components/TrialList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export const TrialListDetail: FC<{
trial: Trial
isBestTrial: (trialId: number) => boolean
directions: Optuna.StudyDirection[]
objectiveNames: string[]
metricNames: string[]
formWidgets?: FormWidgets
}> = ({ trial, isBestTrial, directions, objectiveNames, formWidgets }) => {
}> = ({ trial, isBestTrial, directions, metricNames, formWidgets }) => {
const theme = useTheme()
const action = actionCreator()
const artifactEnabled = useRecoilValue<boolean>(artifactIsAvailable)
Expand Down Expand Up @@ -290,7 +290,7 @@ export const TrialListDetail: FC<{
<TrialFormWidgets
trial={trial}
directions={directions}
objectiveNames={objectiveNames}
metricNames={metricNames}
formWidgets={formWidgets}
/>
<Box
Expand Down Expand Up @@ -561,7 +561,7 @@ export const TrialList: FC<{ studyDetail: StudyDetail | null }> = ({
trial={t}
isBestTrial={isBestTrial}
directions={studyDetail?.directions || []}
objectiveNames={studyDetail?.objective_names || []}
metricNames={studyDetail?.metric_names || []}
formWidgets={studyDetail?.form_widgets}
/>
))}
Expand Down
6 changes: 3 additions & 3 deletions optuna_dashboard/ts/components/TrialTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const TrialTable: FC<{

const theme = useTheme()
const trials: Trial[] = studyDetail !== null ? studyDetail.trials : []
const objectiveNames: string[] = studyDetail?.objective_names || []
const metricNames: string[] = studyDetail?.metric_names || []

const columnHelper = createColumnHelper<Trial>()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -63,8 +63,8 @@ export const TrialTable: FC<{
columnHelper.accessor((row) => row["values"]?.[objectiveId], {
id: `values_${objectiveId}`,
header:
objectiveNames.length === studyDetail?.directions.length
? objectiveNames[objectiveId]
metricNames.length === studyDetail?.directions.length
? metricNames[objectiveId]
: `Objective ${objectiveId}`,
enableSorting: true,
enableColumnFilter: false,
Expand Down
2 changes: 1 addition & 1 deletion optuna_dashboard/ts/types/optuna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export type StudyDetail = {
has_intermediate_values: boolean
note: Note
is_preferential: boolean
objective_names?: string[]
metric_names?: string[]
form_widgets?: FormWidgets
feedback_component_type: FeedbackComponentType
preferences?: [number, number][]
Expand Down

0 comments on commit 01cbcf5

Please sign in to comment.