curl --request POST \
--url 'https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=' \
--header 'Content-Type: application/json' \
--data '
{
"lp_problem": "Minimize\n obj: x0 + x1\nBinary\n x0\n x1\nEnd",
"params": {
"postprocess_iterations": 10,
"seed": 42
},
"run_job_id": "jb-abc123"
}
'import requests
url = "https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY="
payload = {
"lp_problem": "Minimize
obj: x0 + x1
Binary
x0
x1
End",
"params": {
"postprocess_iterations": 10,
"seed": 42
},
"run_job_id": "jb-abc123"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
lp_problem: 'Minimize\n obj: x0 + x1\nBinary\n x0\n x1\nEnd',
params: {postprocess_iterations: 10, seed: 42},
run_job_id: 'jb-abc123'
})
};
fetch('https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'lp_problem' => 'Minimize
obj: x0 + x1
Binary
x0
x1
End',
'params' => [
'postprocess_iterations' => 10,
'seed' => 42
],
'run_job_id' => 'jb-abc123'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY="
payload := strings.NewReader("{\n \"lp_problem\": \"Minimize\\n obj: x0 + x1\\nBinary\\n x0\\n x1\\nEnd\",\n \"params\": {\n \"postprocess_iterations\": 10,\n \"seed\": 42\n },\n \"run_job_id\": \"jb-abc123\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=")
.header("Content-Type", "application/json")
.body("{\n \"lp_problem\": \"Minimize\\n obj: x0 + x1\\nBinary\\n x0\\n x1\\nEnd\",\n \"params\": {\n \"postprocess_iterations\": 10,\n \"seed\": 42\n },\n \"run_job_id\": \"jb-abc123\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"lp_problem\": \"Minimize\\n obj: x0 + x1\\nBinary\\n x0\\n x1\\nEnd\",\n \"params\": {\n \"postprocess_iterations\": 10,\n \"seed\": 42\n },\n \"run_job_id\": \"jb-abc123\"\n}"
response = http.request(request)
puts response.read_body{
"solutions": [
{}
],
"returned_solutions": 123,
"total_solutions": 123,
"truncated": true,
"context": "<string>",
"best_bitstring": "<string>",
"best_cost": 123
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Postprocess Measurement Counts
Improve sampled QUBO solutions with Haiqu’s classical post-processing.
Use this tool after a QAOA or VQE sampling run to turn noisy measured bitstrings into better solutions. It applies bit-flip local search against the QUBO objective and runs synchronously, so results come back immediately.
When to Use:
- Call this after
run_circuits_on_qpu_or_simulatorreturns counts for a QUBO problem, which is the last step of the QAOA workflow. - Call this when the user asks for the best solution or objective value rather than the raw measurement distribution.
Constraints:
- Provide exactly one of
countsorrun_job_id. Preferrun_job_idso large count dictionaries stay out of the tool call. lp_problemmust be the same objective the circuit was built from, otherwise the reported costs are meaningless.- Only the best
max_solutionssolutions are returned; the response reportstotal_solutionsand setstruncatedwhen it omits some.
Notes:
- Report
best_bitstringandbest_costfirst; the solution list is supporting detail. - Implausible costs usually mean the LP problem does not match the circuit that produced the counts, not a post-processing failure.
Args: user: Authenticated user resolved from the API key. data: Problem definition plus inline counts or a run job reference. db: Active database session.
Returns: The best solutions found, ordered by objective value, with a summary.
Raises:
HTTPException: Raised with 400 when neither or both count inputs are
given, 404 when a referenced job is unavailable, 409 when the
referenced job has no usable counts, or 500 when post-processing
fails.
curl --request POST \
--url 'https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=' \
--header 'Content-Type: application/json' \
--data '
{
"lp_problem": "Minimize\n obj: x0 + x1\nBinary\n x0\n x1\nEnd",
"params": {
"postprocess_iterations": 10,
"seed": 42
},
"run_job_id": "jb-abc123"
}
'import requests
url = "https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY="
payload = {
"lp_problem": "Minimize
obj: x0 + x1
Binary
x0
x1
End",
"params": {
"postprocess_iterations": 10,
"seed": 42
},
"run_job_id": "jb-abc123"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
lp_problem: 'Minimize\n obj: x0 + x1\nBinary\n x0\n x1\nEnd',
params: {postprocess_iterations: 10, seed: 42},
run_job_id: 'jb-abc123'
})
};
fetch('https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'lp_problem' => 'Minimize
obj: x0 + x1
Binary
x0
x1
End',
'params' => [
'postprocess_iterations' => 10,
'seed' => 42
],
'run_job_id' => 'jb-abc123'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY="
payload := strings.NewReader("{\n \"lp_problem\": \"Minimize\\n obj: x0 + x1\\nBinary\\n x0\\n x1\\nEnd\",\n \"params\": {\n \"postprocess_iterations\": 10,\n \"seed\": 42\n },\n \"run_job_id\": \"jb-abc123\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=")
.header("Content-Type", "application/json")
.body("{\n \"lp_problem\": \"Minimize\\n obj: x0 + x1\\nBinary\\n x0\\n x1\\nEnd\",\n \"params\": {\n \"postprocess_iterations\": 10,\n \"seed\": 42\n },\n \"run_job_id\": \"jb-abc123\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/ai/postprocess_measurement_counts?HAIQU_API_KEY=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"lp_problem\": \"Minimize\\n obj: x0 + x1\\nBinary\\n x0\\n x1\\nEnd\",\n \"params\": {\n \"postprocess_iterations\": 10,\n \"seed\": 42\n },\n \"run_job_id\": \"jb-abc123\"\n}"
response = http.request(request)
puts response.read_body{
"solutions": [
{}
],
"returned_solutions": 123,
"total_solutions": 123,
"truncated": true,
"context": "<string>",
"best_bitstring": "<string>",
"best_cost": 123
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Body
Define payload for post-processing QUBO measurement counts.
Attributes:
lp_problem: Unconstrained quadratic problem in LP file format.
counts: Measured bitstring counts to optimize.
run_job_id: Run job whose stored results supply counts.
params: Optional post-processing parameter overrides.
max_solutions: Cap on how many solutions are returned inline.
Response
Successful Response
Represent post-processed QUBO solutions, truncated for tool output.
Attributes:
best_bitstring: Lowest-cost solution found.
best_cost: Objective value of best_bitstring.
solutions: Best solutions as bitstring / cost / count
entries, ordered by cost.
returned_solutions: Number of entries in solutions.
total_solutions: Number of solutions the post-processor produced.
truncated: Whether solutions omits some results.
context: Summary of the outcome and how to read it.