From 3a140e5612085bc966901bb0c628198cecc02b41 Mon Sep 17 00:00:00 2001 From: David Sampson Date: Wed, 8 Mar 2023 18:45:37 -0500 Subject: [PATCH 01/11] Renamed experimentOutput and fileOutpu --- apps/backend/app.py | 10 ++-- apps/backend/modules/runner.py | 49 ++++++++++--------- apps/frontend/components/NewExp.tsx | 8 +-- .../stepComponents/InformationStep.tsx | 8 +-- apps/frontend/firebase/db.ts | 4 +- apps/frontend/pages/dashboard.tsx | 2 +- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/apps/backend/app.py b/apps/backend/app.py index d0d112d9..ee47b36d 100644 --- a/apps/backend/app.py +++ b/apps/backend/app.py @@ -74,8 +74,8 @@ def run_batch(data): experiment = expRef.get().to_dict() print(f"Experiment info: {experiment}") experiment['id'] = expId - experimentOutput = experiment['fileOutput'] - resultOutput = experiment['resultOutput'] + trialExtraFile = experiment['trialExtraFile'] + trialResult = experiment['trialResult'] keepLogs = experiment['keepLogs'] scatterPlot = experiment['scatter'] dumbTextArea = experiment['consts'] @@ -84,7 +84,7 @@ def run_batch(data): #Downloading Experiment File os.makedirs(f'ExperimentFiles/{expId}') os.chdir(f'ExperimentFiles/{expId}') - if experimentOutput != '' or postProcess != '' or keepLogs: + if trialExtraFile != '' or postProcess != '' or keepLogs: print('There will be experiment outputs') os.makedirs('ResCsvs') print(f'Downloading file for {expId}') @@ -124,7 +124,7 @@ def run_batch(data): try: #Running the Experiment - conduct_experiment(expId, expRef, experimentOutput, resultOutput, filepath, filetype, numExperimentsToRun) + conduct_experiment(expId, expRef, trialExtraFile, trialResult, filepath, filetype, numExperimentsToRun, keepLogs) # Post Processing if postProcess: @@ -143,7 +143,7 @@ def run_batch(data): uploadBlob = firebaseBucket.blob(f"results/result{expId}.csv") uploadBlob.upload_from_filename('results.csv') - if experimentOutput != '' or postProcess: + if trialExtraFile != '' or postProcess: print('Uploading Result Csvs') try: shutil.make_archive('ResultCsvs', 'zip', 'ResCsvs') diff --git a/apps/backend/modules/runner.py b/apps/backend/modules/runner.py index 35ca2ccd..d532b73a 100644 --- a/apps/backend/modules/runner.py +++ b/apps/backend/modules/runner.py @@ -14,16 +14,17 @@ OUTPUT_INDICATOR_USING_CSVS = "In ResCsvs" -def get_data(process: 'Popen[str]', trialRun: int): +def get_data(process: 'Popen[str]', trialRun: int, keepLogs: bool): try: data = process.communicate() - os.chdir('ResCsvs') - with open(f"log{trialRun}.txt", 'w', encoding='utf8') as f: - f.write(data[0]) - if data[1]: - f.write(data[1]) - f.close() - os.chdir('..') + if keepLogs: + os.chdir('ResCsvs') + with open(f"log{trialRun}.txt", 'w', encoding='utf8') as f: + f.write(data[0]) + if data[1]: + f.write(data[1]) + f.close() + os.chdir('..') print(data) if data[1]: print(f'errors returned from pipe is {data[1]}') @@ -36,14 +37,14 @@ def get_data(process: 'Popen[str]', trialRun: int): return result -def run_trial(experiment_path, config_path, filetype, trialRun: int): +def run_trial(experiment_path, config_path, filetype, trialRun: int, keepLogs: bool): #make sure that the cwd is ExperimentsFiles/{ExperimentId} if filetype == 'python': with Popen(['python', experiment_path, config_path], stdout=PIPE, stdin=PIPE, stderr=PIPE, encoding='utf8') as process: - return get_data(process, trialRun) + return get_data(process, trialRun, keepLogs) elif filetype == 'java': with Popen(['java', '-jar', experiment_path, config_path], stdout=PIPE, stdin=PIPE, stderr=PIPE, encoding='utf8') as process: - return get_data(process, trialRun) + return get_data(process, trialRun, keepLogs) def get_first_line_of_trial_results_csv(filename): @@ -76,7 +77,7 @@ def add_to_output_batch(fileOutput, ExpRun): raise FileHandlingError("Failed to copy results csv") from err -def conduct_experiment(expId, expRef, experimentOutput, resultOutput, filepath, filetype, numTrialsToRun): +def conduct_experiment(expId, expRef, trialExtraFile, trialResult, filepath, filetype, numTrialsToRun, keepLogs): print(f"Running Experiment {expId}") passes = 0 @@ -90,11 +91,11 @@ def conduct_experiment(expId, expRef, experimentOutput, resultOutput, filepath, expRef.update({"startedAtEpochMillis": int(startSeconds * 1000)}) try: print("Running the first trial...") - firstTrial = run_trial(filepath, f'configFiles/{0}.ini', filetype, 0) - if resultOutput == '': + firstTrial = run_trial(filepath, f'configFiles/{0}.ini', filetype, 0, keepLogs) + if trialResult == '': writer.writerow(["Experiment Run", "Result"] + paramNames) else: - if (output := get_first_line_of_trial_results_csv(resultOutput)) is None: + if (output := get_first_line_of_trial_results_csv(trialResult)) is None: raise InternalTrialFailedError("Nothing returned when trying to get header results (David, improve this error message please)") writer.writerow(["Experiment Run"] + output + paramNames) except Exception as err: @@ -122,31 +123,31 @@ def conduct_experiment(expId, expRef, experimentOutput, resultOutput, filepath, #Running the rest of the experiments print(f"Continuing now running {numTrialsToRun}") - if experimentOutput != '': - add_to_output_batch(experimentOutput, 0) + if trialExtraFile != '': + add_to_output_batch(trialExtraFile, 0) firstTrial = OUTPUT_INDICATOR_USING_CSVS - if resultOutput == '': + if trialResult == '': writer.writerow(["0", firstTrial] + get_configs_ordered(f'configFiles/{0}.ini', paramNames)) else: - if (output := get_output_results(resultOutput)) is None: + if (output := get_output_results(trialResult)) is None: raise InternalTrialFailedError("Nothing returned when trying to get first non-header line of results (the first run?) (David, improve this error message please)") writer.writerow(["0"] + output + get_configs_ordered(f'configFiles/{0}.ini', paramNames)) for i in range(1, numTrialsToRun + 1): try: - response_data = run_trial(filepath, f'configFiles/{i}.ini', filetype, i) + response_data = run_trial(filepath, f'configFiles/{i}.ini', filetype, i, keepLogs) except InternalTrialFailedError: print('The trial failed for some internal reason?') # TODO should this halt all further experiment runs? fails += 1 expRef.update({'fails': fails}) continue - if experimentOutput != '': + if trialExtraFile != '': response_data = OUTPUT_INDICATOR_USING_CSVS - add_to_output_batch(experimentOutput, i) - if resultOutput == '': + add_to_output_batch(trialExtraFile, i) + if trialResult == '': writer.writerow([i, response_data] + get_configs_ordered(f'configFiles/{i}.ini', paramNames)) else: - output = get_output_results(resultOutput) + output = get_output_results(trialResult) if output is None: raise InternalTrialFailedError("Nothing returned when trying to get first non-header line of results (the rest of the runs?) (David, improve this error message please)") writer.writerow([i] + output + get_configs_ordered(f'configFiles/{i}.ini', paramNames)) diff --git a/apps/frontend/components/NewExp.tsx b/apps/frontend/components/NewExp.tsx index ec459ce5..73e19156 100644 --- a/apps/frontend/components/NewExp.tsx +++ b/apps/frontend/components/NewExp.tsx @@ -66,8 +66,8 @@ const NewExp = ({ formState, setFormState, copyID, setCopyId, ...rest }) => { parameters: formList([] as any[]), // TODO type for parameters will remove the need for `any` here name: '', description: '', - fileOutput: '', - resultOutput: '', + trialExtraFile: '', + trialResult: '', scatterIndVar: '', scatterDepVar: '', dumbTextArea: '', @@ -90,8 +90,8 @@ const NewExp = ({ formState, setFormState, copyID, setCopyId, ...rest }) => { parameters: formList(params), name: expInfo['name'], description: expInfo['description'], - fileOutput: expInfo['fileOutput'], - resultOutput: expInfo['resultOutput'], + trialExtraFile: expInfo['trialExtraFile'], + trialResult: expInfo['trialResult'], verbose: expInfo['verbose'], nWorkers: expInfo['workers'], scatter: expInfo['scatter'], diff --git a/apps/frontend/components/stepComponents/InformationStep.tsx b/apps/frontend/components/stepComponents/InformationStep.tsx index 04d200aa..82e41391 100644 --- a/apps/frontend/components/stepComponents/InformationStep.tsx +++ b/apps/frontend/components/stepComponents/InformationStep.tsx @@ -25,22 +25,22 @@ export const InformationStep = ({ form, ...props }) => { - +
- +
diff --git a/apps/frontend/firebase/db.ts b/apps/frontend/firebase/db.ts index 06f0ad3f..08c98949 100644 --- a/apps/frontend/firebase/db.ts +++ b/apps/frontend/firebase/db.ts @@ -18,8 +18,8 @@ export const submitExperiment = async (values, userId) => { verbose: values.verbose, workers: values.nWorkers, expId: newExperiment.id, - fileOutput: values.fileOutput, - resultOutput: values.resultOutput, + trialExtraFile: values.trialExtraFile, + trialResult: values.trialResult, keepLogs: values.keepLogs, scatter: values.scatter, scatterIndVar: values.scatterIndVar, diff --git a/apps/frontend/pages/dashboard.tsx b/apps/frontend/pages/dashboard.tsx index 40a7f161..f67cf1de 100644 --- a/apps/frontend/pages/dashboard.tsx +++ b/apps/frontend/pages/dashboard.tsx @@ -198,7 +198,7 @@ const ExpLog = ({ projectinit, setFormState, setCopyId }) => { : null } - {project['finished'] == true && (project['fileOutput'] || project['scatter'] || project['keepLogs']) ? + {project['finished'] == true && (project['trialExtraFile'] || project['scatter'] || project['keepLogs']) ?