You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/examples/instruct_validate_repair/qiskit_code_validation/README.md
+30-4Lines changed: 30 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Qiskit Code Validation with Instruct-Validate-Repair
2
2
3
-
This example demonstrates using Mellea's Instruct-Validate-Repair (IVR) pattern to generate Qiskit quantum computing code that automatically passes flake8-qiskit-migration validation rules (QKT rules).
3
+
This example demonstrates using Mellea's Instruct-Validate-Repair (IVR) pattern to generate Qiskit quantum computing code that automatically passes `flake8-qiskit-migration` validation rules (QKT rules).
4
4
5
5
## What This Example Does
6
6
@@ -34,6 +34,34 @@ Dependencies (`mellea`, `flake8-qiskit-migration`) are automatically installed.
34
34
3.**Post-condition validation**: Validates generated code against QKT rules (see [Qiskit Migration Guide](https://docs.quantum.ibm.com/api/migration-guides))
35
35
4.**Repair loop**: Automatically repairs code that fails validation (up to 5 attempts)
36
36
37
+
### Sampling Strategies
38
+
39
+
The example supports two repair strategies (see [Sampling Strategies](../README.md#sampling-strategies)):
40
+
41
+
-**RepairTemplateStrategy** (default): Adds validation failure reasons directly to the instruction and retries generation
42
+
-**MultiTurnStrategy**: Builds conversation history by adding validation failures as new user messages
43
+
44
+
To switch strategies, edit the `use_multiturn_strategy` variable in `test_qiskit_code_validation()`
45
+
46
+
**Note**: `MultiTurnStrategy` requires `ChatContext()` while `RepairTemplateStrategy` works with `SimpleContext()`. The example automatically selects the appropriate context based on your strategy choice.
47
+
48
+
#### Strategy Performance Comparison
49
+
50
+
Benchmarks on `mistral-small-3.2-24b-qiskit` model (pass rates measure QKT validation only, not correctness):
51
+
52
+
| Dataset | Strategy | First Pass | Post-Repair |
53
+
|---------|----------|------------|-------------|
54
+
|**QHE**| RepairTemplate | 78.2% |**99.3%**|
55
+
|| MultiTurn | 77.5% | 96.7% |
56
+
|**QKT**| RepairTemplate | 54.1% |**83.8%**|
57
+
|| MultiTurn | 37.8% | 70.3% |
58
+
59
+
**Datasets:**
60
+
-**QHE** (QiskitHumanEval): Code generation tasks testing general Qiskit programming
61
+
-**QKT**: Qiskit version migration tasks requiring fixes to deprecated APIs
62
+
63
+
**Note:** These benchmarks measure whether generated code passes QKT validation rules, not whether the code correctly solves the prompt. Both aspects are important for production use.
64
+
37
65
### Code Structure
38
66
39
67
```
@@ -224,6 +252,4 @@ ModuleNotFoundError: No module named 'flake8_qiskit_migration'
224
252
225
253
The following enhancements are planned for future iterations:
226
254
227
-
1.**MultiTurnStrategy Integration** - Try using `MultiTurnStrategy` (see [Sampling Strategies](../README.md#sampling-strategies)) which builds conversation history by adding validation failures as new user messages, to see if this approach improves results over the current `RepairTemplateStrategy` which adds failures directly to the instruction.
228
-
229
-
2.**Enable Smaller Models** - Add system prompt or grounding context with Qiskit API documentation to help smaller models perform accurate migrations. This would allow removing the `pytest.mark.skip` marker and make the example run in standard test suites.
255
+
1.**Enable Smaller Models** - Add system prompt or grounding context with Qiskit API documentation to help smaller models perform accurate migrations. This would allow removing the `pytest.mark.skip` marker and make the example run in standard test suites.
0 commit comments