Write a conclusion supported by the baseline¶
Run a two-variable QUBO, inspect its Algorithm report and decide what a single experiment establishes. Complete QAOA, VQE and experimental design. Use the installed environment.
This problem differs slightly from the earlier QUBO: f(x) = 0.1 − x0 − 0.6 x1 + 1.2 x0 x1. Its four values are 0.1, −0.5, −0.9, −0.3 in 00,01,10,11 order. Enumeration therefore finds the minimum at 10.
Read three distinct results¶
"""Interpret variational output against a bounded baseline and report facts.
An expert analysis separates best objective evaluation, sampled candidate, and
classical baseline. The standard Algorithm report exposes provenance and
history, but it does not upgrade a bounded comparison into an optimality proof.
"""
from __future__ import annotations
import json
from cascaqit import QAOA, LocalBackend, OptimizerConfig, QUBOProblemIR, visualize
def main() -> None:
"""Run a small QUBO and compare distinct result facts."""
problem = QUBOProblemIR.from_terms(
problem_id="lesson.optimization.analysis",
variables=("x0", "x1"),
linear_terms={"x0": -1.0, "x1": -0.6},
quadratic_terms={("x0", "x1"): 1.2},
offset=0.1,
)
result = QAOA(problem, layers=1).run(
backend=LocalBackend(seed=503),
optimizer=OptimizerConfig(
method="COBYLA", max_iterations=6, max_evaluations=5, seed=503
),
initial_parameters=(0.2, -0.2),
final_shots=64,
)
candidate = result.best_observed_candidate
baseline = result.baseline
assert candidate is not None and baseline is not None
assert result.final_result is not None
report = visualize(result)
payload = {
"track": "optimization_researcher",
"level": "expert",
"lesson": "baseline_analysis",
"facts": {
"objective_estimator": result.metadata["objective_estimator"],
"objective_total_shots": result.metadata["objective_total_shots"],
"workflow_total_shots": result.metadata["workflow_total_shots"],
"backend_executions": result.metadata["workflow_backend_execution_count"],
"final_counts": result.final_result.counts,
"final_probabilities": result.final_result.probabilities,
"candidate_count": candidate.count,
"best_energy": round(result.best_evaluation.energy, 10),
"sampled_candidate": candidate.bitstring,
"candidate_value": candidate.objective_value,
"baseline_bitstring": baseline.bitstring,
"baseline_value": baseline.objective_value,
"optimality_claim": candidate.optimality_claim,
"report_profile": report.profile,
"report_section_count": len(report.sections),
},
"boundaries": {
"hardware_execution": False,
"cloud_execution": False,
"network_accessed": False,
"credentials_loaded": False,
},
}
print(json.dumps(payload, sort_keys=True))
if __name__ == "__main__":
main()
python3 examples/user/tracks/optimization_researcher/05_expert_baseline_analysis_en.py
{
"boundaries": {
"cloud_execution": false,
"credentials_loaded": false,
"hardware_execution": false,
"network_accessed": false
},
"facts": {
"backend_executions": 6,
"baseline_bitstring": "10",
"baseline_value": -0.9,
"best_energy": -0.5609248776,
"candidate_count": 28,
"candidate_value": -0.9,
"final_counts": {
"00": 6,
"01": 16,
"10": 28,
"11": 14
},
"final_probabilities": {
"00": 0.10462979564428168,
"01": 0.32777336608607827,
"10": 0.39537020435571835,
"11": 0.17222663391392173
},
"objective_estimator": "exact_state",
"objective_total_shots": 0,
"optimality_claim": "not_claimed",
"report_profile": "algorithm",
"report_section_count": 7,
"sampled_candidate": "10",
"workflow_total_shots": 64
},
"lesson": "baseline_analysis",
"level": "expert",
"track": "optimization_researcher"
}
| Quantity | Question it answers |
|---|---|
best_energy |
What was the lowest expectation evaluated during this search? |
sampled_candidate, candidate_value |
What was the best objective among strings actually observed? |
baseline_bitstring, baseline_value |
What did the bounded classical comparison find? |
The best energy can remain near −0.56 while the sampled candidate reaches −0.9. These values are consistent: the expectation includes worse strings too. Compute the expectation gap and candidate gap separately by subtracting the baseline value. The candidate gap can be zero while the expectation gap is positive.
For this two-variable problem, enumeration covers all four assignments. Matching that minimum supports the narrow statement that the observed candidate solves this instance. It does not show that QAOA always succeeds, converged, or outperforms classical search. The SDK's candidate field remains not_claimed; it does not automatically convert comparison results into a general optimality claim. For larger problems, inspect baseline.status, method, limit and unavailable_reason before assuming a baseline exists.
visualize(result) creates a report from saved results without rerunning optimization. To save it, change the call to visualize(result, output='artifacts/qubo-analysis.html', language='en'). The printed profile and section count only describe report structure; plots and headings cannot strengthen the experiment's conclusion.
Compare repetitions with an explicit cost¶
Repeat the run with seeds 503, 504, 505, 506, 507, keeping the objective, initial parameters, layers and budgets fixed. Record seed, best energy, candidate value, candidate count, stopping reason, backend executions and total shots in a table. Preserve runs that miss the optimum. Report the number of runs that observed 10 out of five, as well as the within-run frequency; these are different statistics.
Here the exact objective and explicit initial vector make the optimization deterministic. Changing seeds mainly changes final sampling. This exercise measures sampling reliability, not sensitivity to optimizer initialization. To study the latter, vary and record the initial parameter vectors in a separate experiment. Five repeats are a teaching exercise, not a precise reliability estimate.
The example uses five objective evaluations plus one final-sampling job, zero objective shots and 64 total shots. Count the classical enumeration separately: it evaluates four assignments. Backend calls and classical function evaluations have different costs, so their raw counts are not a speed comparison.
Practice writing one supported sentence and one unsupported sentence. A supported statement is that a specified run observed a candidate matching the complete four-state baseline. Claiming a speedup or reliable performance on larger QUBOs requires additional experiments, timings and an appropriate classical comparator. See three routes to MIS for a project that makes comparison assumptions explicit.