Skip to content

Commit

Permalink
Merge pull request #875 from porink0424/fix/tslib-types
Browse files Browse the repository at this point in the history
Rename `study_id`, `study_name` -> `id`, `name`
  • Loading branch information
c-bata authored May 8, 2024
2 parents a4ce65f + fc7d7ec commit 987fc0c
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 42 deletions.
2 changes: 1 addition & 1 deletion standalone_app/src/components/StudyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const StudyDetail: FC<{
}),
}}
>
{study?.study_name || "Not Found"}
{study?.name || "Not Found"}
</Typography>
<Card sx={{ margin: theme.spacing(2) }}>
<CardContent>
Expand Down
6 changes: 3 additions & 3 deletions standalone_app/src/components/StudyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const StudyList: FC<{
if (k === "") {
return true
}
return row.study_name.indexOf(k) >= 0
return row.name.indexOf(k) >= 0
})
}
let filteredStudies: Optuna.StudySummary[] = studies.filter(
Expand Down Expand Up @@ -181,13 +181,13 @@ export const StudyList: FC<{
<Box sx={{ display: "flex", flexWrap: "wrap" }}>
{filteredStudies.map((study, idx) => (
<Card
key={study.study_id}
key={study.id}
sx={{ margin: theme.spacing(2), width: "500px" }}
>
<CardActionArea component={Link} to={`/${idx}`}>
<CardContent>
<Typography variant="h5" sx={{ wordBreak: "break-all" }}>
{study.study_id}. {study.study_name}
{study.id}. {study.name}
</Typography>
<Typography
variant="subtitle1"
Expand Down
2 changes: 1 addition & 1 deletion tslib/react/src/MockStudies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const useMockStudies = () => {

export const useMockStudy = (studyId: number | undefined) => {
const mockStudies = useMockStudies()
const mockStudy = mockStudies.find((study) => study.study_id === studyId)
const mockStudy = mockStudies.find((study) => study.id === studyId)
const mockImportance: Optuna.ParamImportance[][] = [
[
{ name: "dropout_l0", importance: 0.07990265450296263 },
Expand Down
8 changes: 3 additions & 5 deletions tslib/react/test/PlotHistory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ describe("PlotHistory Tests", async () => {
}

for (const study of window.mockStudies) {
test(`PlotHistory (study name: ${study.study_name})`, () => {
setup({ study, dataTestId: `plot-history-${study.study_id}` })
expect(
screen.getByTestId(`plot-history-${study.study_id}`)
).toBeInTheDocument()
test(`PlotHistory (study name: ${study.name})`, () => {
setup({ study, dataTestId: `plot-history-${study.id}` })
expect(screen.getByTestId(`plot-history-${study.id}`)).toBeInTheDocument()
})
}
})
8 changes: 4 additions & 4 deletions tslib/react/test/PlotImportance.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe("PlotImportance Tests", async () => {
}

for (const study of window.mockStudies) {
test(`PlotImportance (study name: ${study.study_name})`, () => {
const importance = window.mockImportances[study.study_name] ?? []
test(`PlotImportance (study name: ${study.name})`, () => {
const importance = window.mockImportances[study.name] ?? []
setup({
study,
importance,
dataTestId: `plot-importance-${study.study_id}`,
dataTestId: `plot-importance-${study.id}`,
})
expect(
screen.getByTestId(`plot-importance-${study.study_id}`)
screen.getByTestId(`plot-importance-${study.id}`)
).toBeInTheDocument()
})
}
Expand Down
6 changes: 3 additions & 3 deletions tslib/react/test/PlotIntermediateValues.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe("PlotIntermediateValues Tests", async () => {
}

for (const study of window.mockStudies) {
test(`PlotIntermediateValues (study name: ${study.study_name})`, () => {
setup({ study, dataTestId: `plot-intermediatevalues-${study.study_id}` })
test(`PlotIntermediateValues (study name: ${study.name})`, () => {
setup({ study, dataTestId: `plot-intermediatevalues-${study.id}` })
expect(
screen.getByTestId(`plot-intermediatevalues-${study.study_id}`)
screen.getByTestId(`plot-intermediatevalues-${study.id}`)
).toBeInTheDocument()
})
}
Expand Down
8 changes: 3 additions & 5 deletions tslib/react/test/TrialTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ describe("TrialTable Tests", async () => {
}

for (const study of window.mockStudies) {
test(`TrialTable (study name: ${study.study_name})`, () => {
setup({ study, dataTestId: `trial-table-${study.study_id}` })
expect(
screen.getByTestId(`trial-table-${study.study_id}`)
).toBeInTheDocument()
test(`TrialTable (study name: ${study.name})`, () => {
setup({ study, dataTestId: `trial-table-${study.id}` })
expect(screen.getByTestId(`trial-table-${study.id}`)).toBeInTheDocument()
})
}
})
12 changes: 5 additions & 7 deletions tslib/storage/src/journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class JournalStorage {

public applyCreateStudy(log: JournalOpCreateStudy): void {
this.studies.push({
study_id: this.nextStudyId,
study_name: log.study_name,
id: this.nextStudyId,
name: log.study_name,
directions: [log.directions[0] === 1 ? "minimize" : "maximize"],
union_search_space: [],
intersection_search_space: [],
Expand All @@ -176,13 +176,11 @@ class JournalStorage {
}

public applyDeleteStudy(log: JournalOpDeleteStudy): void {
this.studies = this.studies.filter((item) => item.study_id !== log.study_id)
this.studies = this.studies.filter((item) => item.id !== log.study_id)
}

public applyCreateTrial(log: JournalOpCreateTrial): void {
const thisStudy = this.studies.find(
(item) => item.study_id === log.study_id
)
const thisStudy = this.studies.find((item) => item.id === log.study_id)
if (thisStudy === undefined) {
return
}
Expand Down Expand Up @@ -256,7 +254,7 @@ class JournalStorage {

private getStudyAndTrial(trial_id: number): [Optuna.Study?, Optuna.Trial?] {
const study = this.studies.find(
(item) => item.study_id === this.trialIdToStudyId.get(trial_id)
(item) => item.id === this.trialIdToStudyId.get(trial_id)
)
if (study === undefined) {
return [undefined, undefined]
Expand Down
12 changes: 6 additions & 6 deletions tslib/storage/src/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ const getStudySummaries = (db: SQLite3DB): Optuna.StudySummary[] => {

if (objective === 0) {
summaries.push({
study_id: studyId,
study_name: studyName,
id: studyId,
name: studyName,
directions: [direction],
})
return
}
const index = summaries.findIndex((s) => s.study_id === studyId)
const index = summaries.findIndex((s) => s.id === studyId)
summaries[index].directions.push(direction)
},
})
Expand All @@ -135,8 +135,8 @@ const getStudy = (
summary: Optuna.StudySummary
): Optuna.Study => {
const study: Optuna.Study = {
study_id: summary.study_id,
study_name: summary.study_name,
id: summary.id,
name: summary.name,
directions: summary.directions,
union_search_space: [],
intersection_search_space: [],
Expand All @@ -145,7 +145,7 @@ const getStudy = (
}

let intersection_search_space: Set<Optuna.SearchSpaceItem> = new Set()
study.trials = getTrials(db, summary.study_id, schemaVersion)
study.trials = getTrials(db, summary.id, schemaVersion)
for (const trial of study.trials) {
const userAttrs = getTrialUserAttributes(db, trial.trial_id)
for (const attr of userAttrs) {
Expand Down
4 changes: 2 additions & 2 deletions tslib/storage/test/journal.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Test Journal File Storage", async () => {
)

it("Check the study including Infinities", () => {
const study = studies.find((s) => s.study_name === "single-inf")
const study = studies.find((s) => s.name === "single-inf")
study.trials.forEach((trial, index) => {
if (index % 3 === 0) {
assert.strictEqual(trial.values[0], Infinity)
Expand All @@ -28,7 +28,7 @@ describe("Test Journal File Storage", async () => {
})

it("Check the study including NaNs", () => {
const study = studies.find((s) => s.study_name === "single-nan-report")
const study = studies.find((s) => s.name === "single-nan-report")
for (const trial of study.trials) {
assert.strictEqual(
trial.intermediate_values.find((v) => v.step === 1).value,
Expand Down
10 changes: 5 additions & 5 deletions tslib/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export type AttributeSpec = {
}

export type StudySummary = {
study_id: number
study_name: string
id: number
name: string
directions: StudyDirection[]
}

export type Study = {
study_id: number
study_name: string
id: number
name: string
directions: StudyDirection[]
union_search_space: SearchSpaceItem[]
intersection_search_space: SearchSpaceItem[]
Expand All @@ -64,8 +64,8 @@ export type Study = {

export type Trial = {
trial_id: number
number: number
study_id: number
number: number
state: TrialState
values?: number[]
params: TrialParam[]
Expand Down

0 comments on commit 987fc0c

Please sign in to comment.