Skip to content

Commit

Permalink
refactor(#317): Better design
Browse files Browse the repository at this point in the history
- Get all ARgoS integration tests to pass again, and then cleanup static analysis
  • Loading branch information
jharwell committed Oct 24, 2024
1 parent 87e5dbb commit b5b7724
Show file tree
Hide file tree
Showing 29 changed files with 379 additions and 136 deletions.
9 changes: 5 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def analyze_pytype(session):
session.run('pytype',
f'-j {cores}',
'-k',
'-d name-error,attribute-error,invalid-annotation,pyi-error',
'-d name-error,attribute-error,pyi-error',
'sierra',
external=True)

Expand All @@ -74,8 +74,6 @@ def analyze_mypy(session):
session.install('.') # same as 'pip3 install .'
session.install('.[devel]') # same as 'pip3 install .[devel]'

cores = psutil.cpu_count()

session.run('mypyrun',
'--select',
# No syntax errors
Expand Down Expand Up @@ -109,7 +107,10 @@ def analyze_mypy(session):
'name-match',
'no-untype-def',
'redundant-cast',
'no-untyped-call'
'disallow-untyped-calls',
'check-untyped-defs',
'disallow-untyped-defs',
'disallow-incomplete-defs'

# List types
'list-item',
Expand Down
109 changes: 97 additions & 12 deletions scripts/argos-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ setup_env() {
# between jobs in a workflow on OSX, and doing this the way
# github says to do doesn't work.
export PATH=$pythonLocation/bin:$PATH

# Required to get coverage.py to work with the installed version
# of SIERRA. Omitting this results in either nothing getting
# measured because the local site-packages is omitted, or if that
Expand Down Expand Up @@ -186,7 +186,15 @@ bc_bivar_sanity_test() {
# Check that stage 1 outputs what it is supposed to
################################################################################
stage1_univar_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"
batch_root=$(python3 -c "${batch_root_cmd}")

input_root=$batch_root/exp-inputs/
rm -rf $SIERRA_ROOT
Expand Down Expand Up @@ -219,11 +227,28 @@ stage1_univar_test() {
}

stage1_bivar_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\",\"max_speed.1.9.C5\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd1="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\",\"max_speed.1.9.C5\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"
batch_root_cmd2="from sierra.core import batchroot;
bc=[\"max_speed.1.9.C5\",\"population_size.Linear3.C3\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"

batch_root1=$(python3 -c "${batch_root_cmd1}")

input_root1=$batch_root1/exp-inputs/

batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"max_speed.1.9.C5\",\"population_size.Linear3.C3\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root2=$(python3 -c"${batch_root_cmd2}")

input_root2=$batch_root2/exp-inputs/

Expand Down Expand Up @@ -298,7 +323,16 @@ stage1_bivar_test() {
# Check that stage 2 outputs what it is supposed to
################################################################################
stage2_univar_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"

batch_root=$(python3 -c"${batch_root_cmd}")

output_root=$batch_root/exp-outputs/
scratch_root=$batch_root/scratch/
Expand Down Expand Up @@ -375,7 +409,15 @@ stage2_univar_check_outputs() {
}

stage2_bivar_test() {
batch_root1=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\",\"max_speed.1.9.C5\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd1="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\", \"max_speed.1.9.C5\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"
batch_root1=$(python3 -c"${batch_root_cmd1}")

output_root1=$batch_root1/exp-outputs/

Expand Down Expand Up @@ -410,7 +452,15 @@ stage2_bivar_test() {
# Check that stage 3 outputs what it is supposed to
################################################################################
stage3_univar_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"
batch_root=$(python3 -c"${batch_root_cmd}")

stat_root=$batch_root/statistics
rm -rf $SIERRA_ROOT
Expand Down Expand Up @@ -460,7 +510,16 @@ stage3_univar_check_outputs() {
}

stage3_bivar_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\",\"max_speed.1.9.C5\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd1="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\", \"max_speed.1.9.C5\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"

batch_root=$(python3 -c"${batch_root_cmd1}")

output_root=$batch_root1/exp-outputs/

Expand Down Expand Up @@ -533,7 +592,15 @@ stage4_univar_test() {
--physics-n-engines=1 \
--batch-criteria ${bc}\
--pipeline 1 2 3 4"
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"${bc}\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"${bc}\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"
batch_root=$(python3 -c"${batch_root_cmd}")

graph_root=$batch_root/graphs

Expand Down Expand Up @@ -755,7 +822,16 @@ stage5_bivar_check_cc_outputs() {
# Visual capture test
################################################################################
vc_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\", \"template\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"

batch_root=$(python3 -c"${batch_root_cmd}")

output_root=$batch_root/exp-outputs
video_root=$batch_root/videos
Expand Down Expand Up @@ -798,7 +874,16 @@ vc_test() {
# Cmdline test
################################################################################
cmdline_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"argos_project\",[\"population_size.Linear3.C3\"],\"LowBlockCount.10x10x2\",\"foraging.footbot_foraging\",\"template\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"template\";
scenario=\"LowBlockCount.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"argos_project\",controller=\"foraging.footbot_foraging\",leaf=leaf).to_path();
print(path)
"

batch_root=$(python3 -c"${batch_root_cmd}")

input_root=$batch_root/exp-inputs
rm -rf $SIERRA_ROOT
Expand All @@ -810,7 +895,7 @@ cmdline_test() {
--exp-setup=exp_setup.T50"


$SIERRA_CMD --n-robots=10 --pipeline 1
$SIERRA_CMD --n-agents=10 --pipeline 1

for exp in {0..2}; do
for run in {0..3}; do
Expand Down
10 changes: 9 additions & 1 deletion scripts/core-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ setup_env() {
# Check usage of environment variables
################################################################################
env_vars_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"ros1robot_project\",[\"population_size.Linear3.C3\"],\"OutdoorWorld.10x10x2\",\"turtlebot3.wander\", \"turtlebot3\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"turtlebot3\";
scenario=\"OutdoorWorld.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"ros1robot_project\",controller=\"turtlebot3.wander\",leaf=leaf).to_path();
print(path)
"
batch_root=$(python3 -c"${batch_root_cmd}")

input_root=$batch_root/exp-inputs/
rm -rf $SIERRA_ROOT
Expand Down
42 changes: 38 additions & 4 deletions scripts/ros1gazebo-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ bc_bivar_sanity_test() {
# Check that stage 1 outputs what it is supposed to
################################################################################
stage1_univar_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"ros1gazebo_project\",[\"population_size.Linear3.C3\"],\"HouseWorld.10x10x2\",\"turtlebot3.wander\", \"turtlebot3_house\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"turtlebot3_house\";
scenario=\"HouseWorld.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"ros1gazebo_project\",controller=\"turtlebot3.wander\",leaf=leaf).to_path();
print(path)
"

batch_root=$(python3 -c"${batch_root_cmd}")

input_root=$batch_root/exp-inputs/
rm -rf $SIERRA_ROOT
Expand Down Expand Up @@ -125,11 +134,27 @@ stage1_univar_test() {
}

stage1_bivar_test() {
batch_root1=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"ros1gazebo_project\",[\"population_size.Linear3.C3\",\"max_speed.1.9.C5\"],\"HouseWorld.10x10x2\",\"turtlebot3.wander\", \"turtlebot3_house\").to_path())")
batch_root_cmd1="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\",\"max_speed.1.9.C5\"];
template_stem=\"turtlebot3_house\";
scenario=\"HouseWorld.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"ros1gazebo_project\",controller=\"turtlebot3.wander\",leaf=leaf).to_path();
print(path)
"
batch_root_cmd2="from sierra.core import batchroot;
bc=[\"max_speed.1.9.C5\",\"population_size.Linear3.C3\"];
template_stem=\"turtlebot3_house\";
scenario=\"HouseWorld.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"ros1gazebo_project\",controller=\"turtlebot3.wander\",leaf=leaf).to_path();
print(path)
"
batch_root1=$(python3 -c"${batch_root_cmd1}")

input_root1=$batch_root1/exp-inputs/

batch_root1=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"ros1gazebo_project\",[\"max_speed.1.9.C5\",\"population_size.Linear3.C3\"],\"HouseWorld.10x10x2\",\"turtlebot3.wander\", \"turtlebot3_house\").to_path())")
batch_root2=$(python3 -c"${batch_root_cmd2}")

input_root2=$batch_root2/exp-inputs/

Expand Down Expand Up @@ -197,7 +222,16 @@ stage1_bivar_test() {
# Check that stage 2 works for all exec envs
################################################################################
stage2_univar_test() {
batch_root=$(python3 -c"import sierra.core.root_dirpath_generator as rdg;print(rdg.gen_batch_root(\"$SIERRA_ROOT\",\"ros1gazebo_project\",[\"population_size.Linear3.C3\"],\"HouseWorld.10x10x2\",\"turtlebot3.wander\", \"turtlebot3_house\"))")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"turtlebot3_house\";
scenario=\"HouseWorld.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"ros1gazebo_project\",controller=\"turtlebot3.wander\",leaf=leaf).to_path();
print(path)
"

batch_root=$(python3 -c"${batch_root_cmd}")

scratch_root=$batch_root/scratch/

Expand Down
11 changes: 10 additions & 1 deletion scripts/ros1robot-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@ bc_univar_sanity_test() {
# Check that stage 1 outputs what it is supposed to
################################################################################
stage1_test() {
batch_root=$(python3 -c"from sierra.core.batchroot import batchroot;print(batchroot.ExpRoot(\"$SIERRA_ROOT\",\"ros1gazebo_project\",[\"population_size.Linear3.C3\"],\"OutdoorWorld.10x10x2\",\"turtlebot3.wander\", \"turtlebot3\").to_path())")
batch_root_cmd="from sierra.core import batchroot;
bc=[\"population_size.Linear3.C3\"];
template_stem=\"turtlebot3\";
scenario=\"OutdoorWorld.10x10x2\";
leaf=batchroot.ExpRootLeaf(bc=bc,template_stem=template_stem,scenario=scenario);
path=batchroot.ExpRoot(sierra_root=\"$SIERRA_ROOT\",project=\"ros1robot_project\",controller=\"turtlebot3.wander\",leaf=leaf).to_path();
print(path)
"

batch_root=$(python3 -c"${batch_root_cmd}")

input_root=$batch_root/exp-inputs/
rm -rf $SIERRA_ROOT
Expand Down
39 changes: 30 additions & 9 deletions sierra/core/batchroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@ def from_components(bc: tp.List[str],
scenario: str) -> 'ExpRootLeaf':
return ExpRootLeaf(bc, template_stem, scenario)

def __init__(self, bc: tp.List[str],
def __init__(self,
bc: tp.List[str],
template_stem: str,
scenario: str) -> None:
self.bc = bc
self.template_stem = template_stem
self.scenario = scenario

def to_path(self) -> pathlib.Path:
root = pathlib.Path(f"{0}-{1}+{2}" % (self.template_stem,
self.scenario,
'+'.join(self.bc)))
logging.debug("Generated batch leaf %s", root)
root = pathlib.Path("{0}-{1}+{2}".format(
self.template_stem,
self.scenario,
'+'.join(self.bc)))
logging.trace("Generated batch leaf %s", root.as_posix())
return root

def to_str(self) -> str:
return str(self.to_path())


class ExpRoot():
def __init__(self,
Expand Down Expand Up @@ -91,6 +96,9 @@ def __init__(self,
def to_path(self) -> pathlib.Path:
return self.sierra_root / self.project / self.controller / self.leaf.to_path()

def to_str(self) -> str:
return str(self.to_path())


class PathSet():
def __init__(self, root: ExpRoot) -> None:
Expand All @@ -99,14 +107,27 @@ def __init__(self, root: ExpRoot) -> None:
self.graph_root = root.to_path() / "graphs"
self.model_root = root.to_path() / "models"
self.stat_root = root.to_path() / "statistics"
self.stat_exec_root = self.stat_root.to_path() / "exec"
self.stat_exec_root = self.stat_root / "exec"
self.imagize_root = root.to_path() / "imagize"
self.video_root = root.to_path() / "videos"
self.stat_collate_root = self.stat_root.to_path() / "collated"
self.graph_collate_root = self.graph_root.to_path() / "collated"
self.stat_collate_root = self.stat_root / "collated"
self.graph_collate_root = self.graph_root / "collated"
self.scratch_root = root.to_path() / "scratch"
self.root = root.to_path()

def __str__(self) -> str:
return (f"Batch root: {self.root}\n" +
f"Input root: <batch root>/{self.input_root.name}\n" +
f"Output root: <batch root>/{self.output_root.name}\n" +
f"Graph root: <batch root>/{self.graph_root.name}\n" +
f"Model root: <batch root>/{self.model_root.name}\n" +
f"Statistics root: <batch root>/{self.stat_root.name}\n" +
f"Execution statistics root: <batch root>/{self.stat_exec_root.name}\n" +
f"Imagizing root: <batch root>/{self.imagize_root.name}\n" +
f"Video root: <batch root>/{self.video_root.name}\n" +
f"Statistics collate root: <batch root>/{self.stat_collate_root.name}\n" +
f"Experiment scratch root: <batch root>/{self.scratch_root.name}")


def from_cmdline(args: argparse.Namespace) -> PathSet:
"""Generate directory paths directly from cmdline arguments.
Expand Down Expand Up @@ -154,5 +175,5 @@ def from_exp(sierra_root: str,
project,
controller,
batch_leaf)
logging.info('Generated batch root %s', root)
logging.info('Generated batch root %s', root.to_path())
return PathSet(root)
Loading

0 comments on commit b5b7724

Please sign in to comment.