-
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 6 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 | ||||||||
|
|
||||||||
|
|
||||||||
| def parse_command_line_args(): | ||||||||
|
|
@@ -15,22 +16,46 @@ 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. | ||||||||
| if parsed.output: | ||||||||
| os.makedirs(parsed.output, exist_ok=True) | ||||||||
|
||||||||
| if parsed.output: | |
| os.makedirs(parsed.output, exist_ok=True) | |
| os.makedirs(parsed.output, exist_ok=True) |
| 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,69 @@ 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): | ||||||||||||||||||||||||||||||||
| num_node = num_sw * 2 ## TODO: |ES| != |SW| for mesh_2d | ||||||||||||||||||||||||||||||||
| net = np.zeros(shape=(num_node, num_node)) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if int(np.sqrt(num_sw)) ** 2 != num_sw: | ||||||||||||||||||||||||||||||||
| raise ValueError("Wrong num_sw for mesh_2d, col_len != row_len") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| row_len = col_len = int(np.sqrt(num_sw)) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| num_node = num_sw * 2 ## TODO: |ES| != |SW| for mesh_2d | |
| net = np.zeros(shape=(num_node, num_node)) | |
| if int(np.sqrt(num_sw)) ** 2 != num_sw: | |
| raise ValueError("Wrong num_sw for mesh_2d, col_len != row_len") | |
| row_len = col_len = int(np.sqrt(num_sw)) | |
| n = int(np.sqrt(num_sw)) | |
| num_node = num_sw + 4 * n - 4 # Correct number of nodes for mesh_2d topology | |
| 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 = n |
Copilot
AI
Nov 28, 2025
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.
Undocumented row reversal logic: Lines 171-174 reverse the node numbering for odd-indexed rows in the 2D mesh without explanation. This creates a serpentine/zigzag numbering pattern rather than a simple row-major ordering. If this is intentional (e.g., for routing optimization), it should be documented. Otherwise, this might be unexpected behavior.
Outdated
Copilot
AI
Nov 28, 2025
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.
Typo in comment: "boarder" should be "border".
| # Add es on boarder | |
| # Add es on border |
Outdated
Copilot
AI
Nov 28, 2025
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.
[nitpick] Unclear/non-standard condition ordering: The condition row_len > nx >= 0 uses reverse comparison order which is less readable. Consider rewriting as 0 <= nx < row_len and 0 <= ny < col_len for improved clarity and consistency with typical Python range checks.
| if row_len > nx >= 0 and col_len > ny >= 0: | |
| if 0 <= nx < row_len and 0 <= ny < col_len: |
Outdated
Copilot
AI
Nov 28, 2025
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.
Debug print statement should be removed: This print(result) statement appears to be leftover debug code that should not be in production.
| print(result) |
| 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 | ||||||
|
|
@@ -26,6 +28,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, | ||||||
|
|
@@ -53,14 +56,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.