Skip to content

Commit 247f9ab

Browse files
committed
#387 limit user's ability on experiment number of trials
1 parent e6aa799 commit 247f9ab

1 file changed

Lines changed: 80 additions & 53 deletions

File tree

webapp/components/experiments/ExperimentEdit.js

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ import Utils from '../../Utils';
2525
import ParameterMenu from './ParameterMenu';
2626
import useStyles from './ExperimentEditStyle';
2727
import * as ExperimentHelper from './ExperimentHelper';
28+
import DialogBox from '../general/DialogBox';
2829

2930
const RANGE_VALUE = 0;
3031
const SUPPORTED_TYPES = [REAL_TYPE.INT, REAL_TYPE.FLOAT, REAL_TYPE.STR, REAL_TYPE.BOOL];
32+
const MAX_TRIALS = 100;
33+
let numberOfTrials = 1;
3134

3235
const {
3336
RANGE,
@@ -189,6 +192,7 @@ const ExperimentEdit = (props) => {
189192
const [experimentName, setExperimentName] = useState('');
190193
const [experimentNameError, setExperimentNameError] = useState('');
191194
const [selectionParams, setSelectionParams] = useState([]);
195+
const [trialNumberErrorDialogOpen, setTrialNumberErrorDialogOpen] = useState(false);
192196

193197
// Existing Experiment.
194198
const [experiment, setExperiment] = useState(null);
@@ -339,7 +343,19 @@ const ExperimentEdit = (props) => {
339343
params,
340344
};
341345

342-
if (editState) {
346+
numberOfTrials = 1;
347+
348+
params.forEach((param) => {
349+
if (param.type === LIST) {
350+
numberOfTrials *= param.values.length;
351+
} else if (param.type === RANGE) {
352+
numberOfTrials *= Math.ceil((param.max - param.min) / param.step);
353+
}
354+
});
355+
356+
if (numberOfTrials > MAX_TRIALS) {
357+
setTrialNumberErrorDialogOpen(true);
358+
} else if (editState) {
343359
ExperimentsApi.editExperiment(experiment?.name, newExperimentDetails)
344360
.then(() => {
345361
setView(EXPERIMENT_VIEWS.list);
@@ -467,34 +483,35 @@ const ExperimentEdit = (props) => {
467483
};
468484

469485
return (
470-
<GridLayout className={classes.root}>
471-
<Box className="editExperimentContainer">
472-
<Box my={3} className="editExperimentBack">
473-
<ArrowBackIcon onClick={() => setView(EXPERIMENT_VIEWS.list)} />
474-
<Typography variant="body2">{!editState ? 'New Experiment' : 'Edit Experiment'}</Typography>
475-
</Box>
476-
<Box mb={2} className="editExperimentHead">
477-
<form noValidate autoComplete="off">
478-
<TextField
479-
id="experiment-name"
480-
label="Experiment Name"
481-
variant="filled"
482-
value={experimentName}
483-
onChange={(e) => setExperimentNameInfo(e.target.value)}
484-
error={experimentNameError !== ''}
485-
helperText={experimentNameError}
486-
/>
487-
</form>
488-
<Box mt={3}>
489-
<Divider />
486+
<>
487+
<GridLayout className={classes.root}>
488+
<Box className="editExperimentContainer">
489+
<Box my={3} className="editExperimentBack">
490+
<ArrowBackIcon onClick={() => setView(EXPERIMENT_VIEWS.list)} />
491+
<Typography variant="body2">{!editState ? 'New Experiment' : 'Edit Experiment'}</Typography>
490492
</Box>
491-
</Box>
492-
<Box className="editExperimentContent">
493-
<Box mb={1} className="editExperimentDefault">
494-
<Box mb={2} className="editExperimentBreadcrumb">
495-
<Typography variant="body2">Parameters</Typography>
493+
<Box mb={2} className="editExperimentHead">
494+
<form noValidate autoComplete="off">
495+
<TextField
496+
id="experiment-name"
497+
label="Experiment Name"
498+
variant="filled"
499+
value={experimentName}
500+
onChange={(e) => setExperimentNameInfo(e.target.value)}
501+
error={experimentNameError !== ''}
502+
helperText={experimentNameError}
503+
/>
504+
</form>
505+
<Box mt={3}>
506+
<Divider />
496507
</Box>
497-
{groupParameters.length > 0 && (
508+
</Box>
509+
<Box className="editExperimentContent">
510+
<Box mb={1} className="editExperimentDefault">
511+
<Box mb={2} className="editExperimentBreadcrumb">
512+
<Typography variant="body2">Parameters</Typography>
513+
</Box>
514+
{groupParameters.length > 0 && (
498515
<Box mb={2} className="editExperimentGroup">
499516
<Box mb={2} className="editExperimentBreadcrumb">
500517
<Typography variant="body2">Grouped Parameters</Typography>
@@ -512,43 +529,53 @@ const ExperimentEdit = (props) => {
512529
</Box>
513530
)}
514531
</Box>
515-
)}
516-
{selectionParams.length > 0 && (
532+
)}
533+
{selectionParams.length > 0 && (
517534
<Box className="editExperimentRow">
518535
{parameters.map((parameter, index) => (
519536
ParameterRow(parameter, index, handleParamSelection, handleChange,
520537
handleRangeInput, handleInputValues, addToGroup, removeFromGroup,
521538
removeParameter, selectionParams, classes)
522539
))}
523540
</Box>
524-
)}
541+
)}
542+
</Box>
543+
</Box>
544+
<Box>
545+
<Link to="true" color="primary" onClick={addParameter}>
546+
<AddIcon />
547+
Add parameter
548+
</Link>
525549
</Box>
526550
</Box>
527-
<Box>
528-
<Link to="true" color="primary" onClick={addParameter}>
529-
<AddIcon />
530-
Add parameter
531-
</Link>
532-
</Box>
533-
</Box>
534-
<Box
535-
className="scrollbar scrollchild"
536-
mt={1}
537-
display="flex"
538-
flexWrap="wrap"
539-
>
540-
<Box className="editExperimentFooter">
541-
<Box display="flex">
542-
<Button color="secondary" onClick={() => setView(EXPERIMENT_VIEWS.list)}>
543-
Cancel
544-
</Button>
545-
<Button variant="contained" color="primary" onClick={submit}>
546-
{editState ? 'Save' : 'Create'}
547-
</Button>
551+
<Box
552+
className="scrollbar scrollchild"
553+
mt={1}
554+
display="flex"
555+
flexWrap="wrap"
556+
>
557+
<Box className="editExperimentFooter">
558+
<Box display="flex">
559+
<Button color="secondary" onClick={() => setView(EXPERIMENT_VIEWS.list)}>
560+
Cancel
561+
</Button>
562+
<Button variant="contained" color="primary" onClick={submit}>
563+
{editState ? 'Save' : 'Create'}
564+
</Button>
565+
</Box>
548566
</Box>
549567
</Box>
550-
</Box>
551-
</GridLayout>
568+
</GridLayout>
569+
<DialogBox
570+
open={trialNumberErrorDialogOpen}
571+
onDialogResponse={() => setTrialNumberErrorDialogOpen(false)}
572+
textForDialog={{
573+
heading: 'Error - Number of trials is too large',
574+
content: `Please adjust your exploration parameters to
575+
reduce the number of experiment trials to less than 100. Current number of trials: ${numberOfTrials}`,
576+
}}
577+
/>
578+
</>
552579
);
553580
};
554581

0 commit comments

Comments
 (0)