|
1 | 1 | import math |
2 | 2 | import statistics |
3 | 3 | import networkx as nx |
| 4 | +import numpy as np |
4 | 5 | import rustworkx as rx |
5 | 6 | from scipy import stats |
6 | 7 | from dataclasses import dataclass |
|
18 | 19 | Benchmark, |
19 | 20 | BenchmarkData, |
20 | 21 | BenchmarkResult, |
| 22 | + BenchmarkScore, |
21 | 23 | ) |
22 | 24 | from metriq_gym.helpers.task_helpers import flatten_counts |
23 | 25 | from metriq_gym.qplatform.device import connectivity_graph |
@@ -168,9 +170,12 @@ class LinearRampQAOAResult(BenchmarkResult): |
168 | 170 | approx_ratio: list[float] |
169 | 171 | random_approx_ratio: float = Field(...) |
170 | 172 | confidence_pass: list[bool] |
| 173 | + effective_approx_ratio: list[float] | None = None |
171 | 174 |
|
172 | | - def compute_score(self) -> float | None: |
173 | | - return self.approx_ratio[0] |
| 175 | + def compute_score(self) -> BenchmarkScore: |
| 176 | + if not self.effective_approx_ratio: |
| 177 | + raise ValueError("effective_approx_ratio must be populated to compute score.") |
| 178 | + return BenchmarkScore(value=float(np.mean(self.effective_approx_ratio))) |
174 | 179 |
|
175 | 180 |
|
176 | 181 | def prepare_qaoa_circuit( |
@@ -232,6 +237,7 @@ class AggregateStats: |
232 | 237 | optimal_probability: list[float] |
233 | 238 | approx_ratio: list[float] |
234 | 239 | confidence_pass: list[bool] |
| 240 | + effective_approx_ratio: list[float] |
235 | 241 |
|
236 | 242 |
|
237 | 243 | def calc_trial_stats( |
@@ -317,13 +323,18 @@ def calc_stats(data: LinearRampQAOAData, samples: list["MeasCount"]) -> Aggregat |
317 | 323 | all(stat[ith_layer].confidence_pass for stat in trial_stats) |
318 | 324 | for ith_layer in range(len(data.qaoa_layers)) |
319 | 325 | ] |
| 326 | + effective_approx_ratio = [ |
| 327 | + (r - data.approx_ratio_random_mean) / (1 - data.approx_ratio_random_mean) |
| 328 | + for r in approx_ratio |
| 329 | + ] |
320 | 330 |
|
321 | 331 | return AggregateStats( |
322 | 332 | trial_stats=trial_stats, |
323 | 333 | trials=num_trials, |
324 | 334 | approx_ratio=approx_ratio, |
325 | 335 | optimal_probability=optimal_probability, |
326 | 336 | confidence_pass=confidence_pass, |
| 337 | + effective_approx_ratio=effective_approx_ratio, |
327 | 338 | ) |
328 | 339 |
|
329 | 340 |
|
@@ -403,7 +414,9 @@ def _build_circuits( |
403 | 414 | return circuits_with_params, graph_info, optimal_sol, circuit_encoding |
404 | 415 |
|
405 | 416 | def dispatch_handler(self, device: "QuantumDevice") -> LinearRampQAOAData: |
406 | | - circuits_with_params, graph_info, optimal_sol, circuit_encoding = self._build_circuits(device) |
| 417 | + circuits_with_params, graph_info, optimal_sol, circuit_encoding = self._build_circuits( |
| 418 | + device |
| 419 | + ) |
407 | 420 |
|
408 | 421 | approx_ratio_random_mean, approx_ratio_random_std = calc_random_stats( |
409 | 422 | self.params.num_qubits, |
@@ -443,6 +456,7 @@ def poll_handler( |
443 | 456 | approx_ratio=stats.approx_ratio, |
444 | 457 | random_approx_ratio=job_data.approx_ratio_random_mean, |
445 | 458 | confidence_pass=stats.confidence_pass, |
| 459 | + effective_approx_ratio=stats.effective_approx_ratio, |
446 | 460 | ) |
447 | 461 |
|
448 | 462 | def estimate_resources_handler( |
|
0 commit comments