Skip to content

Commit

Permalink
Merge pull request #247 from rheiland/new-build-test
Browse files Browse the repository at this point in the history
updated scripts to build, run, test all sample projects
  • Loading branch information
MathCancer authored Aug 28, 2024
2 parents 8558917 + a72777a commit 9ad7264
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 55 deletions.
55 changes: 0 additions & 55 deletions beta/test_build_all.sh

This file was deleted.

109 changes: 109 additions & 0 deletions beta/test_build_samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copy this file to the root dir and run it from a Unix bash shell: sh test_build_samples.sh
#
# WARNING: this is primarily intended to be used by core developers when testing a new release.
# It will create new directories in /user_projects
#
# This script is intended to serve as a first step in a two-step process. The second step is
# to run the beta/test_run_samples.py Python script (see its header for instructions).
#
#
# This test_build_samples.sh script is based on the following:
#
# $ make list-projects
# Sample projects: template biorobots-sample cancer-biorobots-sample cancer-immune-sample
# celltypes3-sample heterogeneity-sample pred-prey-farmer virus-macrophage-sample
# worm-sample interaction-sample mechano-sample rules-sample physimess-sample
#
# Note that it does not currently test building the intracellular projects:
# Sample intracellular projects: template_BM ode-energy-sample physiboss-cell-lines-sample
# cancer-metabolism-sample physiboss-tutorial physiboss-tutorial-invasion
#
# After running the script, you can:
# 1) confirm all executables were created
# $ ls -l template_sample biorobots cancer_biorobots cancer_immune_3D celltypes3 heterogeneity pred_prey virus_sample worm interaction_demo mechano_sample rules_sample physimess_sample
# and then:
# 2) confirm the user_projects were created; delete them
# $ cd user_projects
# $ ls
# $ rm -rf template biorobots cancer_biorobots cancer_immune celltypes3 hetero pred_prey virus_mac worm interaction mechano rules physimess

make reset
make template
make
mv project template_sample
make save PROJ=template
#
echo "\n-----------------------------------------"
make reset
make biorobots-sample
make
make save PROJ=biorobots
#
echo "\n-----------------------------------------"
make reset
make cancer-biorobots-sample
make
make save PROJ=cancer_biorobots
#
echo "\n-----------------------------------------"
make reset
make cancer-immune-sample
make
make save PROJ=cancer_immune
#
echo "\n-----------------------------------------"
make reset
make celltypes3-sample
make
make save PROJ=celltypes3
#
echo "\n-----------------------------------------"
make reset
make heterogeneity-sample
make
make save PROJ=hetero
#
echo "\n-----------------------------------------"
make reset
make pred-prey-farmer
make
make save PROJ=pred_prey
#
echo "\n-----------------------------------------"
make reset
make virus-macrophage-sample
make
make save PROJ=virus_mac
#
echo "\n-----------------------------------------"
make reset
make worm-sample
make
make save PROJ=worm
#
echo "\n-----------------------------------------"
make reset
make interaction-sample
make
make save PROJ=interaction
#
echo "\n-----------------------------------------"
make reset
make mechano-sample
make
mv project mechano_sample
make save PROJ=mechano
#
echo "\n-----------------------------------------"
make reset
make rules-sample
make
mv project rules_sample
make save PROJ=rules
#
echo "\n-----------------------------------------"
make reset
make physimess-sample
make
mv project physimess_sample
make save PROJ=physimess
78 changes: 78 additions & 0 deletions beta/test_diffs_svg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# compare diffs between .svg files in different runs
# e.g.,
# python beta/test_diffs_svg.py ~/git/new-build-test/samples_test ~/git/fix_constants/samples_test


import os
import sys
from pathlib import Path
import glob

# print(len(sys.argv))
if (len(sys.argv) < 3):
usage_str = "Usage: %s <dir1> <dir2>" % (sys.argv[0])
print(usage_str)
print("e.g.: python test_diffs_svg.py ~/blah1 ~/blah2")
exit(1)
else:
dir1 = sys.argv[1]
dir2 = sys.argv[2]


# svg_files = Path(dir1).glob(f'{dir1}/out_heterog/snap*.svg')
#print("svg_files=",svg_files)


#for filename in glob.iglob(f'{dir1}/snap*.svg'):

# output_biorobots/ output_interaction/ output_template/
# output_cancer_biorobots/ output_mechano/ output_virus_mac/
# output_cancer_immune/ output_physimess/ output_worm/
# output_celltypes3/ output_pred_prey/
# output_hetero/ output_rules/

