From 33c2c2f7b6bbdeb096036c79094d0826ecb3a989 Mon Sep 17 00:00:00 2001 From: Arne Symons Date: Mon, 23 Sep 2024 17:16:38 +0200 Subject: [PATCH] check gurobi license in co api call --- stream/api.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/stream/api.py b/stream/api.py index c3b91ff..90d1e25 100644 --- a/stream/api.py +++ b/stream/api.py @@ -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 @@ -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, @@ -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"