SNABSuite  0.x
Spiking Neural Architecture Benchmark Suite
Functions | Variables
generate_tex Namespace Reference

Functions

def result_json_to_global_dict (filename)
 
def assemble_global_dict ()
 
def get_key_arrays (dictionary)
 
def get_key_arrays_from_config ()
 
def gather_array_names (snabname)
 
def gather_benchmark_measures (snabname)
 
def write_array_params (texfile, snab, backend, param_names, index)
 
def write_results (texfile, backend, index, snab, measures, got_snab)
 

Variables

 results_dict = dict()
 
 config_array_dict = dict()
 
 param_names = gather_array_names(snabname)
 
 measures = gather_benchmark_measures(snabname)
 
 texfile = open("tables/" + snabname + ".tex", 'w')
 
bool got_snab = False
 

Function Documentation

def generate_tex.assemble_global_dict ( )
Gathers all results from build directory

Definition at line 62 of file generate_tex.py.

63  """
64  Gathers all results from build directory
65  """
66 
67  for filename in os.listdir("../build/"):
68  # All jsons besides invisible files and backup data
69  if filename.endswith(".json") and not filename.startswith("."):
70  if not filename.endswith("_bak.json"):
71  result_json_to_global_dict("../build/" + filename)
72 
73 
def assemble_global_dict()
Definition: generate_tex.py:62
def result_json_to_global_dict(filename)
Definition: generate_tex.py:35
def generate_tex.gather_array_names (   snabname)
Get the array names for the title of the table

Definition at line 106 of file generate_tex.py.

106 def gather_array_names(snabname):
107  """
108  Get the array names for the title of the table
109  """
110 
111  array_names = []
112  for i in config_array_dict[snabname]: # Simulators
113  for j in config_array_dict[snabname][i]:
114  # Check if this is already included
115  if not j in array_names:
116  array_names.append(j)
117  return array_names
118 
119 
def gather_array_names(snabname)
def generate_tex.gather_benchmark_measures (   snabname)
Get the measure names for the title of the table

Definition at line 120 of file generate_tex.py.

121  """
122  Get the measure names for the title of the table
123  """
124 
125  array_names = []
126  for i in results_dict:
127  try:
128  temp = results_dict[i]["0"]
129  except:
130  continue
131  for j in temp:
132  if not j["name"] == snabname:
133  continue
134  for k in j["results"]:
135  array_names.append(k["name"] + " in " + k["measures"])
136  if len(array_names) > 0:
137  return array_names
138  return array_names
139 
140 
def gather_benchmark_measures(snabname)
def generate_tex.get_key_arrays (   dictionary)
Iterates through the dictionary, gathers all entries with lists

dictionary -- dict to iteratively

Definition at line 74 of file generate_tex.py.

74 def get_key_arrays(dictionary):
75  """
76  Iterates through the dictionary, gathers all entries with lists
77 
78  dictionary -- dict to iteratively
79  """
80 
81  temp_dict = dict()
82  for i in dictionary:
83  if type(dictionary[i]) == list:
84  temp_dict[i] = dictionary[i]
85  else:
86  if type(dictionary[i]) == dict:
87  a = get_key_arrays(dictionary[i])
88  if len(a) != 0:
89  temp_dict[i] = a
90  return temp_dict
91 
92 
def get_key_arrays(dictionary)
Definition: generate_tex.py:74
def generate_tex.get_key_arrays_from_config ( )
Gathers all arrays in configs from config directory

Definition at line 93 of file generate_tex.py.

94  """
95  Gathers all arrays in configs from config directory
96  """
97 
98  for filename in os.listdir("../config/"):
99  if filename.endswith(".json") and not filename.startswith("."):
100  with open("../config/" + filename) as temp:
101  json_temp = json.load(temp)
102  config_array_dict[filename.split(
103  ".")[0]] = get_key_arrays(json_temp)
104 
105 
def get_key_arrays(dictionary)
Definition: generate_tex.py:74
def get_key_arrays_from_config()
Definition: generate_tex.py:93
def generate_tex.result_json_to_global_dict (   filename)
Adds results from file to global storage

filename -- name of the file which will be used

Definition at line 35 of file generate_tex.py.

36  """
37  Adds results from file to global storage
38 
39  filename -- name of the file which will be used
40  """
41 
42  with open(filename) as temp:
43  json_temp = json.load(temp)
44 
45  simulator = filename.split(
46  "/")[-1].split(".json")[0].split("_")[0].split("=")[0].split("pynn.")[-1]
47 
48  # Trigger key errors for unknown simulators
49  if simulator not in SIMULATOR_LABELS:
50  return
51 
52  # Get the array number
53  array_nr = filename.split("/")[-1].split(".json")[0].split("_")[-1]
54  if not array_nr.isdigit():
55  array_nr = "0"
56 
57  if simulator not in results_dict:
58  results_dict[simulator] = dict()
59  results_dict[simulator][array_nr] = json_temp
60 
61 
def result_json_to_global_dict(filename)
Definition: generate_tex.py:35
def generate_tex.write_array_params (   texfile,
  snab,
  backend,
  param_names,
  index 
)
Write parameters of the benchmark run

texfile -- open file descriptor to file
snab -- name string of the snab
backend -- backend string
param_names -- list of array names created by gather_array_names
index -- index of the current array entry

Definition at line 141 of file generate_tex.py.

141 def write_array_params(texfile, snab, backend, param_names, index):
142  """
143  Write parameters of the benchmark run
144 
145  texfile -- open file descriptor to file
146  snab -- name string of the snab
147  backend -- backend string
148  param_names -- list of array names created by gather_array_names
149  index -- index of the current array entry
150  """
151 
152  for i in param_names:
153  if backend in config_array_dict[snab] and i in config_array_dict[snab][backend]:
154  texfile.write(
155  " & " + str(config_array_dict[snab][backend][i][int(index)]))
156  else:
157  texfile.write(" & ")
158 
159 
def write_array_params(texfile, snab, backend, param_names, index)
def generate_tex.write_results (   texfile,
  backend,
  index,
  snab,
  measures,
  got_snab 
)
Write results of the benchmark run

texfile -- open file descriptor to file
snab -- name string of the snab
backend -- backend string
measures -- list of measure names created by gather_benchmark_measures
index -- index of the current array entry
got_snab -- boolean wether there was at least one entry

Definition at line 160 of file generate_tex.py.

160 def write_results(texfile, backend, index, snab, measures, got_snab):
161  """
162  Write results of the benchmark run
163 
164  texfile -- open file descriptor to file
165  snab -- name string of the snab
166  backend -- backend string
167  measures -- list of measure names created by gather_benchmark_measures
168  index -- index of the current array entry
169  got_snab -- boolean wether there was at least one entry
170  """
171 
172  for i in results_dict[backend][index]:
173  if i["name"] == snab:
174  got_snab = True
175  for j in measures:
176  found = False
177  for k in i["results"]:
178  if k["name"] == j.split(" in ")[0]:
179  texfile.write(" & " + '{:.2f}'.format(k["value"]))
180  found = True
181  # SNAB exists but measure was not found?
182  if not found:
183  texfile.write(" & ")
184  texfile.write("\n")
185 
186  # Fill in gaps if there were no results
187  if not got_snab:
188  for j in measures:
189  texfile.write(" & ")
190  texfile.write("\n")
191  return got_snab
192 
193 
196 
def assemble_global_dict()
Definition: generate_tex.py:62
def write_results(texfile, backend, index, snab, measures, got_snab)
def get_key_arrays_from_config()
Definition: generate_tex.py:93

Variable Documentation

generate_tex.config_array_dict = dict()

Definition at line 32 of file generate_tex.py.

generate_tex.got_snab = False

Definition at line 223 of file generate_tex.py.

generate_tex.measures = gather_benchmark_measures(snabname)

Definition at line 204 of file generate_tex.py.

generate_tex.param_names = gather_array_names(snabname)

Definition at line 203 of file generate_tex.py.

generate_tex.results_dict = dict()

Definition at line 30 of file generate_tex.py.

generate_tex.texfile = open("tables/" + snabname + ".tex", 'w')

Definition at line 205 of file generate_tex.py.