Skip to content

Commit

Permalink
Implemented chi create functionality for command line
Browse files Browse the repository at this point in the history
  • Loading branch information
lamsoa729 committed Jan 2, 2024
1 parent 17ab91d commit 65daab2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
25 changes: 5 additions & 20 deletions chi_pet/chi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def read_opts(self):
self.opts.workdir = Path.cwd()

if not self.opts.states and self.opts.args_file:
yd = clib.create_dict_from_yaml_file(self.opts.args_file)
self.opts.states = list(yd.keys())
with self.opts.args_file.open('r') as af:
yd = clib.load_yaml_in_order(af)
self.opts.states = list(yd.keys())

def execute(self):
if self.opts.command == "launch":
Expand All @@ -58,24 +59,8 @@ def execute(self):

elif self.opts.command == 'create':
# TODO NEXT implement this functionality
pass
# run_not_path.touch()
# # touch(os.path.join(wd, "run.not"))
# chi_root_node = ChiNode(self.opts)
# chi_root_node.Grow()

# c = ChiCreate(self.opts, self.opts.workdir)
# c.Create(self.opts.create)

# elif self.opts.particleswarmcreate:
# pass
# # c = ChiParticleSwarm(self.opts, self.opts.workdir, 0)
# # c.Create(self.opts.particleswarmcreate)

# elif self.opts.geneticalgorithmcreate:
# pass
# # c = ChiGeneticAlgorithm(self.opts, self.opts.workdir, 0)
# # c.Create(self.opts.geneticalgorithmcreate)
chi_root_node = ChiNode(self.opts.workdir, opts=self.opts)
chi_root_node.make_subnodes()

elif self.opts.command == 'run':
pass
Expand Down
4 changes: 2 additions & 2 deletions chi_pet/chi_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def __init__(self, node_path: Path,
if chi_dict:
self._chi_dict = chi_dict
else:
if not self._opts.param_file_paths:
if not self._opts.param_files:
raise RuntimeError(
"If a ChiDict is not supplied, a params_file_path list must be supplied instead.")
self._chi_dict = ChiDict(
file_path_list=self._opts.param_file_paths)
file_path_list=self._opts.param_files)

self._chi_params = self._chi_dict.search_dict_for_chi_params()
self._level = level if len(self._chi_params) == 0 else min(
Expand Down
2 changes: 0 additions & 2 deletions chi_pet/chi_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from pathlib import Path

# TODO NTEST add parser test


def parse_chi_options():
parent_parser = argparse.ArgumentParser(add_help=False)
Expand Down
17 changes: 10 additions & 7 deletions chi_pet/chi_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ def run(self, opts):
args_dict = load_yaml_in_order(f)

print(dump_yaml_in_order(args_dict, default_flow_style=False))
for k, vals in args_dict.items():

# 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():
args = [str(a) for a in vals]
sim_action = Path('sim.{}'.format(k))
sim_action = Path('sim.{}'.format(run_state))

if k in opts.states:
if self.run_args(opts.workdir, k, args):
# If sim action file exists then run the state
if run_state in opts.states:
if self.run_args(opts.workdir, run_state, args):
(opts.workdir / '.error').touch()
elif sim_action.exists():
sim_action.unlink()
Expand All @@ -86,8 +90,7 @@ def run_args(workdir, state, args):


if __name__ == '__main__':

opts = chi_parse()
opts = parse_chi_options()

c = ChiRun(opts)
c.Run(opts)
c.execute(opts)
14 changes: 14 additions & 0 deletions tests/node_tree_example/args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
setup:
- init_test_prog.py
- --argA
- argA_value
- --argB
- 1

run:
- test_prog.py
- --arg1
- arg1_value

analyze:
- test_analyze.py
1 change: 0 additions & 1 deletion tests/test_chi_parse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Tests for `chi_pet` package."""

import argparse
from pathlib import Path
import pytest
import sys
Expand Down
7 changes: 7 additions & 0 deletions tests/test_chi_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
"""Tests for `chi_run` module of `chi_pet` package."""

from pathlib import Path
import pytest

# TODO NTEST add tests for chi_run.py

0 comments on commit 65daab2

Please sign in to comment.