Anyone who has asked a language model to write Q# will have noticed, that the result quite often does not compile. The interesting part is the reason. In most cases the quantum logic is perfectly fine and what fails is the language itself, because the model writes the Q# it remembers from before the QDK was rewritten in 2024.
Over the past few weeks I built a benchmark to measure this, and then used it to rework the Q# part of the programming skill that the QDK ships for AI coding agents. The pull request was reviewed and merged by the QDK team this week, so the reworked skill will be part of the next release of the QDK extension for VS Code. On exercises that the new text was never tuned on, it takes gpt-6-luna from 84.7% of correct answers with the previous skill to 92.5%, while without any skill at all the same model manages 72.2%.
Models write the Q# of 2022 π
The modern QDK changed Q# in many small ways. The Microsoft.Quantum.* namespaces became Std.*, using blocks became use statements, loops and conditions lost their parentheses, and a fair number of library callables were renamed or removed altogether. A large part of the Q# that exists in public (the older posts on this blog included) predates those changes, and naturally that is what the models have learnt from. Asked for an operation that puts a few qubits into superposition, measures them and counts the ones, a model will quite typically come back with something like this:
namespace Demo {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Measurement;
operation CountOnes(n : Int) : Int {
mutable ones = 0;
using (qs = Qubit[n]) {
for (q in qs) {
H(q);
if (MResetZ(q) == One) {
set ones += 1;
}
}
}
return ones;
}
}
The algorithm is correct, however the current compiler rejects it on the using line, again on the loop (parenthesis are not permitted around for-loop iterations) and then twice more further down. In the Q# of today the same operation reads:
operation CountOnes(n : Int) : Int {
mutable ones = 0;
use qs = Qubit[n];
for q in qs {
H(q);
if MResetZ(q) == One {
ones += 1;
}
}
return ones;
}
Such failure is, of course, the cheapest possible kind to repair, since nothing about the model’s understanding of quantum computing has to change. The numbers confirm that this is indeed where the problem sits. Without any guidance, 129 of the 615 answers that gpt-6-luna gave on the held-out half of the benchmark (we will get to the split in a moment) did not compile, while 91.4% of the answers that did compile were correct. For the open-weight Qwen3.8-27B the contrast is even larger, as only 37.2% of its answers compiled, but 94.8% of those were right.
Grading with the katas’ own checkers π
In order to measure any of this we need a way of deciding whether a piece of Q# is correct, and the QDK already has an excellent one. The quantum katas in the QDK repository contain 225 exercises, and each of them comes with a checker, written in Q# by the QDK team, which verifies a learner’s solution, typically by comparing it against a reference implementation on the simulator. The benchmark hands the exercise to a model instead of a human, takes the Q# file that comes back and runs the very same checker against it, through the released qdk Python package (version 1.34.0). To those I added the 12 exercises of the Learn section of Copenhagen, which gives 237 tasks in total. Every model answers each task five times, in a single request and without any tools, so a full run consists of 1 185 answers.
The second ingredient is a split. The tasks are divided into a development half (114 tasks) and a held-out half (123 tasks), and a kata is never divided between the two. While working on the skill I only ever looked at failed answers from the development half, and the answers on the held-out half were scored but never read. The guide itself contains no exercise content either. Unless stated otherwise, the numbers quoted in this post come from the held-out half.
Without any skill, the sixteen models I ran cover pretty much the whole range:
| Model | Correct, all 237 tasks |
|---|---|
claude-fable-5-2 |
99.3% |
claude-opus-5-5 |
97.1% |
gpt-6.2-astra |
95.2% |
gpt-6.2-sol |
94.8% |
gpt-6.1-terra |
90.3% |
claude-sonnet-5-5 |
90.2% |
claude-haiku-5-5 |
82.8% |
gpt-6-luna |
69.5% |
| Nemotron 3.5 Lightning 30B | 42.6% |
| Inkling 2 Mini | 41.9% |
| Nemotron 3 Nano 30B | 38.4% |
| Granite 4.2 8B | 36.2% |
| Qwen3.8-27B | 32.5% |
| K2-Horizon-7B | 25.7% |
| Granite 4.2 3B | 25.5% |
| Qwen3.5-4B | 15.7% |
The hosted models were called through their APIs, and the eight open-weight ones were served with vLLM on a single H100.
What changed in the skill π
The QDK extension contributes a skill called qdk-programming to the agent, and whenever the agent is about to write Q#, the skill sends it to a file called qsharp.md. That file used to be a general quick reference of the language. It is now a guide of about 1 600 words which covers the things that models actually get wrong. Those are the syntax that changed, the names that need an import or no longer exist (together with what to write instead), the strict separation of Int and Double, the rules for adjoint and controlled operations, the conventions for gates and angles, releasing qubits and bit order. Every statement in it was compiled against QDK 1.34. The previous content was not lost, it moved to qsharp-extras.md, which the agent reads on demand for topics such as tests, projects and target profiles.
Measured on the held-out tasks, with the whole skill in the system message, the before and after look as follows:
| Model | No skill | Skill before | Skill after | After against before (95% interval) |
|---|---|---|---|---|
claude-sonnet-5-5 |
92.0% | 93.8% | 96.4% | +2.6 (0.2 to 5.5) |
claude-haiku-5-5 |
88.3% | 88.6% | 93.5% | +4.9 (1.6 to 8.3) |
gpt-6-luna |
72.2% | 84.7% | 92.5% | +7.8 (3.9 to 12.0) |
Sonnet’s run used the text as it stood before the review, the other two the final one (the review edits changed nothing measurable where I reran both). As expected, most of the gain is code that now compiles. Of the 615 held-out answers of gpt-6-luna, 129 failed to compile without a skill, 46 with the previous skill and 10 with the new one. I also tried the obvious alternative of keeping the old reference in the prompt next to the new guide, and the scores were the same within noise, at about 1 400 more words on every single request. This is the reason why the guide replaces the old file instead of joining it.
The physics is there, the syntax is not π
The most striking results came from the open-weight models, which I ran with the guide alone in the system message:
| Model | No skill | With the guide | Difference (95% interval) |
|---|---|---|---|
| Qwen3.8-27B | 35.3% | 84.2% | +48.9 (42.8 to 55.5) |
| Inkling 2 Mini | 48.0% | 87.5% | +39.5 (33.5 to 45.9) |
| K2-Horizon-7B | 28.3% | 55.8% | +27.5 (22.1 to 33.3) |
| Nemotron 3.5 Lightning 30B | 48.8% | 68.1% | +19.4 (14.0 to 24.7) |
| Granite 4.2 3B | 27.5% | 37.7% | +10.2 (5.4 to 15.0) |
| Qwen3.5-4B | 15.9% | 16.8% | +0.8 (-4.1 to 5.7) |
These runs also predate the review edits, and the two models I reran on the final text, Inkling 2 Mini and Qwen3.5-4B, scored the same within noise. Inkling 2 Mini, a 26B model that runs on a single GPU, end up in the territory of the best frontier models, and all it needed for that was about 1 600 words of syntax reference. I think there is a more general lesson here for anyone who maintains a quantum SDK, or really any SDK that evolves faster than the models are retrained. The models will be behind on the syntax, but they are surprisingly up to date on the subject itself, and a short, tested piece of guidance that ships together with the SDK closes most of that gap quickly and at almost no cost.
For the smallest models the picture is less rosy. They do compile more often with the guide, but the share of their compiling answers that are actually right does not improve, and the smallest one I tried, a 4B model, gains nothing at all. The guide gives a model the language, it does not give it the logic.
What this does not show π
The benchmark asks for one answer in one request. Inside VS Code an agent can also call the compiler and look up the standard library through the tools of the extension, so the gain there may well be smaller. The exercises are single operations and functions, which means that projects, tests and target profiles (the topics of the second file) were not measured. Finally, the katas are public and the models may have seen their solutions, however this applies equally to every column of the tables above.
Final thoughts π
The benchmark, with its tasks, its prompts and every single answer and verdict of every run mentioned here, is available on GitHub. Running it against another model takes three commands (generate, score and report), and anything that speaks the OpenAI chat API will do, a local server included. A paper with the complete analysis is in preparation. In the meantime, if there is a model that should be on the list, or a kind of mistake in generated Q# that the guide still does not prevent, I would be very glad to hear about it.


