fix: handle when config is undefined for trial length
@@ -31,14 +31,15 @@ interface Params {
trialId: string;
}
-const getTrialLength = (config: RawJson): [string, number] => {
- const maxLength = config.searcher.max_length;
- return Object.entries(maxLength)[0] as [string, number];
+const getTrialLength = (config?: RawJson): [string, number] | undefined => {
+ const entries = Object.entries(config?.searcher.max_length || {});
+ if (entries.length !== 0) return entries[0] as [string, number];
+ return undefined;
};
const setTrialLength = (experimentConfig: RawJson, length: number): void => {
- const lengthType = getTrialLength(experimentConfig)[0];
- experimentConfig.searcher.max_length = { [lengthType]: length } ;
+ const trialLength = getTrialLength(experimentConfig);
+ if (trialLength) experimentConfig.searcher.max_length = { [trialLength[0]]: length } ;
};
const trialContinueConfig =
@@ -73,6 +74,19 @@ const TrialDetailsComp: React.FC = () => {
const metricNames = useMemo(() => extractMetricNames(trial.data?.steps), [ trial.data?.steps ]);
+ const upgradedConfig = useMemo(
+ () => {
+ if (!experiment?.configRaw) return;
+ const configClone = clone(experiment.configRaw);
+ upgradeConfig(configClone);
+ return configClone;
+ },
+ [ experiment?.configRaw ],
+ );
+ const trialLength = useMemo(() => {
+ return getTrialLength(upgradedConfig);
+ }, [ upgradedConfig ]);
+
const pollTrialDetails = useCallback(
() => triggerTrialRequest({ id: trialId }),
[ triggerTrialRequest, trialId ],
@@ -90,23 +104,29 @@ const TrialDetailsComp: React.FC = () => {
}, [ ]);
const setFreshContinueConfig = useCallback(() => {
- if (!experiment?.configRaw || !hparams) return;
+ if (!upgradedConfig || !hparams) return;
// do not reset the config if the modal is open
if (contModalVisible || contFormVisible) return;
- const config = clone(experiment.configRaw);
-
+ const config = clone(upgradedConfig);
const newDescription = `Continuation of trial ${trialId}, experiment` +
- ` ${experimentId} (${experiment.configRaw.description})`;
+ ` ${experimentId} (${config.description})`;
setContDescription(newDescription);
- const maxLength = getTrialLength(experiment.configRaw)[1];
+ const maxLength = trialLength && trialLength[1];
if (maxLength !== undefined) setContMaxLength(maxLength);
config.description = newDescription;
if (maxLength) setTrialLength(config, maxLength);
- upgradeConfig(config);
const newConfig = trialContinueConfig(config, hparams, trialId);
setContModalConfig(yaml.safeDump(newConfig));
- }, [ hparams, trialId, experiment?.configRaw, experimentId, contFormVisible, contModalVisible ]);
+ }, [
+ contFormVisible,
+ contModalVisible,
+ upgradedConfig,
+ experimentId,
+ hparams,
+ trialId,
+ trialLength,
+ ]);
const handleContFormCancel = useCallback(() => {
setContFormVisible(false);
@@ -218,7 +238,7 @@ If the problem persists please contact support.',
);
}
- if (!trial.data || !experiment) {
+ if (!trial.data || !experiment || !upgradedConfig) {
return <Spinner fillContainer />;
}
@@ -284,7 +304,7 @@ If the problem persists please contact support.',
name="basic"
>
<Form.Item
- label={`Max ${getTrialLength(experiment.configRaw)[0]}`}
+ label={`Max ${trialLength && trialLength[0]}`}
name="maxLength"
rules={[ { message: 'Please set max length', required: true } ]}
>
