Solving
Requests with many solves
A request with then, expand or boards starts many solves. This page shows how to send many boards, follow the progress of a request, read its solves and stop it.
In short
- A request with
then,expandorboardsstarts many solves. The first solve is the root: budgets, progress and cancel work through it. - Follow the progress in
treeon the root. Wait untiltree.statusis notrunning. - Read the solves with
GET /v1/solves/{id}/children. - Stop a request with
POST /v1/solves/{id}/cancel. Solves that wait are not charged.
Many boards in one request
Send boards in place of board to solve the same pot, stack, ranges and sizes on each board. All boards must be the same street, and each board one time.
The most is 2,000 boards. then and expand apply to each board.
jq '{boards: [["As", "Ks", "7h"], ["Qd", "Jd", "2c"]], pot, stack, ranges}' spot.json > boards.json
curl -sS -X POST "$GECKO_API/v1/solves" \
-H "Authorization: Bearer $GECKO_KEY" -H "Content-Type: application/json" -H "Prefer: wait=30" \
-d @boards.json | tee batch.json | jq '{id, object, tree}'
# the root of the request, for the samples below
ROOT=$(jq -r .id batch.json)
batch = wait_for(call("POST", "/v1/solves", headers=WAIT, json={
"boards": [["As", "Ks", "7h"], ["Qd", "Jd", "2c"]],
"pot": spot["pot"], "stack": spot["stack"], "ranges": spot["ranges"],
}))
print(batch["object"], batch["tree"]["status"], batch["tree"]["solves"]["complete"])
const batch = await waitFor(await call("POST", "/v1/solves", {
headers: wait,
body: { boards: [["As", "Ks", "7h"], ["Qd", "Jd", "2c"]], pot: spot.pot, stack: spot.stack, ranges: spot.ranges },
}));
console.log(batch.object, batch.tree.status, batch.tree.solves.complete);
The answer is a root with "object": "batch". The root is not a solve: it has no result (409 not_a_solve) and costs nothing itself. Its tree block shows the progress, and the solve of each board is under it at GET /v1/solves/{id}/children.
The answer: a root with "object": "batch"
{
"id": "slv_00VcT5MXzAQu86SGrfuI0",
"object": "batch",
"status": "complete",
"street": "batch",
"board": [],
"boards": 2,
"credits": 0,
"result": null,
"tree": {
"status": "running", "stop_reason": null, "estimated_credits": 2, "credits_charged": 1, "max_credits": 20000,
"solves": {"pending": 1, "queued": 0, "running": 1, "complete": 0, "failed": 0, "skipped": 0, "cancelled": 0}
}
}
Follow the progress: the tree block
The root solve of a request with then, expand or boards has a tree block. The top-level status is that of the first solve alone.
tree.status is that of the request. Wait on tree.status.
{
"id": "slv_00VcT6pkVcfEJgZf5uvIA",
"status": "complete",
"tree": {
"status": "stopped",
"stop_reason": "max_credits",
"estimated_credits": 181,
"credits_charged": 100,
"max_credits": 100,
"solves": {"pending": 0, "queued": 0, "running": 0, "complete": 100, "failed": 0, "skipped": 81, "cancelled": 0}
}
}
Every field of the tree block
statusrunning: solves wait or run.complete: every solve reached a final state.stopped: the request ended early;stop_reasonsays why.cancelled: you cancelled it. The last three are final.stop_reasonmax_credits(the budget of the request),insufficient_credits(no calls left),credit_limit(a limit of the key or the account),account_suspendedorcancelled.nullwhile the request runs and when it completes.estimated_credits,credits_charged,max_credits- The estimate made when the request came in, what is charged so far, and the budget.
solves- The number of solves in each state.
problems- Present when a named line was not found under a solved street: the messages. This can happen when the real solve left out a line that no hand reaches.
A request that stopped or was cancelled keeps what is finished. To go on, send one parent request for each line and card that is missing. A new send of the whole body pays again for what is done.
Read the solves of a request
GET /v1/solves/{id}/children lists the next-street solves under a solve, in pages. Each one is a solve with its own result.
The query fields: scope, status, limit, after
scopechildren(default): the solves one street below this solve.tree: every solve of the request this solve belongs to, all streets, without the root.status- Only solves in this state, for example
complete. A value that is not a state gives an empty list. limit- 1 to 500. Default 100.
after- The
nextvalue of the page before. Stop whennextisnull:nextis set only when more rows exist.
curl -sS "$GECKO_API/v1/solves/$ROOT/children?scope=tree&status=complete&limit=500" \
-H "Authorization: Bearer $GECKO_KEY" | jq '{count: (.data | length), next}'
def all_solves(request_id, status="complete"):
"""Every solve under the root of a request, page by page."""
after = None
while True:
page = call("GET", f"/v1/solves/{request_id}/children", headers=AUTH,
params={"scope": "tree", "status": status, "limit": 500, "after": after})
yield from page["data"]
after = page["next"]
if after is None:
return
for solve in all_solves(batch["id"]):
print(solve["street"], solve["board"], solve["line"], solve["result"])
// Every solve under the root of a request, page by page.
async function* allSolves(requestId, status = "complete") {
let after = null;
do {
const query = new URLSearchParams({ scope: "tree", status, limit: "500" });
if (after) query.set("after", after);
const page = await call("GET", `/v1/solves/${requestId}/children?${query}`);
yield* page.data;
after = page.next;
} while (after);
}
for await (const solve of allSolves(batch.id)) {
console.log(solve.street, solve.board, solve.line, solve.result);
}
Stop a request
POST /v1/solves/{id}/cancel stops the whole request, also when you name a solve under the root. Solves that wait are cancelled and not charged.
A solve that runs finishes and is charged. What is finished stays readable.
curl -sS -X POST "$GECKO_API/v1/solves/$ROOT/cancel" -H "Authorization: Bearer $GECKO_KEY" | jq '.tree'
stopped = call("POST", f"/v1/solves/{batch['id']}/cancel", headers=AUTH)
print(stopped["tree"]["status"], stopped["tree"]["solves"]["cancelled"])
const stopped = await call("POST", `/v1/solves/${batch.id}/cancel`);
console.log(stopped.tree.status, stopped.tree.solves.cancelled);
What the answer holds
The answer is the root of the request with its tree, whichever solve of the request you named. tree.status is "cancelled" when solves were still waiting.
After a stop, the solves that will not run are counted as skipped or cancelled at once, never as pending. A request that was already finished is returned as it is.
Look it up
List your requests
GET /v1/solves
GET /v1/solves lists your requests, newest first: one row for each root. limit is 1 to 200 (default 50). For the next page send after with the next value of the page before.