# note that we omit 'output_physimess' only because, currently, it fails the recursive copy of
# additional files needed in config/subdirs (until the Makefiles and "make load PROJ" is updated)
for out_dir in ['output_template','output_biorobots','output_cancer_biorobots','output_celltypes3','output_heterog','output_interaction','output_mechano','output_pred_prey','output_virus_mac','output_worm','output_rules','output_cancer_immune']:
#for out_dir in ['out_template']:
print("---------- processing ",out_dir)
svg_files = glob.glob(f'{dir1}/{out_dir}/snap*.svg')
svg_files.sort()
for filename in svg_files:
f = os.path.basename(filename)
f1 = os.path.join(dir1,out_dir,f)
f2 = os.path.join(dir2,out_dir,f)
# print(f1,f2)
# cmd = f"diff {f1} {f2} | wc -l"
cmd = f"diff {f1} {f2} | wc -l > diff_result.txt"
print(cmd)
os.system(cmd)
with open('diff_result.txt') as f:
vstr = f.readline()
print(vstr)
# Note: a "diff" will almost certainly return 4 lines, showing different run times
# 1340c1340
# < 0 days, 0 hours, 1 minutes, and 12.1327 seconds
# ---
# > 0 days, 0 hours, 1 minutes, and 12.4215 seconds
if (int(vstr) == 0):
print("======----------------> WOW: exact match! (same sim time)")
# userinput = input("\nPress Enter to skip remaining files for this sample:")
# break
elif (int(vstr) != 4): # hard-coded "4"
print("======----------------> Warning: not a match!")
userinput = input("\nPress Enter to skip remaining files for this sample:")
# print("Username is: " + username)
break
# sys.exit(1)

# for fname in os.listdir(dir1):
# fname1 = os.path.join(dir1, fname)
# fname2 = os.path.join(dir2, fname)
# # checking if it is a file
# if os.path.isfile(f):
# print(f)

# cmd = "diff " + dir1 + "out_heterog" + " > " + log_file + " " + background_str
# print("----- cmd = ",cmd)
# # os.system(cmd) # <------ Execute the simulation
78 changes: 78 additions & 0 deletions beta/test_run_samples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# This Python script assumes you have run the beta/test_build_sample.sh script first.
# See its header for instructions.
#
# Copy this Python script from /beta to the root dir (in case you want to edit it), then run it
# It will do the following:
# - load each sample project (from user_projects; created by test_build_sample.sh)
# - compile it
# - modify each project's .xml: max_time, # threads, output folder
# - run it
#
# WARNING: this is primarily intended to be used by core developers when testing a new release.
# It will create new output directories ("output_<proj>")
#
# Run via:
# $ python beta/test_run_samples.py
# or, pipe the terminal output to a file:
# $ python beta/test_run_samples.py > test_run_samples.out
#
# Any serious error should show up in your terminal output. Some "errors" may be benign, e.g.,
# "Error: Could not find <cell_rules> section of XML config file"
#
# Reminder:
# $ ls user_projects/
# biorobots/ hetero/ pred_prey/ worm/
# cancer_biorobots/ interaction/ rules/
# cancer_immune/ mechano/ template/
# celltypes3/ physimess/ virus_mac/

# Sample projects: template biorobots-sample cancer-biorobots-sample cancer-immune-sample
# celltypes3-sample heterogeneity-sample pred-prey-farmer virus-macrophage-sample
# worm-sample interaction-sample mechano-sample rules-sample physimess-sample
#
# It does not currently test running the intracellular projects:
# Sample intracellular projects: template_BM ode-energy-sample physiboss-cell-lines-sample
# cancer-metabolism-sample physiboss-tutorial physiboss-tutorial-invasion
#
#
# If you want to cleanup the created execs:
# $ rm -rf template biorobots cancer_biorobots cancer_immune_3D celltypes3 hetero pred_prey virus_mac worm interaction mechano rules physimess

import subprocess
import xml.etree.ElementTree as ET
import os
import time

user_proj = ["template", "biorobots", "cancer_biorobots", "celltypes3", "hetero", "pred_prey", "virus_mac", "worm", "interaction", "mechano", "rules", "physimess", "cancer_immune"]

model_execs = ["project", "biorobots", "cancer_biorobots", "celltypes3", "heterogeneity", "pred_prey", "virus-sample", "worm", "interaction_demo", "project", "project", "project", "cancer_immune_3D"]

# Using dummy max_time values of 99 for many projects; 61 for the more time-consuming cancer_immune_3D.
# Users can change them as they wish.
max_times = [120, 10, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 61]

for (uproj, myexec, max_time) in zip(user_proj, model_execs, max_times):
print("\n\n------------ ",uproj,myexec, " ----------------------------------")
subprocess.run(["make","reset"])
# make load PROJ=template
s= "PROJ=" + uproj
print("\n ---- doing: make load ",s)
subprocess.run(["make","load",s])
subprocess.run(["make"])

# update max_time and omp_num_threads (=1)
tree = ET.parse('config/PhysiCell_settings.xml')
root = tree.getroot()
root.find(".//max_time").text = str(max_time)
root.find(".//omp_num_threads").text = "1"
new_output_dir = "output_" + uproj
root.find(".//save//folder").text = new_output_dir
tree.write('config/PhysiCell_settings.xml')
try:
os.makedirs(new_output_dir)
except:
pass
time.sleep(1)

subprocess.run([myexec])

0 comments on commit 9ad7264

Please sign in to comment.