Commit 17eb5d37 authored by Mohcine Chraibi's avatar 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 @@
<JuPedSim project="JPS-Project" version="0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ini.xsd"> <JuPedSim project="JPS-Project" version="0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ini.xsd">
<!-- seed used for initialising random generator --> <!-- seed used for initialising random generator -->
<seed>linspace(1, 100000, 10)</seed> <seed>1234</seed>
<num_threads>range(1,9)</num_threads> <num_threads>[1, 2, 4, 8, 16, 24]</num_threads>
<max_sim_time unit="sec">900</max_sim_time> <max_sim_time unit="sec">900</max_sim_time>
<!-- geometry file --> <!-- geometry file -->
<geometry>../geometry.xml</geometry> <geometry>../geometry.xml</geometry>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<!--persons information and distribution --> <!--persons information and distribution -->
<agents operational_model_id="3"> <agents operational_model_id="3">
<agents_distribution> <agents_distribution>
<group group_id="2" agent_parameter_id="0" room_id="1" subroom_id="0" number="100" goal_id="0" router_id="1" route_id=""/> <group group_id="2" agent_parameter_id="0" room_id="1" subroom_id="0" number="40" goal_id="0" router_id="1" route_id=""/>
</agents_distribution> </agents_distribution>
<!-- frequency in persons/minute --> <!-- frequency in persons/minute -->
......
# todo: spaghetti directory horror #!/usr/bin/env python
"""
#! /usr/bin/env python Test description
import numpy as np ================
from xml.dom import minidom - Fundamental Diagram in 2D, test number 102
import os, argparse, logging, time - Width = 1.8 m
from os import path, system - Length = 26.0 m
from sys import argv ,exit - Measurement area: X = [10, 16], Y = [-0.9, 0.9]
import subprocess, glob
import multiprocessing Remarks
=======
TODO: Compare two "clouds" of points and return a number.
Source
======
"""
import os
import sys
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import re, sys import numpy as np
utestdir = os.path.abspath(os.path.dirname(os.path.dirname(sys.path[0])))
#========================= from sys import *
testnr = 9 sys.path.append(utestdir)
#======================== from JPSRunTest import JPSRunTestDriver
from utils import *
SUCCESS = 0
FAILURE = 1 tolerance = 0.05
#-------------------------------------------------------- ms = 20 # size of labels
logfile="log_test_%d.txt"%testnr mt = 18 # size of ticks
f=open(logfile, "w")
f.close() def eval_results(results):
logging.basicConfig(filename=logfile, level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') results = np.sort(results, axis=0)
num_threads = results[:, 0]
#-------------------- DIRS ------------------------------ evac_times = results[:, 1]
HOME = path.expanduser("~") std = np.std(evac_times)
mean = np.mean(evac_times)
logging.info("INFO: mean = %f (+-%f)", mean, std)
#TRUNK = HOME + "/Workspace/peddynamics/JuPedSim/jpscore" fig = plt.figure()
CWD = os.getcwd() ax = fig.add_subplot(1, 1, 1)
DIR = os.path.dirname(os.path.realpath(argv[0])) plt.plot(num_threads, evac_times, "o-b", alpha=0.5)
#TRUNK + "/Utest/test_%d"%testnr
#-------------------------------------------------------- plt.ylabel(r"Evacuation Time [s]", size=ms)
plt.xlabel(r"#Threads", size=ms)
if __name__ == "__main__": plt.xlim([min(num_threads)-0.5, max(num_threads)+0.5])
if CWD != DIR: plt.xticks(fontsize=mt)
logging.info("working dir is %s. Change to %s"%(os.getcwd(), DIR)) plt.xticks(num_threads, fontsize=mt)
os.chdir(DIR) plt.title("mean = %f (+-%f) [s]" % (mean, std))
plt.grid(alpha=0.7)
logging.info("change directory to ..") plt.savefig("evactimes.png", dpi=300)
os.chdir("../..")
logging.info("call makeini.py with -f %s/master_ini.xml"%DIR) def run_test_9(inifile, trajfile):
subprocess.call(["python", "makeini.py", "-f", "%s/master_ini.xml"%DIR]) maxtime = get_maxtime(inifile)
os.chdir(DIR) num_threads = get_num_threads(inifile)
#-------- 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)
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_")[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) fps, N, traj = parse_file(trajfile)
J = flow(fps, N, traj, 61) if not N:
logging.critical(" N = %d"%N)
if not flows.has_key(ncpu): exit(FAILURE)
flows[ncpu] = [J] evac_time = (max(traj[:, 1]) - min(traj[:, 1])) / float(fps)
else: return (num_threads, evac_time)
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():
print >>tt, key, ":", value
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
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() if __name__ == "__main__":
tt.close() test = JPSRunTestDriver(9, argv0=argv[0],
######################################################################### testdir=sys.path[0],
ms = 8 utestdir=utestdir)
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 results = test.run_test(testfunction=run_test_9)
logging.info("time elapsed %.2f [s]."%(time2-time1)) eval_results(results)
logging.info("std_all = %.2f, tol=%.2f"%(std_all, tolerance)) logging.info("%s exits with SUCCESS" % (argv[0]))
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) exit(SUCCESS)
...@@ -114,6 +114,18 @@ def PassedLineY(p, exit): ...@@ -114,6 +114,18 @@ 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):
""" """
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</trajectories> </trajectories>
<!-- where to store the logs --> <!-- where to store the logs -->
<logfile>log</logfile> <logfile>log</logfile>
<num_threads>8</num_threads> <num_threads>24</num_threads>
<!-- traffic information: e.g closed doors or smoked rooms --> <!-- traffic information: e.g closed doors or smoked rooms -->
<traffic_constraints> <traffic_constraints>
<!-- room states are: good or smoked --> <!-- room states are: good or smoked -->
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
<!--persons information and distribution --> <!--persons information and distribution -->
<agents operational_model_id="3"> <agents operational_model_id="3">
<agents_distribution> <agents_distribution>
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="2" number="20" goal_id="0" router_id="1" /> <group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="2" number="60" goal_id="0" router_id="1" />
</agents_distribution> </agents_distribution>
<!-- frequency in persons/minute --> <!-- frequency in persons/minute -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment