quicopt.client¶
client ¶
quicopt.client — talk to the Quicopt service over HTTP.
Encode a model to wire bytes (quicopt.wire), POST it, read the result back.
Stdlib-only (urllib): the transport adds no dependency, like the rest of the
core. The request body is the versioned wire bytes; the response is the service's
result JSON (status / objective / solution / a ready-to-print
display / …). The first keyless call mints an API key, returned in the
X-Quicopt-Api-Key response header and remembered on the :class:Client so
later calls replay it as Authorization: Bearer.
Two entry points mirror the two service endpoints:
- :meth:
Client.solve— POST/v1/solve, block for the result (synchronous). - :meth:
Client.submit— POST/v1/jobs, return a :class:Jobto poll.
A non-2xx response raises :class:QuicoptError, carrying the service's stable
reason code and the framed display text.
Result
dataclass
¶
Result(
job_id: str,
status: str,
objective: Optional[float],
feasible: Optional[bool],
solution: Dict[str, float],
solve_time_seconds: float,
solver_data: Dict[str, Any],
display: str,
)
A finished solve, parsed from the service's result JSON. objective and
feasible are None when the class or outcome leaves them undefined
(e.g. an unconstrained heuristic, or no incumbent). display is the framed,
ready-to-print summary the service renders for every backend alike.
model_class
property
¶
The class the service routed the model to (LP/MILP/QUBO/…).
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The |
Optional[str]
|
service did not report one. |
QuicoptError ¶
Bases: Exception
A non-2xx service response. reason is the service's stable snake_case
code (size_exceeded, unsupported_model, quota_exhausted, …),
display the framed message to print, status_code the HTTP status.
Source code in src/quicopt/client.py
Client ¶
A connection to a Quicopt service at base_url. Holds the API key: pass
a known one, or let the first keyless call mint one (then read it back from
client.api_key to persist).
Bind a client to a service endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The service base URL; a trailing slash is stripped. |
required |
api_key
|
Optional[str]
|
A known API key, or |
None
|
timeout
|
float
|
Per-request socket timeout, in seconds. |
60.0
|
Source code in src/quicopt/client.py
solve ¶
solve(
model: _Model,
*,
config: Optional[Dict[str, Any]] = None,
gzip: bool = False
) -> Result
Solve model synchronously, blocking until the result returns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
_Model
|
A front-end model (Pyomo, OR-Tools MathOpt) — imported to the
wire IR here — or a |
required |
config
|
Optional[Dict[str, Any]]
|
Optional service parameters, sent as the query string. |
None
|
gzip
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
The finished solve. |
Raises:
| Type | Description |
|---|---|
QuicoptError
|
On a non-2xx response. |
Source code in src/quicopt/client.py
submit ¶
Submit model for asynchronous solving and return a handle to poll.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
_Model
|
A Pyomo/MathOpt model, a |
required |
config
|
Optional[Dict[str, Any]]
|
Optional service parameters, sent as the query string. |
None
|
gzip
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Job |
'Job'
|
A handle to the queued job; call :meth: |
Raises:
| Type | Description |
|---|---|
QuicoptError
|
On a non-2xx response. |
Source code in src/quicopt/client.py
Job
dataclass
¶
Job(client: Client, job_id: str)
A handle to an async job. :meth:result polls until it finishes.
status ¶
Fetch the job's metadata and framed log_tail.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
The job state ( |
Dict[str, Any]
|
log tail, as returned by the service. |
Source code in src/quicopt/client.py
result ¶
result(
*,
wait: bool = True,
timeout: float = 120.0,
poll: float = 0.5
) -> Result
Fetch the job's result, optionally polling until it is ready.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait
|
bool
|
If |
True
|
timeout
|
float
|
Maximum time to poll, in seconds, before giving up. |
120.0
|
poll
|
float
|
Delay between polls, in seconds. |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
The finished solve. |
Raises:
| Type | Description |
|---|---|
QuicoptError
|
If |
Source code in src/quicopt/client.py
log ¶
Fetch the job's plain-text log.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The framed log view on success, or the error text on failure. |
delete ¶
Delete the job and its stored blob/result/log on the server.
Returns:
| Type | Description |
|---|---|
None
|
None. |