Skip to content

Commit

Permalink
check gurobi license in co api call
Browse files Browse the repository at this point in the history
  • Loading branch information
asyms committed Sep 23, 2024
1 parent 6bdf709 commit 33c2c2f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions stream/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging as _logging
import os

import gurobipy as gp
from zigzag.stages.main import MainStage
from zigzag.utils import pickle_load, pickle_save

Expand Down Expand Up @@ -31,6 +32,23 @@ def _sanity_check_inputs(hardware: str, workload: str, mapping: str, mode: str,
os.makedirs(output_path)


def _sanity_check_gurobi_license():
try:
# Try to create a simple optimization model
model = gp.Model()
# Check if the model was successfully created (license check)
model.optimize()
# If model.optimize() runs without a license issue, return
return
except gp.GurobiError as e:
# Catch any Gurobi errors, especially licensing errors
if e.errno == gp.GRB.Error.NO_LICENSE:
error_message = "No valid Gurobi license found. Get an academic WLS license at https://www.gurobi.com/academia/academic-program-and-licenses/"
else:
error_message = f"An unexpected Gurobi error occurred: {e.message}"
raise ValueError(error_message)


def optimize_allocation_ga(
hardware: str,
workload: str,
Expand Down Expand Up @@ -96,6 +114,7 @@ def optimize_allocation_co(
skip_if_exists: bool = False,
):
_sanity_check_inputs(hardware, workload, mapping, mode, output_path)
_sanity_check_gurobi_license()

# Output paths
node_hw_performances_path = f"{output_path}/{experiment_id}-saved_cn_hw_cost.pickle"
Expand Down

0 comments on commit 33c2c2f

Please sign in to comment.