GRBBatch#
- GRBBatch#
Gurobi batch object. Batch optimization is a feature available with the Gurobi Cluster Manager. It allows a client program to build an optimization model, submit it to a Compute Server cluster (through a Cluster Manager), and later check on the status of the model and retrieve its solution. For more information, please refer to the Batch Optimization section.
Commonly used methods on batch objects include
Update
(refresh attributes from the Cluster Manager),Abort
(abort execution of a batch request),Retry
(retry optimization for an interrupted or failed batch),Discard
(remove the batch request and all related information from the Cluster Manager), andGetJSONSolution
(query solution information for the batch request).These methods are built on top of calls to the Cluster Manager REST API. They are meant to simplify such calls, but note that you always have the option of calling the REST API directly.
Batch objects have four attributes:
BatchID: Unique ID for the batch request.
BatchStatus: Last batch status. Status values are described in the Batch Status Code section.
BatchErrorCode: Last error code.
BatchErrorMessage: Last error message.
You can access their values ,
batch.BatchStatus
orbatch.BatchID
, or by usingGet
. Note that all Batch attributes are locally cached, and are only updated when you create a client-side batch object or when you explicitly update this cache, which can done by callingUpdate
.- GRBBatch GRBBatch(GRBEnv& env, string& batchID)#
Constructor for
GRBBatch
.Given a
BatchID
, as returned byoptimizeBatch
, and a Gurobi environment that can connect to the appropriate Cluster Manager (i.e., one where parameters CSManager, UserName, and ServerPassword have been set appropriately), this function returns aGRBBatch
object. With it, you can query the current status of the associated batch request and, once the batch request has been processed, you can query its solution. Please refer to the Batch Optimization section for details and examples.- Parameters:
env – The environment in which the new batch object should be created.
batchID – ID of the batch request for which you want to access status and other information.
- Returns:
New batch object.
- Example:
GRBBatch batch = GRBBatch(env, batchID);
- void Abort()#
This method instructs the Cluster Manager to abort the processing of this batch request, changing its status to ABORTED. Please refer to the Batch Status Codes section for further details.
- Example:
// Abort this batch if it is taking too long TimeSpan interval = DateTime.Now - start; if (interval.TotalSeconds > maxwaittime) { batch.Abort(); break; }
- void Discard()#
This method instructs the Cluster Manager to remove all information related to the batch request in question, including the stored solution if available. Further queries for the associated batch request will fail with error code DATA_NOT_AVAILABLE. Use this function with care, as the removed information can not be recovered later on.
- Example:
// Remove batch request from manager batch.Discard();
- string GetJSONSolution()#
This method retrieves the solution of a completed batch request from a Cluster Manager. The solution is returned as a JSON solution string. For this call to succeed, the status of the batch request must be COMPLETED. Note further that the result file stored Cluster Manager side must be gzip-compressed and exactly one result file should be associated with this batch; for batches submitted programmatically through the API both will be the case. Please refer to the Batch Status Codes section for further details.
- Returns:
The requested solution in JSON format.
- Example:
// Get JSON solution as string Console.WriteLine("JSON solution:" + batch.GetJSONSolution());
- int Get(GRB.IntAttr attr)#
Query the value of an int-valued batch attribute.
- Parameters:
attr – The attribute being queried.
- Returns:
The current value of the requested attribute.
- string Get(GRB.StringAttr attr)#
Query the value of a string-valued batch attribute.
- Parameters:
attr – The attribute being queried.
- Returns:
The current value of the requested attribute.
- void Retry()#
This method instructs the Cluster Manager to retry optimization of a failed or aborted batch request, changing its status to SUBMITTED. Please refer to the Batch Status Codes section for further details.
- Example:
// If the batch failed, we retry it if (batch.BatchStatus == GRB.BatchStatus.FAILED) { batch.Retry(); System.Threading.Thread.Sleep(2000); batch.Update(); }
- void Update()#
All Batch attribute values are cached locally, so queries return the value received during the last communication with the Cluster Manager. This method refreshes the values of all attributes with the values currently available in the Cluster Manager (which involves network communication).
- Example:
// Update the resident attribute cache of the Batch object // with the latest values from the cluster manager. batch.Update();
- void WriteJSONSolution(string& filename)#
This method returns the stored solution of a completed batch request from a Cluster Manager. The solution is returned in a gzip-compressed JSON file. The file name you provide must end with a .json.gz extension. The JSON format is described in the JSON solution format section. Note that for this call to succeed, the status of the batch request must be COMPLETED. Note further that the result file stored Cluster Manager side must be gzip-compressed and exactly one result file should be associated with this batch; for batches submitted programmatically through the API both will be the case. Please refer to the Batch Status Codes section for further details.
- Parameters:
filename – Name of file where the solution should be stored (in JSON format).
- Example:
// Write the full JSON solution string to a file batch.WriteJSONSolution("batch-sol.json.gz");