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 @@
<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>linspace(1, 100000, 10)</seed>
<num_threads>range(1,9)</num_threads>
<seed>1234</seed>
<num_threads>[1, 2, 4, 8, 16, 24]</num_threads>
<max_sim_time unit="sec">900</max_sim_time>
<!-- geometry file -->
<geometry>../geometry.xml</geometry>
......@@ -45,7 +45,7 @@
<!--persons information and distribution -->
<agents operational_model_id="3">
<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>
<!-- frequency in persons/minute -->
......
# 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[0])))
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[0]))
#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_")[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
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[0],
testdir=sys.path[0],
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[0], std_all, tolerance))
exit(FAILURE)
else:
logging.info("%s exits with SUCCESS std_all = %f < %f"%(argv[0], std_all, tolerance))
exit(SUCCESS)
results = test.run_test(testfunction=run_test_9)
eval_results(results)
logging.info("%s exits with SUCCESS" % (argv[0]))
exit(SUCCESS)
......@@ -114,7 +114,19 @@ def PassedLineY(p, exit):
x2 = exit[2]
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):
"""
get max sim time
......
......@@ -15,7 +15,7 @@
</trajectories>
<!-- where to store the logs -->
<logfile>log</logfile>
<num_threads>8</num_threads>
<num_threads>24</num_threads>
<!-- traffic information: e.g closed doors or smoked rooms -->
<traffic_constraints>
<!-- room states are: good or smoked -->
......@@ -47,7 +47,7 @@
<!--persons information and distribution -->
<agents operational_model_id="3">
<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>
<!-- 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