quicopt.wire¶
wire ¶
quicopt.wire — a Program → the bytes the service reads.
Encoding is deterministic: the same model always produces the same bytes, and they
are the bytes the service produces for that model too — checked against committed
goldens in tests/test_wire_golden.py. The encoder uses nothing outside the
standard library, like the rest of the package.
Example
import pulp
from quicopt import Client
from quicopt.pulp import import_model
from quicopt.wire import encode
prob = pulp.LpProblem("mix", pulp.LpMaximize)
x = pulp.LpVariable("x", lowBound=0, upBound=4)
y = pulp.LpVariable("y", cat="Binary")
prob += 3 * x + 5 * y
prob += x + 2 * y <= 5
body = encode(import_model(prob)) # 209 bytes
result = Client(api_key="…").solve(body) # bytes solve like a model
print(result.status, result.objective) # optimal 14.0
Encoding is normally invisible: Client.solve
does it for you, and what it POSTs is exactly these bytes. Reach for encode
to send them yourself, store them, or check them — and note that
solve takes the bytes back, so an encoded model is a portable artifact,
not an internal step.
body is the whole request: no session, no dialect, no order the encoder
gets to choose. That is what makes "the bytes are identical" a testable claim
rather than a hope, and it is what tests/test_wire_golden.py checks
against committed goldens.
encode ¶
encode(prog: Program) -> bytes
Encode a Program to the (v1) bytes the service reads.
Two equal Programs always encode to equal bytes, whichever order their tables happened to be built in. A model that declares no uncertainty, no structure and no block encodes to exactly the bytes it would have before any of them existed, so none of them costs an ordinary model anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prog
|
Program
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The message, deterministic and identical byte for byte to what the |
bytes
|
Quicopt service produces for the same model. |
Source code in src/quicopt/wire.py
encode_params ¶
Encode just the Param tables as a standalone ParamData message.
This is how data is rebound without resending the model: send the Program
once, then one ParamData per instance. Tables are written in sorted-key
order, so the same data always encodes to the same bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
A mapping |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The encoded |