### 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 @@ linspace(1, 100000, 10) range(1,9) 1234 [1, 2, 4, 8, 16, 24] 900 ../geometry.xml ... ... @@ -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 import numpy as np from xml.dom import minidom 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 #======================== Remarks ======= TODO: Compare two "clouds" of points and return a number. SUCCESS = 0 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') Source ====== #-------------------- 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))) from sys import * sys.path.append(utestdir) from JPSRunTest import JPSRunTestDriver from utils import * #TRUNK = HOME + "/Workspace/peddynamics/JuPedSim/jpscore" CWD = os.getcwd() DIR = os.path.dirname(os.path.realpath(argv)) #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) tolerance = 0.05 ms = 20 # size of labels mt = 18 # size of ticks 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 = {} for inifile in inifiles: if not path.exists(inifile): logging.critical("inifile <%s> does not exist"%inifile) exit(FAILURE) #--------------------- SIMULATION ------------------------ #os.chdir(TRUNK) #cd to the simulation directory executable = "%s/bin/jpscore"%TRUNK if not path.exists(executable): logging.critical("executable <%s> does not exist yet."%executable) exit(FAILURE) b = inifile.split("num_threads_") ncpu = int( re.split("[.|_]", b) ) 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") 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 plt.ylabel(r"Evacuation Time [s]", size=ms) plt.xlabel(r"#Threads", size=ms) plt.xlim([min(num_threads)-0.5, max(num_threads)+0.5]) plt.xticks(fontsize=mt) plt.xticks(num_threads, fontsize=mt) plt.title("mean = %f (+-%f) [s]" % (mean, std)) plt.grid(alpha=0.7) plt.savefig("evactimes.png", dpi=300) for key, value in timedic.items(): print >>tt, key, ":", value def run_test_9(inifile, trajfile): 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() M = np.array([np.mean(i) for i in flows.values()]) # std pro CPU MT = np.array([np.mean(i) for i in timedic.values()]) # std pro CPU if __name__ == "__main__": test = JPSRunTestDriver(9, argv0=argv, testdir=sys.path, utestdir=utestdir) S = np.array([np.std(i) for i in flows.values()]) # std pro CPU ST = np.array([np.std(i) for i in timedic.values()]) # std pro CPU std_all = np.std(M) 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, std_all, tolerance)) exit(FAILURE) else: logging.info("%s exits with SUCCESS std_all = %f < %f"%(argv, std_all, tolerance)) exit(SUCCESS) results = test.run_test(testfunction=run_test_9) eval_results(results) logging.info("%s exits with SUCCESS" % (argv)) exit(SUCCESS)
 ... ... @@ -114,7 +114,19 @@ def PassedLineY(p, exit): x2 = exit 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').firstChild.nodeValue) return num_threads def get_maxtime(filename): """ get max sim time ... ...
 ... ... @@ -15,7 +15,7 @@ log 8 24 ... ... @@ -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!
{"ft_lang_label":"__label__en","ft_lang_prob":0.65930367,"math_prob":0.8956696,"size":340,"snap":"2021-04-2021-17","text_gpt3_token_len":90,"char_repetition_ratio":0.122023806,"word_repetition_ratio":0.0,"special_character_ratio":0.25588235,"punctuation_ratio":0.01923077,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98846686,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-26T03:10:41Z\",\"WARC-Record-ID\":\"<urn:uuid:d26f426a-c6a3-4893-93c7-0dc0b4090a4d>\",\"Content-Length\":\"559229\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2be7645c-462e-4328-afad-c61d2467b09b>\",\"WARC-Concurrent-To\":\"<urn:uuid:b4a5a632-385b-4208-9b0c-530f9092feaf>\",\"WARC-IP-Address\":\"134.94.32.196\",\"WARC-Target-URI\":\"https://gitlab.version.fz-juelich.de/jupedsim/jpscore/-/commit/17eb5d376e1e828b36c2626ecebf8bd9f848e573\",\"WARC-Payload-Digest\":\"sha1:PXFCNZ3RALVHR6WTUK2K3ICF3LSSOK2Y\",\"WARC-Block-Digest\":\"sha1:ELJKE4E22DJGNTPSVXFCV275T2N7LAU4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610704795033.65_warc_CC-MAIN-20210126011645-20210126041645-00564.warc.gz\"}"}