Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/cuopt/cuopt/routing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,9 @@ def save_data_model_to_yaml(data_model, solver_settings, solution, fname):
b_r_fp = solver_settings.get_best_results_file_path()
b_r_i = solver_settings.get_best_results_interval()
if b_r_fp:
if b_r_i:
yamldict.update({"best_result_path", b_r_fp})
yamldict.update({"best_result_interval", b_r_i})
if b_r_i is not None:
yamldict["best_result_path"] = b_r_fp
yamldict["best_result_interval"] = b_r_i

if solution.get_status() == 0:
sol_df = solution.get_route()
Expand Down
8 changes: 8 additions & 0 deletions python/cuopt/cuopt/tests/routing/test_solver_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import yaml

import cudf

Expand Down Expand Up @@ -52,7 +53,9 @@ def test_dump_config():
"""Test SolverSettings solve with config file"""
s = routing.SolverSettings()
config_file = "solver_cfg.yaml"
best_results_file = "best_results.txt"
s.dump_config_file(config_file)
s.dump_best_results(best_results_file, 0)
Comment on lines +56 to +58

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use per-test temporary paths to avoid filename collisions.

Hardcoded solver_cfg.yaml / best_results.txt can cause flaky behavior in parallel or repeated test runs. Use tmp_path-scoped files.

Suggested change
-def test_dump_config():
+def test_dump_config(tmp_path):
     """Test SolverSettings solve with config file"""
     s = routing.SolverSettings()
-    config_file = "solver_cfg.yaml"
-    best_results_file = "best_results.txt"
+    config_file = tmp_path / "solver_cfg.yaml"
+    best_results_file = tmp_path / "best_results.txt"
     s.dump_config_file(config_file)
     s.dump_best_results(best_results_file, 0)
     assert s.get_config_file_name() == config_file
@@
-    with open(config_file) as f:
+    with open(config_file) as f:
         config = yaml.safe_load(f)
-    assert config["best_result_path"] == best_results_file
+    assert config["best_result_path"] == str(best_results_file)
     assert config["best_result_interval"] == 0

As per coding guidelines, **/*test*.{cpp,py,cu,cuh}: “Prevent flaky tests from GPU timing, uninitialized memory, or race conditions.”

Also applies to: 72-75

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/cuopt/cuopt/tests/routing/test_solver_settings.py` around lines 56 -
58, Tests use hardcoded filenames (config_file = "solver_cfg.yaml",
best_results_file = "best_results.txt") when calling s.dump_config_file and
s.dump_best_results which can collide in parallel runs; change to use the pytest
tmp_path fixture to create per-test files/paths (e.g., tmp_path /
"solver_cfg.yaml" and tmp_path / "best_results.txt") and pass those Path strings
to s.dump_config_file and s.dump_best_results, and apply the same tmp_path-based
replacements for the other occurrences referenced around lines 72-75 so each
test writes to isolated temporary files.

Source: Coding guidelines

assert s.get_config_file_name() == config_file

# Small example data model: 3 locations, 1 vehicle
Expand All @@ -66,6 +69,11 @@ def test_dump_config():
routing_solution = routing.Solve(dm, s)
assert routing_solution.get_status() == 0

with open(config_file) as f:
config = yaml.safe_load(f)
assert config["best_result_path"] == best_results_file
assert config["best_result_interval"] == 0

# Load from written solver_cfg.yaml and solve again
dm_from_yaml, s_from_yaml = utils.create_data_model_from_yaml(config_file)
solution_from_yaml = routing.Solve(dm_from_yaml, s_from_yaml)
Expand Down