Skip to content

Commit 313a0de

Browse files
committed
debug for traffic matrix
1 parent 107fa1e commit 313a0de

5 files changed

Lines changed: 439 additions & 9 deletions

File tree

examples/small_test_baseline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ traffic:
9191
enabled: true
9292
model: gravity
9393
gbps_per_mw: 250.0
94-
mw_per_dc_region: 50.0
94+
mw_per_dc_region: 500.0
9595
priority_ratios:
9696
0: 1
9797
matrix_name: baseline_traffic_matrix
@@ -103,7 +103,7 @@ traffic:
103103
distance_metric: euclidean_km
104104
emission: explicit_pairs
105105
jitter_stddev: 0.0
106-
rounding_gbps: 0.0
106+
rounding_gbps: 100.0
107107

108108
data_sources:
109109
uac_polygons: "data/tl_2020_us_uac20.zip"

examples/small_test_clos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ traffic:
9292
enabled: true
9393
model: gravity
9494
gbps_per_mw: 250.0
95-
mw_per_dc_region: 50.0
95+
mw_per_dc_region: 500.0
9696
priority_ratios:
9797
0: 1
9898
matrix_name: baseline_traffic_matrix
@@ -104,7 +104,7 @@ traffic:
104104
distance_metric: euclidean_km
105105
emission: explicit_pairs
106106
jitter_stddev: 0.0
107-
rounding_gbps: 0.0
107+
rounding_gbps: 100.0
108108

109109
data_sources:
110110
uac_polygons: "data/tl_2020_us_uac20.zip"

topogen/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ def build_command(args: argparse.Namespace) -> None:
8383
prefix = getattr(config_obj, "_source_path", config_path)
8484
output_path = Path.cwd() / f"{Path(prefix).stem}_scenario.yml"
8585

86+
# Attach optional debug directory to config for downstream use
87+
if getattr(args, "debug_dir", None):
88+
try:
89+
debug_dir = Path(args.debug_dir)
90+
debug_dir.mkdir(parents=True, exist_ok=True)
91+
config_obj._debug_dir = debug_dir
92+
# Provide a stable stem to downstream exporters
93+
config_obj._source_stem = Path(config_path).stem
94+
except Exception:
95+
# Non-fatal: continue without debug directory
96+
pass
97+
8698
# Run the pipeline with timing
8799
with Timer("Topology generation pipeline"):
88100
scenario_yaml = _run_pipeline(
@@ -349,6 +361,14 @@ def main() -> None:
349361
action="store_true",
350362
help="Print generated YAML to stdout for debugging",
351363
)
364+
build_parser.add_argument(
365+
"--debug-dir",
366+
default=None,
367+
help=(
368+
"Optional directory to write debug artifacts (e.g., traffic matrix "
369+
"internals as JSON) when -v is enabled"
370+
),
371+
)
352372

353373
build_parser.set_defaults(func=build_command)
354374

topogen/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ class TrafficGravityConfig:
312312
emission: One of {"explicit_pairs", "macro_pairwise"} for output format.
313313
max_partners_per_dc: If set, keeps top-K partners per DC by weight.
314314
jitter_stddev: Lognormal sigma for multiplicative noise (0 disables jitter).
315-
rounding_gbps: If > 0, round per-pair demands to this step size and conserve totals.
315+
rounding_gbps: If > 0, quantize undirected per-pair totals to this step size.
316+
rounding_policy: Quantization policy for undirected totals. One of
317+
{"nearest", "ceil", "floor"}. "nearest" minimizes absolute error,
318+
"ceil" guarantees non-negative inflation (sum >= exact total), and
319+
"floor" guarantees non-positive inflation (sum <= exact total).
316320
mw_per_dc_region_overrides: Optional overrides by metro name or full DC path
317321
(e.g., "metro3/dc2"). Overrides apply after defaults.
318322
"""
@@ -326,6 +330,7 @@ class TrafficGravityConfig:
326330
max_partners_per_dc: int | None = None
327331
jitter_stddev: float = 0.0
328332
rounding_gbps: float = 0.0
333+
rounding_policy: str = "nearest"
329334
mw_per_dc_region_overrides: dict[str, float] = field(default_factory=dict)
330335

331336

@@ -456,6 +461,9 @@ class TopologyConfig:
456461
# Visualization behavior; default False keeps previous straight-line rendering
457462
_use_real_corridor_geometry: bool = False
458463
_source_path: Path | None = None
464+
# Optional instrumentation fields for debugging/export
465+
_debug_dir: Path | None = None
466+
_source_stem: str | None = None
459467

460468
@classmethod
461469
def from_yaml(cls, config_path: Path) -> TopologyConfig:

0 commit comments

Comments
 (0)