Python Async gRPC Client API Reference#
Import path: cuopt.grpc.linear_programming.
Client#
- class cuopt.grpc.linear_programming.Client(str host, int port, tls=None, *)#
Methods
cancel(self, str job_id)Request cancellation of a running job.
delete(self, str job_id)Cancel
job_idif it is still running, then delete it on the server and release its state.incumbents(self, str job_id[, from_index])Return incumbent solutions collected so far (or all remaining).
join_incumbent_stream(self, str job_id[, ...])Wait for the background incumbent-stream thread started by
start_incumbent_stream().join_log_stream(self, str job_id[, timeout])Wait for the background log-stream thread started by
start_log_stream().logs(self, str job_id[, from_byte])Return all solver log lines for a job that has finished.
result(self, str job_id[, variable_names])Fetch the solution for a completed job, or
Noneif not ready.start_incumbent_stream(self, str job_id, ...)Poll for MIP incumbent solutions on a background thread until the job completes.
start_log_stream(self, str job_id[, ...])Stream solver logs on a background thread until the job completes.
status(self, str job_id)Return the current
JobStatusforjob_idwithout blocking.submit(self, problem, SolverSettings settings)Submit a problem for solving and return its
job_id.wait(self, str job_id[, timeout])Block until
job_idreaches a terminal state and return itsJobStatus.- cancel(self, str job_id)#
Request cancellation of a running job. The job moves to
JobStatus.CANCELLED; calldelete()to release its state.
- delete(self, str job_id)#
Cancel
job_idif it is still running, then delete it on the server and release its state. Joins any client-side incumbent-stream thread for this job first. Call once you no longer need the job’s result or logs.
- incumbents(self, str job_id, from_index=0)#
Return incumbent solutions collected so far (or all remaining).
Works while the job is running or after it completes. Each entry is a dict with
index,objective, andassignment(list of floats).
- join_incumbent_stream(self, str job_id, timeout=None)#
Wait for the background incumbent-stream thread started by
start_incumbent_stream().
- join_log_stream(self, str job_id, timeout=None)#
Wait for the background log-stream thread started by
start_log_stream().Returns a dict when a thread was started for
job_id, elseNone. Useful keys:lines— list of log line strings collected so farlive_lines— count of lines received from the live stream threadbackfilled—Trueif the live stream received no lines and this method then calledlogs()as a client-side fallback to filllines(and re-invoke the callback). That fetch is not destructive; the server keeps the log untildelete().
Other keys in the dict are internal; do not rely on them.
- logs(self, str job_id, from_byte=0)#
Return all solver log lines for a job that has finished.
Raises
JobNotReadyErrorif the job is still queued or running. For live output during the solve, usestart_log_stream().
- result(self, str job_id, variable_names=None)#
Fetch the solution for a completed job, or
Noneif not ready.LP vs MIP is determined from the server response (via
grpc_client_t::get_result). Passvariable_names(column order) to keysolution.get_vars()by name. RaisesGrpcErrorif the job failed or was cancelled.
- start_incumbent_stream(
- self,
- str job_id,
- settings,
- from_index=0,
- poll_interval_ms=1000,
Poll for MIP incumbent solutions on a background thread until the job completes.
Pass
settingswithGetSolutionCallbackinstances registered viaset_mip_callback()(same as local solve).Call
join_incumbent_stream()beforedelete().
- start_log_stream(self, str job_id, callback=print, from_byte=0)#
Stream solver logs on a background thread until the job completes.
callbackis invoked ascallback(line, job_complete)for each line. ReturnFalseexplicitly to stop early; other return values (includingNonefromprint) keep the stream open.Call
join_log_stream()beforedelete()to ensure all log lines were received. To collect lines in memory:lines = [] client.start_log_stream(job_id, lines.append)
- submit(self, problem, SolverSettings settings)#
Submit a problem for solving and return its
job_id.problemis aProblemorDataModel. The job runs asynchronously; usewait()orstatus()to track it andresult()to fetch the solution. Alwaysdelete()when done.
- wait(self, str job_id, timeout=None)#
Block until
job_idreaches a terminal state and return itsJobStatus.timeoutis in whole seconds.Nonewaits indefinitely. Non-Nonevalues are converted withint(timeout)(so0.5becomes0and waits indefinitely). Positive timeouts poll about once per second and raiseGrpcErrorif the deadline expires (they do not return a non-terminalJobStatus).
Supporting Types#
- class cuopt.grpc.linear_programming.TlsConfig(root_certs=None, client_cert=None, client_key=None)#
TLS / mTLS settings for
Client.Each PEM argument may be PEM text or a path to a PEM file. For mTLS, pass both
client_certandclient_key. Whenroot_certsis omitted, the client uses the system/default CA trust store.Attributes
client_cert
client_key
root_certs
- client_cert#
- client_key#
- root_certs#
Exceptions#
- exception cuopt.grpc.linear_programming.GrpcError#
Bases:
RuntimeError
See also#
Python Async gRPC Client — overview and when to use this client
Python Async gRPC Client Examples — log and incumbent streaming examples
gRPC API (Reference) —
CuOptRemoteServiceproto / RPC reference