@@ -25,9 +25,11 @@ import Utils from '../../Utils';
2525import ParameterMenu from './ParameterMenu' ;
2626import useStyles from './ExperimentEditStyle' ;
2727import * as ExperimentHelper from './ExperimentHelper' ;
28+ import DialogBox from '../general/DialogBox' ;
2829
2930const RANGE_VALUE = 0 ;
3031const SUPPORTED_TYPES = [ REAL_TYPE . INT , REAL_TYPE . FLOAT , REAL_TYPE . STR , REAL_TYPE . BOOL ] ;
32+ const MAX_TRIALS = 100 ;
3133
3234const {
3335 RANGE ,
@@ -189,11 +191,14 @@ const ExperimentEdit = (props) => {
189191 const [ experimentName , setExperimentName ] = useState ( '' ) ;
190192 const [ experimentNameError , setExperimentNameError ] = useState ( '' ) ;
191193 const [ selectionParams , setSelectionParams ] = useState ( [ ] ) ;
194+ const [ trialNumberErrorDialogOpen , setTrialNumberErrorDialogOpen ] = useState ( false ) ;
192195
193196 // Existing Experiment.
194197 const [ experiment , setExperiment ] = useState ( null ) ;
195198 const experiments = useSelector ( ( state ) => state . experiments . experiments ) ;
196199
200+ let numberOfTrials = 1 ;
201+
197202 const validateParameter = ( param ) => {
198203 let updatedParam = param ;
199204 if ( param . type === LIST ) {
@@ -339,7 +344,19 @@ const ExperimentEdit = (props) => {
339344 params,
340345 } ;
341346
342- if ( editState ) {
347+ numberOfTrials = 1 ;
348+
349+ params . forEach ( ( param ) => {
350+ if ( param . type === LIST ) {
351+ numberOfTrials *= param . values . length ;
352+ } else if ( param . type === RANGE ) {
353+ numberOfTrials *= Math . ceil ( ( param . max - param . min ) / param . step ) ;
354+ }
355+ } ) ;
356+
357+ if ( numberOfTrials > MAX_TRIALS ) {
358+ setTrialNumberErrorDialogOpen ( true ) ;
359+ } else if ( editState ) {
343360 ExperimentsApi . editExperiment ( experiment ?. name , newExperimentDetails )
344361 . then ( ( ) => {
345362 setView ( EXPERIMENT_VIEWS . list ) ;
@@ -467,34 +484,35 @@ const ExperimentEdit = (props) => {
467484 } ;
468485
469486 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 />
487+ < >
488+ < GridLayout className = { classes . root } >
489+ < Box className = "editExperimentContainer" >
490+ < Box my = { 3 } className = "editExperimentBack" >
491+ < ArrowBackIcon onClick = { ( ) => setView ( EXPERIMENT_VIEWS . list ) } />
492+ < Typography variant = "body2" > { ! editState ? 'New Experiment' : 'Edit Experiment' } </ Typography >
490493 </ 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 >
494+ < Box mb = { 2 } className = "editExperimentHead" >
495+ < form noValidate autoComplete = "off" >
496+ < TextField
497+ id = "experiment-name"
498+ label = "Experiment Name"
499+ variant = "filled"
500+ value = { experimentName }
501+ onChange = { ( e ) => setExperimentNameInfo ( e . target . value ) }
502+ error = { experimentNameError !== '' }
503+ helperText = { experimentNameError }
504+ />
505+ </ form >
506+ < Box mt = { 3 } >
507+ < Divider />
496508 </ Box >
497- { groupParameters . length > 0 && (
509+ </ Box >
510+ < Box className = "editExperimentContent" >
511+ < Box mb = { 1 } className = "editExperimentDefault" >
512+ < Box mb = { 2 } className = "editExperimentBreadcrumb" >
513+ < Typography variant = "body2" > Parameters</ Typography >
514+ </ Box >
515+ { groupParameters . length > 0 && (
498516 < Box mb = { 2 } className = "editExperimentGroup" >
499517 < Box mb = { 2 } className = "editExperimentBreadcrumb" >
500518 < Typography variant = "body2" > Grouped Parameters</ Typography >
@@ -512,43 +530,53 @@ const ExperimentEdit = (props) => {
512530 </ Box >
513531 ) }
514532 </ Box >
515- ) }
516- { selectionParams . length > 0 && (
533+ ) }
534+ { selectionParams . length > 0 && (
517535 < Box className = "editExperimentRow" >
518536 { parameters . map ( ( parameter , index ) => (
519537 ParameterRow ( parameter , index , handleParamSelection , handleChange ,
520538 handleRangeInput , handleInputValues , addToGroup , removeFromGroup ,
521539 removeParameter , selectionParams , classes )
522540 ) ) }
523541 </ Box >
524- ) }
542+ ) }
543+ </ Box >
544+ </ Box >
545+ < Box >
546+ < Link to = "true" color = "primary" onClick = { addParameter } >
547+ < AddIcon />
548+ Add parameter
549+ </ Link >
525550 </ Box >
526551 </ 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 >
552+ < Box
553+ className = "scrollbar scrollchild"
554+ mt = { 1 }
555+ display = "flex"
556+ flexWrap = "wrap"
557+ >
558+ < Box className = "editExperimentFooter" >
559+ < Box display = "flex" >
560+ < Button color = "secondary" onClick = { ( ) => setView ( EXPERIMENT_VIEWS . list ) } >
561+ Cancel
562+ </ Button >
563+ < Button variant = "contained" color = "primary" onClick = { submit } >
564+ { editState ? 'Save' : 'Create' }
565+ </ Button >
566+ </ Box >
548567 </ Box >
549568 </ Box >
550- </ Box >
551- </ GridLayout >
569+ </ GridLayout >
570+ < DialogBox
571+ open = { trialNumberErrorDialogOpen }
572+ onDialogResponse = { ( ) => setTrialNumberErrorDialogOpen ( false ) }
573+ textForDialog = { {
574+ heading : 'Error - Number of trials is too large' ,
575+ content : `Please adjust your exploration parameters to
576+ reduce the number of experiment trials to less than 100. Current number of trials: ${ numberOfTrials } ` ,
577+ } }
578+ />
579+ </ >
552580 ) ;
553581} ;
554582
0 commit comments