Gemini 2.5 Flash Beats GPT-4o Detecting Quantum Software's Costliest Hidden Bug
Researchers built an LLM pipeline that found 25 hidden flaky tests in quantum software repos and can classify their root causes with 94% F1-score
ProTakeaways
- New pipeline found 25 hidden flaky tests in 12 quantum software repos (Qiskit, NetKet, etc.), growing the only known dataset by 54% to 71 confirmed cases.
- Google Gemini 2.5 Flash achieved the best results: F1=0.9420 for flakiness detection and F1=0.9643 for root-cause identification across 7 LLMs tested.
- Randomness (unseeded PRNGs) is the #1 cause of quantum flaky tests at 19.2%, unlike classical software where concurrency dominates -- fix is usually adding a constant seed.
- Method-level code context beats full-file context for LLM recall -- models perform better when shown only the relevant method, not the entire codebase.
- Root cause classification remains hard -- all models score between 0.40-0.65 F1 on the 9-class taxonomy, making full automation still out of reach.
- Dataset and pipeline are open on Zenodo; future work targets automated patch generation and dynamic test re-execution on simulators.
Quantum software has a testing problem that most developers don't know about. Unlike classical code, quantum programs are inherently probabilistic -- the same circuit can produce different measurement outcomes on different runs. That randomness bleeds into test suites, creating a class of bugs called quantum flaky tests: tests that pass or fail without any code changes, making it nearly impossible to tell whether a failure is a real regression or just noise.

