Try our new documentation site (beta).
Next: Interpreting the JSON Solution Up: Batch Optimization Previous: Submitting a Batch Optimization
Interacting with Batch Requests
You can use a BatchID string to ask the Cluster Manager for more information about the corresponding batch. Specifically, you can query the BatchStatus for that batch, and if the batch is complete you can retrieve the computed solution as a JSON string.
Your first step in using a BatchID
to gather more information
is to create a Gurobi environment that enables you to connect to your
Cluster Manager. This is done in this line of our Python example:
with setupbatchenv().start() as env, gp.Batch(batchID, env) as batch:The
setupbatchenv
method creates an environment with the
CSManager,
UserName, and
ServerPassword parameters
set to appropriate values.
With this environment and our BatchID
, we can now create a
Batch object (by calling the
Batch
constructor in the above code segment) that holds
information about the batch.
That Batch object can be used to
query the BatchStatus:
# Setup and start environment, create local Batch handle object with setupbatchenv().start() as env, gp.Batch(batchID, env) as batch: starttime = time.time() while batch.BatchStatus == GRB.BATCH_SUBMITTED: # Abort this batch if it is taking too long curtime = time.time() if curtime - starttime > maxwaittime: batch.abort() break # Wait for two seconds time.sleep(2) # Update the resident attribute cache of the Batch object with the # latest values from the cluster manager. batch.update() # If the batch failed, we retry it if batch.BatchStatus == GRB.BATCH_FAILED: batch.retry()It can also be used to perform various operations on the batch, including aborting or retrying the batch.
Once a batch has been completed, you can query the solution and all
related attributes for tagged elements in the model by retrieving the
associated JSON solution string (or by
saving it into a file):
print("JSON solution:") # Get JSON solution as string, create dict from it sol = json.loads(batch.getJSONSolution())
By default, the Cluster Manager will keep the solution for the model
and other information for a while (the exact retention policy is set
by the Cluster Manager). You can ask the Cluster Manager to discard
information for a batch by explicitly calling the discard
method:
# Remove batch request from manager batch.discard()No further queries on that batch are possible after this has been done.
Next: Interpreting the JSON Solution Up: Batch Optimization Previous: Submitting a Batch Optimization