-
Notifications
You must be signed in to change notification settings - Fork 27
Update simulator #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update simulator #61
Changes from all commits
df5b2c4
1c758a4
3b7bec3
d147c56
ceb661c
be646da
a313564
cd7c9fb
aaea516
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| from typing import Any, Sequence | ||
| import argparse | ||
| import os | ||
| from .. import core | ||
|
|
||
|
|
||
|
|
@@ -16,19 +17,42 @@ def parse_command_line_args(): | |
| description="Process the stream and network paths." | ||
| ) | ||
|
|
||
| # Add the positional arguments | ||
|
|
||
| parser.add_argument("task", type=str, help="The file path to the stream CSV file.") | ||
| parser.add_argument("net", type=str, help="The file path to the network CSV file.") | ||
| # Switch to optional flags for all parameters | ||
| parser.add_argument( | ||
| "task", | ||
| type=str, | ||
| help="The file path to the stream CSV file.", | ||
| ) | ||
| parser.add_argument( | ||
| "output", type=str, nargs="?", help="The output folder path.", default="./" | ||
| "net", | ||
| type=str, | ||
| help="The file path to the network CSV file.", | ||
| ) | ||
| parser.add_argument( | ||
| "workers", type=int, nargs="?", help="The number of workers.", default=1 | ||
| "--output", | ||
| type=str, | ||
| default="./", | ||
| nargs="?", | ||
| help="The output folder path.", | ||
| ) | ||
| parser.add_argument( | ||
| "name", type=str, nargs="?", help="The name of the experiment.", default="-" | ||
| "--workers", | ||
| type=int, | ||
| default=1, | ||
| nargs="?", | ||
| help="The number of workers.", | ||
| ) | ||
| parser.add_argument( | ||
| "--name", | ||
| type=str, | ||
| default="-", | ||
| nargs="?", | ||
| help="The name of the experiment.", | ||
| ) | ||
|
Comment on lines
26
to
+51
|
||
|
|
||
| parsed = parser.parse_args() | ||
| ## TODO: Put me somewhere else. | ||
| os.makedirs(parsed.output, exist_ok=True) | ||
|
|
||
| args = parse_command_line_constants(parser) | ||
|
|
||
|
|
@@ -62,7 +86,7 @@ def benchmark(stream_path, network_path): | |
|
|
||
| if __name__ == "__main__": | ||
| args = parse_command_line_args() | ||
| benchmark(args.STREAM_PATH, args.NETWORK_PATH) | ||
| benchmark(args.task, args.net) | ||
|
|
||
|
|
||
| def _interface(name: str) -> Any: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,19 +85,7 @@ def line(num_sw, num_queue, data_rate, header): | |
| net[i + num_sw, i] = 1 | ||
| net[i, i + num_sw] = 1 | ||
|
|
||
| result = [] | ||
| for i in range(num_node): | ||
| for j in range(num_node): | ||
| if net[i][j]: | ||
| link = [] | ||
| link.append((i, j)) | ||
| link.append(num_queue) | ||
| link.append(data_rate) | ||
| link.append(ERROR) | ||
| link.append(0) | ||
| result.append(link) | ||
|
|
||
| result = pd.DataFrame(result, columns=["link", "q_num", "rate", "t_proc", "t_prop"]) | ||
| result = _convert_2darray_to_csv(net, num_node, num_queue, data_rate) | ||
| result.to_csv(header + ".csv", index=False) | ||
| return net | ||
|
|
||
|
|
@@ -119,24 +107,13 @@ def ring(num_sw, num_queue, data_rate, header): | |
| net[0, num_sw - 1] = 1 | ||
| net[num_sw - 1, 0] = 1 | ||
|
|
||
| result = [] | ||
| for i in range(num_node): | ||
| for j in range(num_node): | ||
| if net[i][j]: | ||
| link = [] | ||
| link.append((i, j)) | ||
| link.append(num_queue) | ||
| link.append(data_rate) | ||
| link.append(ERROR) | ||
| link.append(0) | ||
| result.append(link) | ||
|
|
||
| result = pd.DataFrame(result, columns=["link", "q_num", "rate", "t_proc", "t_prop"]) | ||
| result = _convert_2darray_to_csv(net, num_node, num_queue, data_rate) | ||
| result.to_csv(header + ".csv", index=False) | ||
| return net | ||
|
|
||
|
|
||
| def tree(num_sw, num_queue, data_rate, header): | ||
| # Aka. STAR | ||
| num_node = num_sw * 2 + 1 | ||
| net = np.zeros(shape=(num_node, num_node)) | ||
|
|
||
|
|
@@ -145,19 +122,8 @@ def tree(num_sw, num_queue, data_rate, header): | |
| net[i * 2 + 1, i] = 1 | ||
| net[i, i * 2 + 2] = 1 | ||
| net[i * 2 + 2, i] = 1 | ||
| result = [] | ||
| for i in range(num_node): | ||
| for j in range(num_node): | ||
| if net[i][j]: | ||
| link = [] | ||
| link.append((i, j)) | ||
| link.append(num_queue) | ||
| link.append(data_rate) | ||
| link.append(ERROR) | ||
| link.append(0) | ||
| result.append(link) | ||
|
|
||
| result = pd.DataFrame(result, columns=["link", "q_num", "rate", "t_proc", "t_prop"]) | ||
| result = _convert_2darray_to_csv(net, num_node, num_queue, data_rate) | ||
| result.to_csv(header + ".csv", index=False) | ||
| return net | ||
|
|
||
|
|
@@ -170,12 +136,13 @@ def mesh(num_sw, num_queue, data_rate, header): | |
| for i in range(0, num_sw - 1): | ||
| net[i, i + 1] = 1 | ||
| net[i + 1, i] = 1 | ||
|
|
||
| ## Connect the switch and the end-station | ||
| for i in range(num_sw): | ||
| net[i + num_sw, i] = 1 | ||
| net[i, i + num_sw] = 1 | ||
|
|
||
| ## Connect the mesh | ||
| ## Connect the ring | ||
| net[0, num_sw - 1] = 1 | ||
| net[num_sw - 1, 0] = 1 | ||
|
|
||
|
|
@@ -184,24 +151,70 @@ def mesh(num_sw, num_queue, data_rate, header): | |
| net[i, num_sw - i - 1] = 1 | ||
| net[num_sw - i - 1, i] = 1 | ||
|
|
||
| result = [] | ||
| for i in range(num_node): | ||
| for j in range(num_node): | ||
| if net[i][j]: | ||
| link = [] | ||
| link.append((i, j)) | ||
| link.append(num_queue) | ||
| link.append(data_rate) | ||
| link.append(ERROR) | ||
| link.append(0) | ||
| result.append(link) | ||
| result = _convert_2darray_to_csv(net, num_node, num_queue, data_rate) | ||
| result.to_csv(header + ".csv", index=False) | ||
| return net | ||
|
|
||
| result = pd.DataFrame(result, columns=["link", "q_num", "rate", "t_proc", "t_prop"]) | ||
| def mesh_2d(num_sw, num_queue, data_rate, header): | ||
|
|
||
| n = int(np.sqrt(num_sw)) | ||
| num_node = num_sw + 4 * n - 4 | ||
| net = np.zeros(shape=(num_node, num_node)) | ||
|
|
||
| if n ** 2 != num_sw: | ||
| raise ValueError("Wrong num_sw for mesh_2d, col_len != row_len") | ||
|
|
||
| row_len = col_len = int(np.sqrt(num_sw)) | ||
|
|
||
| # Save to mat | ||
| mat = [] | ||
| count = 0 | ||
| for i in range(row_len): | ||
| if i % 2 == 0: | ||
| row = list(range(count, count + col_len)) | ||
| else: | ||
| row = list(range(count, count + col_len))[::-1] | ||
|
Comment on lines
+173
to
+176
|
||
| mat.append(row) | ||
| count += col_len | ||
|
|
||
| # Fill net | ||
| searched = set() | ||
| es_id = num_sw | ||
|
|
||
| def _dfs(x, y): | ||
| nonlocal es_id, searched | ||
| if x < 0 or y < 0 or x >= row_len or y >= col_len: | ||
| return | ||
| if (x,y) in searched: | ||
| return | ||
| searched.add((x,y)) | ||
|
|
||
| # Add es on border | ||
| if x == 0 or y == 0 or x == row_len - 1 or y == col_len - 1: | ||
| net[mat[x][y]][es_id] = 1 | ||
| net[es_id][mat[x][y]] = 1 | ||
| es_id += 1 | ||
|
|
||
| # Connect sw neighbors | ||
| def _search_nxt(x, y, nx, ny): | ||
| if 0 <= nx < row_len and 0 <= ny < col_len: | ||
| net[mat[x][y]][mat[nx][ny]] = 1 | ||
| net[mat[nx][ny]][mat[x][y]] = 1 | ||
| _dfs(nx, ny) | ||
|
|
||
| _search_nxt(x, y, x-1, y) | ||
| _search_nxt(x, y, x+1, y) | ||
| _search_nxt(x, y, x, y-1) | ||
| _search_nxt(x, y, x, y+1) | ||
|
|
||
| _dfs(0, 0) | ||
|
|
||
| result = _convert_2darray_to_csv(net, num_node, num_queue, data_rate) | ||
| result.to_csv(header + ".csv", index=False) | ||
| return net | ||
|
|
||
|
|
||
| TOPO_FUNC = [line, ring, tree, mesh] | ||
| TOPO_FUNC = [line, ring, tree, mesh, mesh_2d] | ||
|
|
||
|
|
||
| def generate_flowset( | ||
|
|
@@ -227,6 +240,7 @@ def generate_flowset( | |
| result.to_csv(header + ".csv", index=False) | ||
| return | ||
|
|
||
| # NOTE: Prioritize uti(ES) <= 75% for traffic generation | ||
| availble_es = np.argwhere(uti_ports <= 0.75).reshape(-1) | ||
| if availble_es.size == 0: | ||
| availble_es = np.array([x for x in range(num_es)]) | ||
|
|
@@ -251,3 +265,24 @@ def generate_flowset( | |
| i += 1 | ||
| else: | ||
| continue | ||
|
|
||
|
|
||
| def _convert_2darray_to_csv(net, num_node, num_queue, data_rate): | ||
| result = [] | ||
| for i in range(num_node): | ||
| for j in range(num_node): | ||
| if net[i][j]: | ||
| link = [] | ||
| link.append((i, j)) | ||
| link.append(num_queue) | ||
| link.append(data_rate) | ||
| link.append(ERROR) | ||
| link.append(0) | ||
| result.append(link) | ||
|
|
||
| result = pd.DataFrame(result, columns=["link", "q_num", "rate", "t_proc", "t_prop"]) | ||
| return result | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| mesh_2d(9,1,1,"test") | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,9 @@ | |||||
| import traceback | ||||||
| import itertools | ||||||
| import pandas as pd | ||||||
| import numpy as np | ||||||
| from tqdm import tqdm | ||||||
| import os | ||||||
| import networkx as nx | ||||||
| from .dataset_spec import generate_flowset | ||||||
| from .dataset_spec import TOPO_FUNC | ||||||
|
|
@@ -27,6 +29,7 @@ def __init__(self, num_ins, num_stream, num_sw, period, size, deadline, topo): | |||||
| self.topo = [topo] if isinstance(topo, int) else topo | ||||||
|
|
||||||
| def run(self, path): | ||||||
| os.makedirs(path, exist_ok=True) | ||||||
| param_combinations = list(itertools.product( | ||||||
| self.num_stream, | ||||||
| self.num_sw, | ||||||
|
|
@@ -54,14 +57,14 @@ def run(self, path): | |||||
| data_rate=1, | ||||||
| header=path + header + "_topo", | ||||||
| ) | ||||||
| _flowset = generate_flowset( | ||||||
| _ = generate_flowset( | ||||||
| nx.DiGraph(net), | ||||||
| size, | ||||||
| period, | ||||||
| deadline, | ||||||
| num_stream, | ||||||
| num_sw, | ||||||
| num_sw, | ||||||
| num_sw if topo != 4 else int(np.sqrt(num_sw)-1) * 4, | ||||||
|
||||||
| num_sw if topo != 4 else int(np.sqrt(num_sw)-1) * 4, | |
| num_sw if topo != 4 else 4 * int(np.sqrt(num_sw)) - 4, # For square mesh (topo==4), number of border nodes is 4*n-4 where n=sqrt(num_sw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misleading comment: The comment "Switch to optional flags for all parameters" is inaccurate since
taskandnetremain as positional arguments, not optional flags. Either update the comment to reflect that onlyoutput,workers, andnameare optional, or make all arguments truly optional with--taskand--netflags.