A new paper from researchers at Toronto Metropolitan University and the University of Maryland, Baltimore County takes on this problem directly. The team built an automated pipeline that mines GitHub issue reports and pull requests from quantum software repositories, uses embedding-based similarity search to surface previously unknown flaky tests, and then deploys LLMs to classify whether a report is flaky and to identify the root cause -- all without re-running a single test.
Why quantum flakiness is its own beast
Flaky tests are not new. At Google, in 2014, 73K out of 1.6M (4.56%) of test failures were caused by flaky tests; in 2017, 1.5% of 4.2M tests were flaky. Classical tooling like iDFlakies and FlakeFlagger has been developed to handle this in traditional codebases. But quantum software introduces three compounding challenges that make those tools insufficient:
- Probabilistic by design. Quantum software's inherently probabilistic outputs make it susceptible to quantum flakiness -- tests that pass or fail inconsistently without code changes.
- Hardware noise. On real quantum hardware, decoherence and gate errors introduce additional variability that makes it hard to distinguish genuine regressions from hardware-induced fluctuations.
- Expensive to reproduce. Diagnosing flakiness normally means re-running a test many times. On IBM's quantum platform, that costs $96 USD per minute with limited queue availability -- making brute-force detection economically impractical.
Quantum flakiness remained largely unexplored due to the lack of available datasets. The prior state of the art was a manually curated set of 46 flaky test reports scraped from 14 open-source quantum repositories using keyword search -- a method that is both slow and low-recall.
The pipeline: embeddings first, LLMs second
The core innovation is a two-stage detection pipeline. First, the team uses a pre-trained embedding model (mixedbread-ai/mxbai-embed-large-v1) to convert all GitHub issue reports and pull requests into dense vector representations. They then compute cosine similarity between each new report and the known flaky test cases from the prior dataset. Reports that score above a threshold are flagged as candidates and reviewed by at least two authors.
This iterative process ran in two passes:
- The first pass identified 15 new flaky tests from the top cosine similarity scores.
- Those 15 were added to the seed set, and a second pass found 10 more.
In total, they identified 25 new flaky tests across the 12 repositories, increasing the original dataset size by 54%. The full dataset now covers 71 confirmed flaky tests drawn from 8,628 closed issue reports -- an observed flakiness rate of about 0.82%.
Once the dataset was expanded, the team fed issue descriptions, PR comments, and code diffs into a suite of seven LLMs to answer two questions: (1) is this report flaky at all, and (2) if so, what is the root cause? They used LangChain to manage prompt construction and conversational context, testing four combinations of text context (partial vs. full issue thread) crossed with two levels of code context (method-level vs. full file).
What actually causes quantum tests to flake
The expanded dataset reveals a taxonomy of eight root cause categories. The distribution is telling:
- Randomness (19.2%): Unseeded pseudo-random number generators (PRNGs) are the top culprit. A test calling
random_circuit(num_qubits, depth)without a fixed seed will produce a different circuit on every run, making assertions non-deterministic. The fix is almost always addingseed=4200(or any constant) to the call. - Multi-threading (13.7%): Parallel builds and concurrent jobs create race conditions. One Qiskit example showed
sphinx-build -j autocausing address collisions; the fix was removing the-j autoflag. - Software environment (11.0%): Tests that fail only on specific Python versions or CI runners (e.g., GitHub Actions Python 3.10) but pass locally.
- Floating point operations (9.6%): Hard-coded tolerance values like
abs=1e-5fail intermittently when numerical precision varies across hardware. The fix is computing tolerance dynamically from the result's own error estimate. - Network issues (8.2%), unhandled exceptions (5.5%), visualization bugs (5.5%), and unordered collections (1.4%) round out the taxonomy.
Notably, the most common root cause is Randomness (19.2% of cases), and its most common fix is to fix the seed (16.4% of all fixes). Compared to classical flakiness, the leading causes are async waits and concurrency. This mirrors findings from probabilistic and ML software, where randomness dominates -- not concurrency.
Gemini 2.5 Flash wins the benchmark
The team evaluated seven models: GPT-4o, GPT-4o-mini, GPT-4.1-mini, LLaMA 3.1 70B, LLaMA 3.1 405B, Gemini 2.5 Flash, and Claude 4 Haiku. Performance was measured using F1-score and Matthews Correlation Coefficient (MCC) -- a metric that accounts for class imbalance better than accuracy alone.
For both partial and full context, Gemini 2.5 Flash ranks as best-performing with an F1-score of 0.9420 and an MCC of 0.8887 for flakiness detection. For root-cause identification, Gemini achieves an F1 of 0.9643 with full context. The result is somewhat counterintuitive -- GPT-4o is generally considered the stronger general-purpose model, but Gemini's reasoning capabilities appear better suited to this specialized task.
A few other findings from the model comparison:
- Method-level code context (
C_p) consistently outperforms full-file context (C_f) for recall -- models, like human engineers, get confused when shown an entire codebase rather than the relevant method. - Full issue threads (including all comments) generally improve performance over just the initial description.
- Few-shot prompting via cosine-ranked similar examples improved recall for most models, with GPT-4o-mini gaining +0.047 on partial context.
- Root cause classification is the hardest task -- all models drop significantly compared to binary flakiness detection, with most scoring between 0.40 and 0.65 F1.
- Fine-tuned CodeBERT was also tested but failed to generalize to the GitHub IR/PR format.
Where it falls short
The dataset, while expanded, is still small -- 71 flaky and 71 non-flaky examples. The findings may not be fully representative of the broader population of quantum software projects, especially those utilizing different testing frameworks or methodologies. The pipeline also relies entirely on developer-reported issues, which means flaky tests that were silently fixed or never reported are invisible to it. The team also ran only a single inference pass per model, and since LLMs are non-deterministic, results could vary across runs.
Root cause identification in particular remains a weak point. The multi-label classification task (some tests have two causes simultaneously) and the need to reason across both natural language and code push all current models below 0.65 F1 in most configurations -- good enough to triage, not good enough to fully automate.
What's available and what comes next
The expanded dataset is publicly available on Zenodo, including the buggy code, associated fixes, and code diffs -- artifacts that were absent from the original dataset. This makes it a reusable benchmark for anyone building flaky test detection tools for quantum software.
The practical use cases are clear: any team maintaining a Qiskit, NetKet, or similar quantum library can plug this pipeline into their CI workflow to automatically triage incoming issue reports and flag likely flaky tests before a human reviews them. The method-level code context approach also suggests a concrete integration point -- tools like PyDriller can extract the relevant changed methods automatically, feeding them directly into the LLM prompt.
The team plans to extend the pipeline with dynamic test re-execution on simulators and to explore automated patch generation -- moving from detection and diagnosis toward actually fixing the flaky tests. Given that quantum hardware time costs nearly $100 per minute, even a tool that correctly identifies the root cause half the time could save significant engineering resources.