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
92 changes: 92 additions & 0 deletions regression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Cuopt Regression Testing



## Getting started
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think this file is more like template, may be we need to populate it with more details.


To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!

## Add your files

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:

```
cd existing_repo
git remote add origin https://gitlab-master.nvidia.com/ramakrishnap/cuopt-regression-testing.git
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Iroy30 This might not be relevant anymore. Also please go through this doc and remove any unnecessary elements.

git branch -M main
git push -uf origin main
```

## Integrate with your tools

- [ ] [Set up project integrations](https://gitlab-master.nvidia.com/ramakrishnap/cuopt-regression-testing/-/settings/integrations)

## Collaborate with your team

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)

## Test and Deploy

Use the built-in continuous integration in GitLab.

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)

***

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name
Choose a self-explaining name for your project.

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
Comment on lines +1 to +92
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Replace generic template with regression-testing-specific documentation.

This file appears to be a boilerplate GitLab README template rather than documentation for the regression testing framework. It should be replaced with actual documentation covering: (1) regression test framework overview, (2) how to set up and run tests, (3) configuration file format and examples, (4) interpreting results and metrics, and (5) contributing new regression tests.

🧰 Tools
🪛 LanguageTool

[style] ~49-~49: Consider using a less common alternative to make your writing sound more unique and professional.
Context: ...le and use the handy template below (or feel free to structure it however you want - this is...

(FEEL_FREE_TO_STYLE_ME)


[grammar] ~52-~52: Use a hyphen to join words.
Context: ...e template are suggestions for most open source projects. Also keep in mind that ...

(QB_NEW_EN_HYPHEN)


[style] ~61-~61: Consider shortening this phrase to just ‘whether’, unless you mean ‘regardless of whether’.
Context: ...ll images that convey metadata, such as whether or not all the tests are passing for the proje...

(WHETHER)


[style] ~81-~81: Consider shortening or rephrasing this to strengthen your wording.
Context: ...accepting them. For people who want to make changes to your project, it's helpful to have some...

(MAKE_CHANGES)


[grammar] ~89-~89: Use a hyphen to join words.
Context: ...ted to the project. ## License For open source projects, say how it is licensed....

(QB_NEW_EN_HYPHEN)

🪛 markdownlint-cli2 (0.18.1)

16-16: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
In regression/README.md around lines 1-92, the file currently contains a generic
GitLab README template; replace it with regression-testing-specific
documentation that covers (1) a concise framework overview and architecture
diagram/flow, (2) step-by-step setup and run instructions including required
dependencies, environment variables, and example commands to execute tests
locally and in CI, (3) configuration file format with schema and at least one
complete example config, (4) how to interpret results and metrics (what logs,
exit codes, artifact locations, and sample output/thresholds to look for), and
(5) contribution guidelines for adding new regression tests (test structure,
naming, and a PR checklist); include links to CI job names, example artifacts,
and a short Troubleshooting and License section.

288 changes: 288 additions & 0 deletions regression/benchmark_scripts/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
Copy link
Collaborator

Choose a reason for hiding this comment

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

Look at other files for reference, recently this section has been reduced.

# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.

import os
from multiprocessing import Process
#from utils import get_configuration, LPMetrics, RoutingMetrics
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove stale code

#from cuopt import linear_programming
#from cuopt import routing
#from cuopt import utilities
import rmm
import time
import pandas as pd
import glob
import logging as log
from datetime import datetime
import os
import argparse

log.getLogger().setLevel(log.INFO)
Comment on lines +11 to +26
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Clean up commented and duplicate imports.

Several import issues need attention:

  1. Lines 13-16: Commented-out imports should be removed or uncommented if needed.
  2. Line 23: os is imported twice (lines 11 and 23).
  3. Line 20: glob is imported but only used inside the worker function where it's re-imported.

Apply this diff:

 import os
 from multiprocessing import Process
-#from utils import get_configuration, LPMetrics, RoutingMetrics
-#from cuopt import linear_programming
-#from cuopt import routing
-#from cuopt import utilities
 import rmm
 import time
 import pandas as pd
-import glob
 import logging as log
 from datetime import datetime
-import os
 import argparse
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import os
from multiprocessing import Process
#from utils import get_configuration, LPMetrics, RoutingMetrics
#from cuopt import linear_programming
#from cuopt import routing
#from cuopt import utilities
import rmm
import time
import pandas as pd
import glob
import logging as log
from datetime import datetime
import os
import argparse
log.getLogger().setLevel(log.INFO)
import os
from multiprocessing import Process
import rmm
import time
import pandas as pd
import logging as log
from datetime import datetime
import argparse
🧰 Tools
🪛 Flake8 (7.3.0)

[error] 13-13: block comment should start with '# '

(E265)


[error] 14-14: block comment should start with '# '

(E265)


[error] 15-15: block comment should start with '# '

(E265)


[error] 16-16: block comment should start with '# '

(E265)


[error] 20-20: 'glob' imported but unused

(F401)


[error] 23-23: redefinition of unused 'os' from line 11

(F811)

🪛 Ruff (0.14.2)

23-23: Redefinition of unused os from line 11

Remove definition: os

(F811)


def create_regression_markdown(data, regression_path, test_type_string):
regression_md_file = regression_path + "/" + test_type_string + "_regressions.md"

md_data = "*No regressions*"
# This to reduce size of slack message
limit_no_of_regression_list = 5

if len(data) > 0:
status = "*!! Regressions found !!*"
end_msg = "\n*Continues ...*" if len(data) > limit_no_of_regression_list else ""
table = data[:limit_no_of_regression_list].to_string(index=False)
md_data = status + f'\n```\n{table}\n```' + end_msg

with open(regression_md_file, "w") as fp:
fp.write(md_data)

def record_regressions(test_name, data, req_metrics, regression_path, test_type_string):

regression_file = regression_path + "/" + test_type_string + "_regressions.csv"

regression_df = pd.DataFrame({"Test Name":[], "Metric Name":[], "Value":[], "Avg Value":[], "Regression(%)":[]})
for name in req_metrics:
if name.startswith("bks_change_"):
pchange = data[name].iloc[-1].item()
metric_name = name.replace("bks_change_", "")
limit = req_metrics[metric_name]["bks"].get("threshold", 5)
prev_val_mean = pchange
latest_val = pchange
else:
limit = req_metrics[name].get("threshold", 5)
prev_val_mean = data[name][:-1][-30:].mean().item() if len(data) > 1 else data[name].iloc[-1].item()
latest_val = data[name].iloc[-1].item()

if prev_val_mean == 0:
pchange = latest_val
else:
pchange = ((latest_val - prev_val_mean)/prev_val_mean) * 100

if abs(pchange) >= limit:
regression_df.loc[len(regression_df)] = [test_name, name, latest_val, prev_val_mean, pchange]

regression_df.to_csv(regression_file)
create_regression_markdown(regression_df, regression_path, test_type_string)

def get_bks_change(
metrics, required_metrics
):
bks_metrics = {}
for metric, value in required_metrics.items():
if "bks" in value.keys():
bks = value["bks"]["value"]
if bks == None:
continue
current = metrics[metric]
if bks == 0:
bks_metrics["bks_change_" + metric] = abs(current) * 100
elif current == 0:
bks_metrics["bks_change_" + metric] = abs(bks) * 100
else:
bks_metrics["bks_change_" + metric] = abs(((current - bks)/bks) * 100)

return bks_metrics

def record_result(
test_name, metrics, required_metrics, csv_path, test_type_string
):
file_path = csv_path + "/"
if test_type_string=="lp" or test_type_string=="mip":
file_path += test_type_string + "_" + test_name + ".csv"
else:
file_path += test_name + ".csv"
bks_metrics = get_bks_change(metrics, required_metrics)

# Add default metrics to data
required_metrics.update(bks_metrics)
metrics.update(bks_metrics)
req_metrics = list(required_metrics.keys()) + ["date_time", "git_commit"]

current_data = pd.DataFrame({key : [metrics[key]] for key in sorted(req_metrics)})
if os.path.isfile(file_path):
previous_data = pd.read_csv(file_path, index_col=0)
updated_data = pd.concat([previous_data, current_data], ignore_index=True)
else:
updated_data = current_data
record_regressions(test_name, updated_data, required_metrics, csv_path, test_type_string)
updated_data.to_csv(file_path)


def run_benchmark(
test_name,
data_model,
solver_settings,
required_metrics,
csv_path,
git_commit,
test_status_file,
d_type
):
import rmm
mr = rmm.mr.get_current_device_resource()

from utils import LPMetrics, RoutingMetrics
from cuopt import linear_programming
from cuopt import routing

start_time = time.time()
if d_type=="lp" or d_type=="mip":
metrics = LPMetrics()._asdict()
solver_settings.set_parameter("infeasibility_detection", False)
solver_settings.set_parameter("time_limit", 60)
solution = linear_programming.Solve(data_model, solver_settings)
else:
metrics = RoutingMetrics()._asdict()
solution = routing.Solve(data_model)
end_time = time.time()

metrics["gpu_memory_usage"] = int(mr.allocation_counts.peak_bytes/(1024*1024))
metrics["date_time"] = datetime.now().strftime("%m_%d_%Y_%H_%M_%S")
metrics["git_commit"] = git_commit

success_status = False

if d_type=="lp" or d_type=="mip":
## Optimal solution
acceptable_termination = ["Optimal", "TimeLimit", "FeasibleFound"]
if solution.get_termination_reason() in acceptable_termination:
success_status = True
metrics["solver_time"] = solution.get_solve_time()
metrics["primal_objective_value"] = solution.get_primal_objective()
if d_type == "lp":
lp_stats = solution.get_lp_stats()
metrics["nb_iterations"] = lp_stats["nb_iterations"]
else:
milp_stats = solution.get_milp_stats()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may need to look at if engine has introduced any new stats and whether we need to catch those.

metrics["mip_gap"] = milp_stats["mip_gap"]
metrics["max_constraint_violation"] = milp_stats["max_constraint_violation"]
metrics["max_int_violation"] = milp_stats["max_int_violation"]
metrics["max_variable_bound_violation"] = milp_stats["max_variable_bound_violation"]
record_result(test_name, metrics, required_metrics, csv_path, d_type)
else:
if solution.get_status() == 0:
success_status = True
metrics["solver_time"] = end_time - start_time
metrics["total_objective_value"] = solution.get_total_objective()
metrics["vehicle_count"] = solution.get_vehicle_count()

objectives = solution.get_objective_values()
if "prize" in required_metrics:
metrics["prize"] = objectives[routing.Objective.PRIZE]
if "cost" in required_metrics:
metrics["cost"] = objectives[routing.Objective.COST]
if "travel_time" in required_metrics:
metrics["travel_time"] = objectives[routing.Objective.TRAVEL_TIME]
record_result(test_name, metrics, required_metrics, csv_path, d_type)
return "SUCCESS" if success_status is True else "FAILED"

def reinitialize_rmm():

pool_size = 2**30
rmm.reinitialize(pool_allocator=True, initial_pool_size=pool_size)

base_mr = rmm.mr.get_current_device_resource()
stats_mr = rmm.mr.StatisticsResourceAdaptor(base_mr)
rmm.mr.set_current_device_resource(stats_mr)

return base_mr, stats_mr


def worker(gpu_id, dataset_file_path, csv_path, git_commit, log_path, test_status_file, n_gpus, d_type="routing"):
import os
os.environ["CUDA_VISIBLE_DEVICES"] = gpu_id

import glob
from utils import get_configuration
data_files = []
if d_type == "lp" or d_type == "mip":
data_files = glob.glob(dataset_file_path + "/*.mps")
else:
data_files = glob.glob(dataset_file_path + "/*_config.json")
idx = int(gpu_id)
n_files = 1 #len(data_files)

while idx < n_files:
mr, stats_mr = reinitialize_rmm()
from rmm._cuda.gpu import CUDARuntimeError, getDevice, setDevice

data_file = data_files[idx]
test_name = str(data_file)
status = "FAILED"
try:
test_name, data_model, solver_settings, requested_metrics = get_configuration(data_file, dataset_file_path, d_type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For LP and MILP are we using MPS files or are we still using json ?

log.basicConfig(level=log.INFO, filename=log_path+"/"+test_name+"_log.txt", filemode="a+",
format="%(asctime)-15s %(levelname)-8s %(message)s")
log.getLogger().setLevel(log.INFO)
log.info(f"------------- Test Start : {test_name} gpu id : {gpu_id} -------------------")
status = run_benchmark(
test_name,
data_model,
solver_settings,
requested_metrics,
csv_path,
git_commit,
test_status_file,
d_type
)
except Exception as e:
log.error(str(e))

with open(test_status_file, "a") as f:
f.write("\n")
f.write(test_name +": " + status)

# Delete instance of rmm
del mr
del stats_mr

log.info(f"------------- Test End : {test_name} gpu id : {gpu_id} -------------------")
idx = idx + n_gpus


def run(dataset_file_path, csv_path, git_commit, log_path, test_status_file, n_gpus, d_type):
# Restricting n_gpus to one to avoid resource sharing
#n_gpus = 1
procs = []
for gpu_id in range(int(n_gpus)):
p = Process(target=worker, args=(str(gpu_id), dataset_file_path, csv_path, git_commit, log_path, test_status_file, int(n_gpus), d_type))
p.start()
procs.append(p)

for p in procs:
p.join()
print("All processes finished.")


if __name__ == "__main__":

parser = argparse.ArgumentParser()

parser.add_argument(
"-c", "--config-path", type=str, help="Path to all configuration file"
)
parser.add_argument(
"-r", "--csv-path", type=str, help="Path to store result files, this would be for github where results gets stored"
)
parser.add_argument(
"-g", "--git-commit", type=str, help="git commit sha to keep track of runs"
)
parser.add_argument(
"-l", "--log-path", type=str, help="Path to log files"
)
parser.add_argument(
"-s", "--test-status-file", type=str, help="All test status will be stored in this file"
)
parser.add_argument(
"-n", "--num-gpus", type=str, help="Number of GPUs available"
)
parser.add_argument(
"-t", "--type", type=str, default="", help="Type of benchmark"
)
args = parser.parse_args()
run(args.config_path, args.csv_path, args.git_commit, args.log_path, args.test_status_file, args.num_gpus, args.type)
12 changes: 12 additions & 0 deletions regression/benchmark_scripts/configs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Creating configuration and data file

- For each test, create a configuration file and a corresponding data file.
- Refer `test_name_confg.json` for the format of the configuration file.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo in filename reference.

Line 4 references test_name_confg.json but should be test_name_config.json (missing "i").

- Refer `test_name_confg.json` for the format of the configuration file.
+ Refer `test_name_config.json` for the format of the configuration file.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Refer `test_name_confg.json` for the format of the configuration file.
- Refer `test_name_config.json` for the format of the configuration file.
🤖 Prompt for AI Agents
In regression/benchmark_scripts/configs/README.md around line 4, the filename
reference contains a typo: "test_name_confg.json" should be
"test_name_config.json"; update the README to replace the incorrect filename
with the correct one so the referenced example matches the actual file name.

- Supported metrics can be found in `cuopt/regression/benchmark_scripts/utils.py`
- File names should start with test names followed by `config` or data depending on type of it.
- Data file should be as per openapi spec of cuopt server
- These configuration and data files needs to be uploaded to `s3://cuopt-datasets/regression_datasets/`
Copy link
Collaborator

Choose a reason for hiding this comment

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

May be we shouldn't share these details.


```
aws s3 cp /path/to/files s3://cuopt-datasets/regression_datasets/
```
Loading