Skip to content

Commit

Permalink
Removed unnecessary todos and update chi_run
Browse files Browse the repository at this point in the history
  • Loading branch information
lamsoa729 committed Jan 4, 2024
1 parent 65daab2 commit 9307fc0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 45 deletions.
2 changes: 1 addition & 1 deletion chi_pet/analysis/graph_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def sci_notation_latex(num_str, sig_figs=4, d_range=0, **kwargs):
@param num_str: string of a number in exponential form
@param sig_figs: The number of significant figures
@param d_range: The exponent range before applying scientific notation.
@param **kwargs: TODO
@param **kwargs:
@return: latex string
"""
Expand Down
24 changes: 12 additions & 12 deletions chi_pet/chi.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ def read_opts(self):
self.opts.states = list(yd.keys())

def execute(self):
if self.opts.command == "launch":

if self.opts.command == 'create':
chi_root_node = ChiNode(self.opts.workdir, opts=self.opts)
chi_root_node.make_subnodes()

elif self.opts.command == 'run':
pass
c = ChiRun(self.opts)
c.run(self.opts)

elif self.opts.command == "launch":
# # If no sim dirs are given find them all in simulations
# if self.opts.launch == []:
# self.opts.launch = clib.find_dirs(wd / "simulations")
Expand All @@ -57,18 +67,8 @@ def execute(self):
# running_path.touch()
pass

elif self.opts.command == 'create':
# TODO NEXT implement this functionality
chi_root_node = ChiNode(self.opts.workdir, opts=self.opts)
chi_root_node.make_subnodes()

elif self.opts.command == 'run':
elif self.opts.prep:
pass
c = ChiRun(self.opts)
c.Run(self.opts)

# elif self.opts.prep:
# pass
# # leaf_lst = clib.find_leaf_dirs(self.opts.workdir)
# # for leaf_dir in leaf_lst:
# # if self.opts.args_file:
Expand Down
6 changes: 5 additions & 1 deletion chi_pet/chi_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def parse_chi_options():
parent_parser.add_argument('-a', '--args_file', type=Path,
help='Name file that holds the program argument list. (Used with --create option and --launch option)')
parent_parser.add_argument('-d', '--workdir', type=Path,
help='Name of the working directory where simulation will be run. Used with --run option only)')
help='Name of the working directory where simulation will be created or run.')
parent_parser.add_argument('-s', '--states', nargs='+', type=str,
help='Name of all the states the simulation will run eg. start, build, analyze, etc.')

Expand All @@ -32,6 +32,10 @@ def parse_chi_options():
parser.add_argument('-rm', '--remove', nargs='+', metavar='FILE(s)', type=Path,
help='Removes FILEs from seed directories.')

# TODO add clean functionality
parser.add_argument('-C', '--clean', action='store_true',
help='Remove subnode and data directory files from current work directory.')

subparsers = parser.add_subparsers(dest='command')

# CREATE options
Expand Down
39 changes: 26 additions & 13 deletions chi_pet/chi_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,39 @@ def run_args(workdir, state, args):

class ChiRun(object):
def __init__(self, opts):
self.opts = opts
self._opts = opts

def run(self, opts):
workdir_path = Path(opts.workdir)
args_file_path = workdir_path / opts.args_file
if not workdir_path.exists():
def run(self):
"""Run simulation pipeline defined in the the args.yaml file defined as self.opts.args_file.
Parameters
----------
opts : _type_
_description_
Raises
------
FileNotFoundError
_description_
FileNotFoundError
_description_
"""

# TODO NEXT Make these more useful for running simulations
if not self._opts.workdir.exists():
raise FileNotFoundError(
"Run failed. Directory {} does not exists.".format(
opts.workdir))
self._opts.workdir))

elif not args_file_path.exists():
elif not self._opts._args_file.exists():
raise FileNotFoundError(
"Run failed. args.yaml file not found in {}.".format(
opts.workdir))
"Run failed. args.yaml file not found in {self._opts.workdir}.".format(
))
else:
with args_file_path.open('r') as f:
with self._opts.args_file.open('r') as f:
args_dict = load_yaml_in_order(f)

print(dump_yaml_in_order(args_dict, default_flow_style=False))

# print(dump_yaml_in_order(args_dict, default_flow_style=False))
# Loop through all states in args.yaml.
# TODO Add option to see if sim_action file exists and only run those states.
for run_state, vals in args_dict.items():
Expand Down Expand Up @@ -93,4 +106,4 @@ def run_args(workdir, state, args):
opts = parse_chi_options()

c = ChiRun(opts)
c.execute(opts)
c.run(opts)
32 changes: 15 additions & 17 deletions chi_pet/old/ChiParams.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def UpdateParamValues(self):
def UpdateShotgunParamValues(self):
for cparam in self.chiparams:
if cparam.values:
# TODO If two param value lists are different,
# choose the smaller one.
if self.opts.n != cparam.GetNValues():
print("## Number of values of in {0}({1}) \
does not match nvars given({2}). Setting nvars to {1}.".format(
Expand Down Expand Up @@ -212,7 +210,7 @@ def MakeSimDirectoryDatabase(self, run_dir, gen, ind_lst=[]):
sim_values += str(p[i]) + " "
sim_name += p.format(p[i]) + "_"

#sim_name = sim_name[:-1] + str(random.uniform(0.0, 1.0))
# sim_name = sim_name[:-1] + str(random.uniform(0.0, 1.0))
sim_name = sim_name[:-1]
sim_values = sim_values[:-1]
# print "sim_values: {}".format(sim_values)
Expand Down Expand Up @@ -367,23 +365,23 @@ def UpdateFitness(self, sim_dir, dotest=False):
with open(data_file_path, 'r') as stream:
fitness_yaml = yaml.load(stream)
# Compile fitness information
#em_fitness = 0.0
#length_correlation_avg = 0.0
#fbiorientation = 0.0
#kinetochore_fitness = 0.0
# em_fitness = 0.0
# length_correlation_avg = 0.0
# fbiorientation = 0.0
# kinetochore_fitness = 0.0

# Get the EM and length correlation fitness information
#em_fitness = (fitness_yaml['short'] + fitness_yaml['med'] + fitness_yaml['long'])/3.
#length_correlation_avg = fitness_yaml['length_correlation_avg']
# em_fitness = (fitness_yaml['short'] + fitness_yaml['med'] + fitness_yaml['long'])/3.
# length_correlation_avg = fitness_yaml['length_correlation_avg']

# Get the chromosome fitness information, base it off chromosome seconds fraction key
# if 'chromosome_seconds_fraction' in fitness_yaml:
# fbiorientation = fitness_yaml['fbiorientation']
# kinetochore_fitness = np.mean([fitness_yaml['chromosome_kc_spb_distance'], fitness_yaml['chromosome_kc_spindle1d']])

# Combine total fitness in our special way
#total_fitness = em_fitness + 2.0*length_correlation_avg + 2.0*fbiorientation + kinetochore_fitness
#self.fitness[idx] = total_fitness
# total_fitness = em_fitness + 2.0*length_correlation_avg + 2.0*fbiorientation + kinetochore_fitness
# self.fitness[idx] = total_fitness

# Get what SpindleAnalysis thinks is the total fitness
total_fitness = fitness_yaml['FINAL_FITNESS']
Expand Down Expand Up @@ -553,7 +551,7 @@ def UpdateGeneticsRoulette(self):
# Roulette wheel selection of the available parameters
value1 = random.uniform(0.0, 1.0) * self.weight_sum1
parent1_idx = -1
#cur_value1 = self.min_fitness
# cur_value1 = self.min_fitness
for i in range(self.nparticles):
value1 -= (self.fitness[i] - self.min_genetics)
if value1 <= 0.0:
Expand Down Expand Up @@ -587,10 +585,10 @@ def UpdateGeneticsRoulette(self):

# Two point crossover
# Two point crossover
#self.parents[cidx1] = [parent1_idx, parent2_idx]
#self.parents[cidx2] = [parent1_idx, parent2_idx]
#cp1 = int(random.uniform(0, len(self.chiparams)))
#cp2 = int(random.uniform(0, len(self.chiparams)))
# self.parents[cidx1] = [parent1_idx, parent2_idx]
# self.parents[cidx2] = [parent1_idx, parent2_idx]
# cp1 = int(random.uniform(0, len(self.chiparams)))
# cp2 = int(random.uniform(0, len(self.chiparams)))
# if cp2 < cp1:
# temp = cp1
# cp1 = cp2
Expand Down Expand Up @@ -703,7 +701,7 @@ def PrintSwarmBest(self):
str2 += " {} ".format(self.gbest_better)
print(str2)

#str3 = "{} {} ".format("gfull", self.gbest)
# str3 = "{} {} ".format("gfull", self.gbest)
# for ichi in xrange(len(self.chiparams)):
# str3 += " {} ".format(self.gbestx[ichi].values[self.gbestid])
# print str3
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RUN apt update && \
RUN git clone --recursive https://github.com/lamsoa729/chi_pet.git /root/chi_pet && \
pip install -e /root/chi_pet

# TODO add continuous integration



0 comments on commit 9307fc0

Please sign in to comment.