Skip to content

Commit

Permalink
Merge pull request #71 from AutomatingSciencePipeline/Convert-to-cons…
Browse files Browse the repository at this point in the history
…tant

Added constant conversion to the backend
  • Loading branch information
budak7273 authored Nov 11, 2022
2 parents daf2eca + 4538676 commit e0a5d9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
19 changes: 14 additions & 5 deletions apps/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def run_batch(data):
if firstRun == "ERROR":
writer.writerow([0,"Error"])
print("Experiment {id} ran into an error while running aborting")
else:
elif expToRun-1 >= 0:
print(f"result from running first experiment: {firstRun}\n Continuing now running {expToRun-1}")
writer.writerow(["0",firstRun] + get_configs_ordered(f'configFiles/{0}.ini',paramNames))
for i in range(1,expToRun):
Expand All @@ -84,7 +84,7 @@ def run_batch(data):
passes +=1
else:
fails +=1
print(f"Finished running Experiments")
print(f"Finished running Experiments")

#Uploading Experiment Results
print(f'Uploading Results to the frontend')
Expand Down Expand Up @@ -150,13 +150,21 @@ def gen_list(otherVar, paramspos):
elif otherVar['type'] == 'string':
paramspos.append([(otherVar['name'],otherVar['default'])])
elif otherVar['type'] == 'bool':
paramspos.append([(otherVar['name'],val) for val in [True,False]])
paramspos.append([(otherVar['name'],val) for val in [True,False]])

def gen_configs(hyperparams):
os.mkdir('configFiles')
os.chdir('configFiles')
configNum = 0
for defaultVar in hyperparams:
consts = {}
params = []
for param in hyperparams:
if (param['type'] =='integer' or param['type'] == 'float') and param['min'] == param['max']:
consts[param['name']] = param['min']
else:
params.append(param)

for defaultVar in params:
if defaultVar['type'] == 'string':
continue
paramspos = []
Expand All @@ -165,13 +173,14 @@ def gen_configs(hyperparams):
for otherVar in hyperparams:
if otherVar['name'] != defaultVar['name']:
gen_list(otherVar,paramspos)

perms = list(itertools.product(*paramspos))
for perm in perms:
config = configparser.ConfigParser()
res = {}
for var in perm:
res[var[0]] = var[1]
for var in consts.keys():
res[var] = consts[var]
config['DEFAULT'] = res
with open(f'{configNum}.ini', 'w') as configFile:
config.write(configFile)
Expand Down
14 changes: 9 additions & 5 deletions scripts/proof_of_concept/genetic_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import random
import copy
import sys
import configparser

#sample experiment that runs a truncation generational loop with a genome represented by a list of 0s and 1s. fitness is measured by number of 1s
#in genome. maximum fitness is measured at the given generation number.
Expand Down Expand Up @@ -62,13 +63,16 @@ def chromSort(chrom):
#main generational loop: for each loop, removes least fit half of chromosomes from population. The remaining chromosomes are duplicated to
#replace the population. every generation, every bit in the genome of every chromosome has a chance to mutate and flip from a 1 to a 0
def main():
config = configparser.ConfigParser()
args = sys.argv[1:]
configFile = args[0]
config.read(configFile)
#takes in 5 arguments: generations, population, genome length, mutation rate, and seed
generations = int(float(args[0]))
population = int(float(args[1]))
genomelength = int(float(args[2]))
mutationrate = float(args[3])
seed = int(float(args[4]))
generations = int(config["DEFAULT"]["g"])
population = int(config["DEFAULT"]["p"])
genomelength = int(config["DEFAULT"]["gl"])
mutationrate = float(config["DEFAULT"]["mr"])
seed = int(config["DEFAULT"]["s"])
random.seed(seed)
#generate initial population
chroms = generateChroms(population, genomelength)
Expand Down

0 comments on commit e0a5d9c

Please sign in to comment.