Skip to content

Commit 05dcd3c

Browse files
minestarksbillti
andauthored
Copilot tools for run, estimate, circuit (#2380)
Adds new `LanguageModelTool`s for running a Q# program locally, resource estimation, and circuit diagrams. Just as when they're explicitly invoked, these commands bring up the webview panels to show results. The results are also added to the chat context so that the language model can talk about and/or interpret them. Example: ![image](https://github.com/user-attachments/assets/7487fba6-2caf-4533-bbcc-c09a99c58f13) --------- Co-authored-by: Bill Ticehurst <[email protected]>
1 parent a0808ba commit 05dcd3c

File tree

8 files changed

+806
-309
lines changed

8 files changed

+806
-309
lines changed

vscode/package.json

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@
398398
"command": "qsharp-vscode.copilotClear",
399399
"category": "QDK",
400400
"title": "Clear Quantum Copilot chat",
401-
"enablement": "!qdkCopilotIsBusy",
401+
"enablement": "config.Q#.chat.enabled && !qdkCopilotIsBusy",
402402
"icon": "$(clear-all)"
403403
},
404404
{
@@ -828,6 +828,116 @@
828828
],
829829
"additionalProperties": false
830830
}
831+
},
832+
{
833+
"name": "qsharp-run-program",
834+
"tags": [
835+
"azure-quantum",
836+
"qsharp",
837+
"qdk"
838+
],
839+
"toolReferenceName": "qsharpRunProgram",
840+
"displayName": "Run Q# Program",
841+
"modelDescription": "Executes a Q# program. The path to a .qs file must be specified in the `filePath` parameter. A quantum simulator will be run locally. Q# does not provide any CLI tools, so call this tool whenever you need to execute Q#, instead of running any CLI commands. The `shots` parameter controls the number of times to repeat the simulation. If the number of shots is greater than 1, a histogram will be generated, and the results will be displayed in a dedicated panel.",
842+
"canBeReferencedInPrompt": true,
843+
"icon": "./resources/file-icon-light.svg",
844+
"inputSchema": {
845+
"type": "object",
846+
"properties": {
847+
"filePath": {
848+
"type": "string",
849+
"description": "The absolute path to the .qs file. If this file is part of a project, the whole project will be compiled as the program. A .qs file belongs to a project if it resides anywhere under a src/ directory whose parent directory also contains a qsharp.json manifest."
850+
},
851+
"shots": {
852+
"type": "number",
853+
"description": "The number of times to run the program. Defaults to 1 if not specified.",
854+
"default": 1
855+
}
856+
},
857+
"required": [
858+
"filePath"
859+
],
860+
"additionalProperties": false
861+
}
862+
},
863+
{
864+
"name": "qsharp-generate-circuit",
865+
"tags": [
866+
"azure-quantum",
867+
"qsharp",
868+
"qdk"
869+
],
870+
"toolReferenceName": "qsharpGenerateCircuit",
871+
"displayName": "Generate Q# Circuit Diagram",
872+
"modelDescription": "Generates a visual circuit diagram for a Q# program. The path to a .qs file must be specified in the `filePath` parameter. This tool will compile the Q# program and generate a quantum circuit diagram that visually represents the quantum operations in the code. If the program contains any dynamic behavior such as comparing measurement results, then the program will be executed using a quantum simulator, and the resulting circuit diagram will simply be a trace of the operations that were actually executed during simulation. The diagram will be displayed in a dedicated circuit panel.",
873+
"canBeReferencedInPrompt": true,
874+
"icon": "./resources/file-icon-light.svg",
875+
"inputSchema": {
876+
"type": "object",
877+
"properties": {
878+
"filePath": {
879+
"type": "string",
880+
"description": "The absolute path to the .qs file. If this file is part of a project, the whole project will be compiled as the program. A .qs file belongs to a project if it resides anywhere under a src/ directory whose parent directory also contains a qsharp.json manifest."
881+
}
882+
},
883+
"required": [
884+
"filePath"
885+
],
886+
"additionalProperties": false
887+
}
888+
},
889+
{
890+
"name": "qsharp-run-resource-estimator",
891+
"tags": [
892+
"azure-quantum",
893+
"qsharp",
894+
"qdk"
895+
],
896+
"toolReferenceName": "qsharpRunResourceEstimator",
897+
"displayName": "Run Q# Resource Estimator",
898+
"modelDescription": "Runs the quantum resource estimator on a Q# program to calculate the required physical resources. The path to a .qs file must be specified in the `filePath` parameter. This tool will analyze the Q# program and generate estimates of the quantum resources required to run the algorithm, such as the number of qubits, T gates, and other quantum operations. Results will be displayed in a dedicated resource estimator panel.",
899+
"canBeReferencedInPrompt": true,
900+
"icon": "./resources/file-icon-light.svg",
901+
"inputSchema": {
902+
"type": "object",
903+
"properties": {
904+
"filePath": {
905+
"type": "string",
906+
"description": "The absolute path to the .qs file. If this file is part of a project, the whole project will be compiled as the program. A .qs file belongs to a project if it resides anywhere under a src/ directory whose parent directory also contains a qsharp.json manifest."
907+
},
908+
"qubitTypes": {
909+
"type": "array",
910+
"description": "Array of qubit type labels to use for resource estimation. Allowed values:\n- 'qubit_gate_ns_e3': Superconducting/spin qubit with 1e-3 error rate\n- 'qubit_gate_ns_e4': Superconducting/spin qubit with 1e-4 error rate\n- 'qubit_gate_us_e3': Trapped ion qubit with 1e-3 error rate\n- 'qubit_gate_us_e4': Trapped ion qubit with 1e-4 error rate\n- 'qubit_maj_ns_e4 + surface_code': Majorana qubit with 1e-4 error rate (surface code QEC)\n- 'qubit_maj_ns_e6 + surface_code': Majorana qubit with 1e-6 error rate (surface code QEC)\n- 'qubit_maj_ns_e4 + floquet_code': Majorana qubit with 1e-4 error rate (floquet code QEC)\n- 'qubit_maj_ns_e6 + floquet_code': Majorana qubit with 1e-6 error rate (floquet code QEC)",
911+
"items": {
912+
"type": "string",
913+
"enum": [
914+
"qubit_gate_ns_e3",
915+
"qubit_gate_ns_e4",
916+
"qubit_gate_us_e3",
917+
"qubit_gate_us_e4",
918+
"qubit_maj_ns_e4 + surface_code",
919+
"qubit_maj_ns_e6 + surface_code",
920+
"qubit_maj_ns_e4 + floquet_code",
921+
"qubit_maj_ns_e6 + floquet_code"
922+
]
923+
},
924+
"default": [
925+
"qubit_gate_ns_e3"
926+
]
927+
},
928+
"errorBudget": {
929+
"type": "number",
930+
"description": "Error budget for the resource estimation. Must be a number between 0 and 1. Default is 0.001.",
931+
"minimum": 0,
932+
"maximum": 1,
933+
"default": 0.001
934+
}
935+
},
936+
"required": [
937+
"filePath"
938+
],
939+
"additionalProperties": false
940+
}
831941
}
832942
]
833943
},

vscode/src/circuit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type CircuitParams = {
3232
/**
3333
* Result of a circuit generation attempt.
3434
*/
35-
type CircuitOrError = {
35+
export type CircuitOrError = {
3636
simulated: boolean;
3737
} & (
3838
| {
@@ -116,7 +116,7 @@ export async function showCircuitCommand(
116116
* that means this is a dynamic circuit. We fall back to using the
117117
* simulator in this case ("trace" mode), which is slower.
118118
*/
119-
async function generateCircuit(
119+
export async function generateCircuit(
120120
extensionUri: Uri,
121121
params: CircuitParams,
122122
): Promise<CircuitOrError> {

vscode/src/debugger/output.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ function formatComplex(real: number, imag: number) {
1212
return `${r}${i}`;
1313
}
1414

15-
export function createDebugConsoleEventTarget(out: (message: string) => void) {
16-
const eventTarget = new QscEventTarget(false);
15+
export function createDebugConsoleEventTarget(
16+
out: (message: string) => void,
17+
captureEvents: boolean = false,
18+
) {
19+
const eventTarget = new QscEventTarget(captureEvents);
1720

1821
eventTarget.addEventListener("Message", (evt) => {
1922
out(evt.detail + "\n");

0 commit comments

Comments
 (0)