Use array for tell values

This commit is contained in:
keisuke-umezawa
2023-01-24 10:58:18 +09:00
parent 96a6362850
commit bd07e0497a
4 changed files with 15 additions and 15 deletions
+4 -4
View File
@@ -415,13 +415,13 @@ def create_app(storage: BaseStorage, debug: bool = False) -> Bottle:
@json_api_view
def tell_trial(study_id: int, trial_id: int) -> BottleViewReturn:
s = request.json.get("state", None)
v = request.json.get("value", None)
vs = request.json.get("values", None)
try:
value = float(v) if v is not None else v
values = [float(v) for v in vs] if vs is not None else vs
except ValueError:
response.status = 400 # Bad request
return {"reason": "You need to pass float castable value"}
return {"reason": "You need to pass float castable values"}
string2State = {
"Running": TrialState.RUNNING,
@@ -444,7 +444,7 @@ def create_app(storage: BaseStorage, debug: bool = False) -> Bottle:
study = optuna.load_study(storage=storage, study_name=study_name)
try:
study.tell(trial_id, values=value, state=state)
study.tell(trial_id, values=values, state=state)
except Exception as e:
response.status = 400 # Bad request
return {"reason": e.args}
+3 -3
View File
@@ -270,10 +270,10 @@ export const actionCreator = () => {
studyId: number,
trialId: number,
state: TrialState,
value?: string
values?: string[]
) => {
const message = value === undefined ? `id=${trialId}, state=${state}` : `id=${trialId}, state=${state}, value=${value}`
tellTrialAPI(studyId, trialId, state, value)
const message = values === undefined ? `id=${trialId}, state=${state}` : `id=${trialId}, state=${state}, values=${values}`
tellTrialAPI(studyId, trialId, state, values)
.then(() => {
enqueueSnackbar(`Success to update trial (${message})`, {
variant: "success",
+4 -4
View File
@@ -221,11 +221,11 @@ export const tellTrialAPI = (
studyId: number,
trialId: number,
state: TrialState,
value?: string
values?: string[]
): Promise<void> => {
const req: { [name: string]: string } = {state: state}
if (value !== undefined) {
req["value"] = value
const req: { [name: string]: TrialState | string[] } = {state: state}
if (values !== undefined) {
req["values"] = values
}
return axiosInstance
@@ -267,15 +267,15 @@ export const TrialTable: FC<{
const collapseBody = (index: number) => {
const [value, setValue] = useState("")
const [objectiveValue, setObjectiveValue] = useState("")
const handleSubmit = (e: FormEvent<HTMLFormElement>): void => {
e.preventDefault()
const studyId = (studyDetail as StudyDetail).id
const trialId = trials[index].number
action.tellTrial(studyId, trialId, "Complete" as TrialState, value)
action.tellTrial(studyId, trialId, "Complete" as TrialState, [objectiveValue])
}
const handleChangeValue = (e: ChangeEvent<HTMLInputElement>): void => {
setValue(e.target.value)
setObjectiveValue(e.target.value)
}
const handleFailTrial = (e: MouseEvent<HTMLButtonElement>): void => {
const studyId = (studyDetail as StudyDetail).id
@@ -320,7 +320,7 @@ export const TrialTable: FC<{
</Typography>
<form onSubmit={handleSubmit}>
<Box margin={1}>
<TextField id="objective-0" label="Objective 0" type="number" value={value} onChange={handleChangeValue} />
<TextField id="objective-0" label="Objective 0" type="number" value={objectiveValue} onChange={handleChangeValue} />
<TextField id="objective-1" label="Objective 1" type="number" />
</Box>
<Button variant="contained" type="submit">