Commit 17eb5d37 by Mohcine Chraibi

Modify test 9

- Run same simulation with the same configuration (seed=const)
- Change for every iteration the number of threads
- Plot evacuation times vs number of threads
- Test fails if std(evacuation times) > 0
parent cc87deac
 ... @@ -3,8 +3,8 @@ ... @@ -3,8 +3,8 @@ linspace(1, 100000, 10) 1234 range(1,9) [1, 2, 4, 8, 16, 24] 900 900 ../geometry.xml ../geometry.xml ... @@ -45,7 +45,7 @@ ... @@ -45,7 +45,7 @@ ... ...
 # todo: spaghetti directory horror #!/usr/bin/env python """ Test description ================ - Fundamental Diagram in 2D, test number 102 - Width = 1.8 m - Length = 26.0 m - Measurement area: X = [10, 16], Y = [-0.9, 0.9] #! /usr/bin/env python Remarks import numpy as np ======= from xml.dom import minidom TODO: Compare two "clouds" of points and return a number. import os, argparse, logging, time from os import path, system from sys import argv ,exit import subprocess, glob import multiprocessing import matplotlib.pyplot as plt import re, sys #========================= testnr = 9 #======================== SUCCESS = 0 Source FAILURE = 1 ====== #-------------------------------------------------------- logfile="log_test_%d.txt"%testnr f=open(logfile, "w") f.close() logging.basicConfig(filename=logfile, level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') #-------------------- DIRS ------------------------------ """ HOME = path.expanduser("~") import os import sys import matplotlib.pyplot as plt import numpy as np utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0]))) from sys import * sys.path.append(utestdir) from JPSRunTest import JPSRunTestDriver from utils import * #TRUNK = HOME + "/Workspace/peddynamics/JuPedSim/jpscore" tolerance = 0.05 CWD = os.getcwd() ms = 20 # size of labels DIR = os.path.dirname(os.path.realpath(argv[0])) mt = 18 # size of ticks #TRUNK + "/Utest/test_%d"%testnr #-------------------------------------------------------- if __name__ == "__main__": if CWD != DIR: logging.info("working dir is %s. Change to %s"%(os.getcwd(), DIR)) os.chdir(DIR) logging.info("change directory to ..") os.chdir("../..") logging.info("call makeini.py with -f %s/master_ini.xml"%DIR) subprocess.call(["python", "makeini.py", "-f", "%s/master_ini.xml"%DIR]) os.chdir(DIR) #-------- get directory of the code TRUNK os.chdir("../..") lib_path = os.getcwd() sys.path.append(lib_path) from utils import * os.chdir("..") TRUNK = os.getcwd() os.chdir(DIR) #---------------------------------------- logging.info("change directory back to %s"%DIR) time1 = time.time() i = 0 flows = {} MAX_CPU = multiprocessing.cpu_count() geofile = "%s/geometry.xml"%DIR inifiles = glob.glob("inifiles/*.xml") logging.info("MAX CPU = %d"%MAX_CPU) if not path.exists(geofile): logging.critical("geofile <%s> does not exist"%geofile) exit(FAILURE) def eval_results(results): results = np.sort(results, axis=0) num_threads = results[:, 0] evac_times = results[:, 1] std = np.std(evac_times) mean = np.mean(evac_times) logging.info("INFO: mean = %f (+-%f)", mean, std) fig = plt.figure() ax = fig.add_subplot(1, 1, 1) plt.plot(num_threads, evac_times, "o-b", alpha=0.5) timedic = {} plt.ylabel(r"Evacuation Time [s]", size=ms) for inifile in inifiles: plt.xlabel(r"#Threads", size=ms) if not path.exists(inifile): plt.xlim([min(num_threads)-0.5, max(num_threads)+0.5]) logging.critical("inifile <%s> does not exist"%inifile) plt.xticks(fontsize=mt) exit(FAILURE) plt.xticks(num_threads, fontsize=mt) #--------------------- SIMULATION ------------------------ plt.title("mean = %f (+-%f) [s]" % (mean, std)) #os.chdir(TRUNK) #cd to the simulation directory plt.grid(alpha=0.7) executable = "%s/bin/jpscore"%TRUNK plt.savefig("evactimes.png", dpi=300) if not path.exists(executable): logging.critical("executable <%s> does not exist yet."%executable) exit(FAILURE) b = inifile.split("num_threads_")[1] ncpu = int( re.split("[.|_]", b)[0] ) cmd = "%s --inifile=%s"%(executable, inifile) logging.info('start simulating with exe=<%s>'%(cmd)) logging.info('n CPU = <%d>'%(ncpu)) #------------------------------------------------------ t1_run = time.time() subprocess.call([executable, "--inifile=%s"%inifile]) t2_run = time.time() if not timedic.has_key(ncpu): timedic[ncpu] = [t2_run - t1_run] else: timedic[ncpu].append(t2_run - t1_run) #------------------------------------------------------ logging.info('end simulation ...\n--------------\n') trajfile = "trajectories/traj" + inifile.split("ini")[2] logging.info('trajfile = <%s>'%trajfile) #--------------------- PARSING & FLOW-MEASUREMENT -------- if not path.exists(trajfile): logging.critical("trajfile <%s> does not exist"%trajfile) exit(FAILURE) fps, N, traj = parse_file(trajfile) J = flow(fps, N, traj, 61) if not flows.has_key(ncpu): flows[ncpu] = [J] else: flows[ncpu].append(J) #------------------------------------------------------------------------------ logging.debug("flows: (%s)"%', '.join(map(str, flows))) # ----------------------- PLOT RESULTS ---------------------- flow_file = "result.txt" times_file = "times.txt" ff = open(flow_file, "w") tt = open(times_file, "w") logging.info('write flow values in \"%s\" and times in \"%s\"'%(flow_file, times_file)) for key, value in flows.items(): print >>ff, key, ":", value for key, value in timedic.items(): def run_test_9(inifile, trajfile): print >>tt, key, ":", value maxtime = get_maxtime(inifile) num_threads = get_num_threads(inifile) fps, N, traj = parse_file(trajfile) if not N: logging.critical(" N = %d"%N) exit(FAILURE) evac_time = (max(traj[:, 1]) - min(traj[:, 1])) / float(fps) return (num_threads, evac_time) time2 = time.time() if __name__ == "__main__": M = np.array([np.mean(i) for i in flows.values()]) # std pro CPU test = JPSRunTestDriver(9, argv0=argv[0], MT = np.array([np.mean(i) for i in timedic.values()]) # std pro CPU testdir=sys.path[0], utestdir=utestdir) S = np.array([np.std(i) for i in flows.values()]) # std pro CPU results = test.run_test(testfunction=run_test_9) ST = np.array([np.std(i) for i in timedic.values()]) # std pro CPU eval_results(results) std_all = np.std(M) logging.info("%s exits with SUCCESS" % (argv[0])) exit(SUCCESS) print >>ff, "===========================" print >>ff, "===========================" print >>ff, "Means " print >>ff, M print >>ff, "===========================" print >>ff, "Std " print >>ff, S print >>ff, "===========================" print >>ff, "Std all " print >>ff, std_all print >>ff, "===========================" print >>ff, "===========================" ff.close() tt.close() ######################################################################### ms = 8 ax = plt.subplot(211) ax.plot(flows.keys(), M, "o-", lw=2, label='Mean', color='blue') ax.errorbar(flows.keys(), M, yerr=S, fmt='-o') #ax.fill_between(flows.keys(), M+S, M-S, facecolor='blue', alpha=0.5) #axes().set_aspect(1./axes().get_data_ratio()) #ax.legend(loc='best') ax.grid() ax.set_xlabel(r'# cores',fontsize=18) ax.set_ylabel(r'$J\; [\, \frac{1}{\rm{s}}\, ]$',fontsize=18) ax.set_xlim(0.5, MAX_CPU + 0.5) ax.set_xticks(flows.keys()) plt.title("# Simulations %d"%len(flows[ncpu])) #------------------ plot times ax2 = plt.subplot(212) ax2.plot(timedic.keys(), MT, "o-", lw=2, label='Mean', color='blue') ax2.errorbar(timedic.keys(), MT, yerr=ST, fmt='-o') ax2.set_xlabel(r'# cores',fontsize=18) ax2.set_ylabel(r'$T\; [ s ]$',fontsize=18) ax2.set_xticks(timedic.keys()) ax2.set_xlim(0.5, MAX_CPU + 0.5) ax2.set_ylim( min( MT ) - max(ST)-0.1 , max( MT ) + max(ST) +0.1) #ax.legend(loc='best') ax2.grid() plt.tight_layout() logging.info("save file in cpu.png") plt.savefig("cpu.png") #plt.show() ######################################################################### tolerance = 0.5# todo: this is to large 0.5 logging.info("time elapsed %.2f [s]."%(time2-time1)) logging.info("std_all = %.2f, tol=%.2f"%(std_all, tolerance)) if std_all > tolerance: logging.success("%s exits with FAILURE std_all = %f > %f"%(argv[0], std_all, tolerance)) exit(FAILURE) else: logging.info("%s exits with SUCCESS std_all = %f < %f"%(argv[0], std_all, tolerance)) exit(SUCCESS)
 ... @@ -114,7 +114,19 @@ def PassedLineY(p, exit): ... @@ -114,7 +114,19 @@ def PassedLineY(p, exit): x2 = exit[2] x2 = exit[2] return any(p[:, 3] <= y) & any(p[:, 3] >= y) & any(p[:, 2] >= x1) & any(p[:, 2] <= x2) return any(p[:, 3] <= y) & any(p[:, 3] >= y) & any(p[:, 2] >= x1) & any(p[:, 2] <= x2) def get_num_threads(filename): """ get num_threads """ logging.info("parsing <%s>"%filename) try: xmldoc = minidom.parse(filename) except: logging.critical('could not parse file %s. exit'%filename) exit(FAILURE) num_threads = float(xmldoc.getElementsByTagName('num_threads')[0].firstChild.nodeValue) return num_threads def get_maxtime(filename): def get_maxtime(filename): """ """ get max sim time get max sim time ... ...
 ... @@ -15,7 +15,7 @@ ... @@ -15,7 +15,7 @@ log log 8 24 ... @@ -47,7 +47,7 @@ ... @@ -47,7 +47,7 @@ ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!