Skip to content

[WIP] Copilot tools for run, estimate, circuit #2380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ Most of the core components are implemented in Rust. These components are packag
- **qsc_rir/**: Runtime Intermediate Representation
- **fuzz/**: Fuzz testing infrastructure for the compiler
- **language_service/**: Q# language service for editor features
- **src/code_action.rs**: Code actions
- **src/code_lens/**: Code lens
- **src/completion/**: Completions
- **src/definition/**: Go to definition
- **src/hover/**: Hover
- **src/references/**: Find references
- **src/rename/**: Inline rename
- **src/signature_help/**: Signature help
- **src/state/**: Language service state management
- **noisy_simulator/**: Simulator for quantum noise modeling
- **resource_estimator/**: Quantum Resource Estimator implementation
- **wasm/**: WebAssembly bindings for core components
Expand All @@ -49,6 +58,22 @@ Most of the core components are implemented in Rust. These components are packag
**Python**

- **pip/**: The `qsharp` Python package
- **qsharp/**: Python package source
- **src/**: Rust implementation for Python bindings
- **tests/**: Unit tests
- **tests-integration/**: Integration tests with Qiskit, PyQIR, QIR Runner, and simulators
- **interop_qiskit/**: Qiskit interoperability tests
- **test_circuits/**: Test circuit definitions
- **test_gateset_qasm.py**: QASM gate set tests
- **test_gate_correctness.py**: Gate correctness validation
- **test_qir.py**: QIR integration with Qiskit
- **test_qsharp.py**: Q# and Qiskit interop tests
- **test_re.py**: Resource estimator tests
- **test_run_sim.py**: Simulation runtime tests
- **resources/**: Test resources for adaptive QIR
- **test_adaptive_ri_qir.py**: Adaptive Result Interop QIR tests
- **test_adaptive_rif_qir.py**: Adaptive Result+Feedback Interop QIR tests
- **test_base_qir.py**: Base QIR functionality tests
- **jupyterlab/**: JupyterLab extension for Q#
- **widgets/**: Q# Jupyter widgets

Expand All @@ -71,6 +96,43 @@ Most of the core components are implemented in Rust. These components are packag
- **npm/**: The `qsharp-lang` npm package
- **playground/**: Q# Playground website
- **vscode/**: Visual Studio Code extension for Q#
- **src/**: Extension source code
- **language-service/**: Language service integration
- **activate.ts**: Language service activation
- **codeActions.ts**: Code actions implementation
- **codeLens.ts**: Code lens provider
- **completion.ts**: Autocompletion provider
- **definition.ts**: Go to definition
- **diagnostics.ts**: Diagnostics handling
- **format.ts**: Code formatting
- **hover.ts**: Hover information provider
- **notebook.ts**: Notebook integration
- **references.ts**: Find references
- **rename.ts**: Symbol renaming
- **signature.ts**: Signature help provider
- **testExplorer.ts**: Test explorer integration
- **webview/**: UI components
- **docview.tsx**: Documentation view
- **editor.tsx**: Editor components
- **help.tsx**: Help view
- **webview.tsx**: Webview base
- **theme.ts**: Theme handling
- **azure/**: Azure integration
- **debugger/**: Debugger implementation
- **copilot/**: Copilot integration
- **gh-copilot/**: GitHub Copilot integration
- **extension.ts**: Main extension entry point
- **circuit.ts**: Circuit representation
- **circuitEditor.ts**: Circuit editor
- **diagnostics.ts**: Diagnostic handling
- **projectSystem.ts**: Project management
- **qirGeneration.ts**: QIR generation
- **notebook.ts**: Notebook integration
- **telemetry.ts**: Telemetry collection
- **resources/**: Extension resources
- **syntaxes/**: Q# syntax definitions
- **test/**: Extension tests
- **wasm/**: WebAssembly integration

## Development workflow

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ __pycache__/
.pytest_cache/
.idea/
*.so
# temp - local dev stuff for reference
reference.json
language-model-tools-reference.json.md
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default tseslint.config(
"jupyterlab/lib/",
"jupyterlab/qsharp-jupyterlab/labextension/",
"**/.*/",
"vscode/extract-tools.js",
"vscode/out/",
"vscode/test/out/",
"widgets/src/qsharp_widgets/static/",
Expand Down
53 changes: 53 additions & 0 deletions vscode/extract-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const fs = require("fs");
const path = require("path");

const name = process.argv[2] || "package.json";
if (!fs.existsSync(name)) {
console.error(`File not found: ${name}`);
process.exit(1);
}

// Read package.json file
const packageJsonPath = path.join(process.cwd(), name);
const packageJson = require(packageJsonPath);

// Extract the languageModelTools array
const tools = packageJson.contributes.languageModelTools;

// Prepare the markdown content
let markdownContent = "# Q# Language Model Tools\n\n";

// Loop through each tool and extract the required fields
tools.forEach((tool) => {
markdownContent += `## ${tool.displayName}\n\n`;
markdownContent += `- **Name**: \`${tool.name}\`\n`;
markdownContent += `- **Description**: ${tool.modelDescription}\n\n`;

// Extract and format input parameters if available
if (tool.inputSchema && tool.inputSchema.properties) {
markdownContent += "### Input Parameters\n\n";

// Create a parameters table with name, type, required, and description
markdownContent += "| Parameter | Type | Required | Description |\n";
markdownContent += "|-----------|------|----------|-------------|\n";

const properties = tool.inputSchema.properties;
const requiredParams = tool.inputSchema.required || [];

Object.keys(properties).forEach((paramName) => {
const param = properties[paramName];
const isRequired = requiredParams.includes(paramName) ? "Yes" : "No";
markdownContent += `| \`${paramName}\` | \`${param.type}\` | ${isRequired} | ${param.description} |\n`;
});

markdownContent += "\n";
}
});

// Write the markdown content to a file
const outputPath = path.join(process.cwd(), `language-model-tools-${name}.md`);
fs.writeFileSync(outputPath, markdownContent);

console.log(
`Successfully extracted language model tools info to ${outputPath}`,
);
143 changes: 143 additions & 0 deletions vscode/language-model-tools-package.json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Q# Language Model Tools

## Get Azure Quantum Jobs

- **Name**: `azure-quantum-get-jobs`
- **Description**: Get a list of recent jobs that have been run by the customer, along with their statuses, in the currently active workspace. Call this when you need to know what jobs have been run recently or need a history of jobs run, for example when a customer asks 'What are my recent jobs?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|

## Get Azure Quantum Job Details

- **Name**: `azure-quantum-get-job`
- **Description**: Get the job information for a customer's job given its id. Call this whenever you need to know information about a specific job, for example when a customer asks 'What is the status of my job?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `job_id` | `string` | Yes | Job's unique identifier. |

## Connect to Azure Quantum Workspace

- **Name**: `azure-quantum-connect-to-workspace`
- **Description**: Starts the UI flow to connect to an existing Azure Quantum Workspace. Call this when the customer does not have an active workspace, and agrees to connect to a workspace.

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|

## Download Azure Quantum Job Results

- **Name**: `azure-quantum-download-job-results`
- **Description**: Download and display the results from a customer's job given its id. Call this when you need to download or display as a histogram the results for a job, for example when a customer asks 'What are the results of my last job?' or 'Can you show me the histogram for this job?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `job_id` | `string` | Yes | Job's unique identifier. |

## Get Azure Quantum Workspaces

- **Name**: `azure-quantum-get-workspaces`
- **Description**: Get a list of workspaces the customer has access to, in the form of workspace ids. Call this when you need to know what workspaces the customer has access to, for example when a customer asks 'What are my workspaces?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|

## Submit to Azure Quantum Target

- **Name**: `azure-quantum-submit-to-target`
- **Description**: Submit the current Q# program to Azure Quantum with the provided information. Call this when you need to submit or run a Q# program with Azure Quantum, for example when a customer asks 'Can you submit this program to Azure?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `job_name` | `string` | Yes | The string to name the created job. |
| `target_id` | `string` | Yes | The ID or name of the target to submit the job to. |
| `number_of_shots` | `number` | Yes | The number of shots to use for the job. |

## Get Active Azure Quantum Workspace

- **Name**: `azure-quantum-get-active-workspace`
- **Description**: Get the id of the active workspace for this conversation. Call this when you need to know what workspace is the active workspace being used in the context of the current conversation, for example when a customer asks 'What is the workspace that's being used?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|

## Set Active Azure Quantum Workspace

- **Name**: `azure-quantum-set-active-workspace`
- **Description**: Set the active workspace for this conversation by id. Call this when you need to set what workspace is the active workspace being used in the context of the current conversation, for example when a customer says 'Please use this workspace for my requests.'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `workspace_id` | `string` | Yes | The id of the workspace to set as active. |

## Get Azure Quantum Providers

- **Name**: `azure-quantum-get-providers`
- **Description**: Get a list of hardware providers available to the customer, along with their provided targets. Call this when you need to know what providers or targets are available, for example when a customer asks 'What are the available providers?' or 'What targets do I have available?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|

## Get Azure Quantum Target

- **Name**: `azure-quantum-get-target`
- **Description**: Get the target information for a specified target given its id. Call this whenever you need to know information about a specific target, for example when a customer asks 'What is the status of this target?'

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `target_id` | `string` | Yes | The ID of the target to get. |

## Run Q# Program

- **Name**: `qsharp-run-program`
- **Description**: 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.

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `filePath` | `string` | Yes | The absolute path to the .qs file. If this file is part of a project, as defined by being in a folder with a qsharp.json file, the whole project will be compiled as the program. |
| `shots` | `number` | No | The number of times to run the program. Defaults to 1 if not specified. |

## Generate Q# Circuit Diagram

- **Name**: `qsharp-generate-circuit`
- **Description**: 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. The diagram will be displayed in a dedicated circuit panel.

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `filePath` | `string` | Yes | The absolute path to the .qs file. If this file is part of a project, as defined by being in a folder with a qsharp.json file, the whole project will be compiled as the program. |

## Run Q# Resource Estimator

- **Name**: `qsharp-run-resource-estimator`
- **Description**: 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.

### Input Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `filePath` | `string` | Yes | The absolute path to the .qs file. If this file is part of a project, as defined by being in a folder with a qsharp.json file, the whole project will be compiled as the program. |

84 changes: 83 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
"command": "qsharp-vscode.copilotClear",
"category": "Q#",
"title": "Clear Quantum Copilot chat",
"enablement": "!qdkCopilotIsBusy",
"enablement": "config.Q#.chat.enabled && !qdkCopilotIsBusy",
"icon": "$(clear-all)"
},
{
Expand Down Expand Up @@ -806,6 +806,88 @@
],
"additionalProperties": false
}
},
{
"name": "qsharp-run-program",
"tags": [
"azure-quantum",
"qsharp",
"qdk"
],
"toolReferenceName": "qsharpRunProgram",
"displayName": "Run Q# Program",
"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.",
"canBeReferencedInPrompt": true,
"icon": "./resources/file-icon-light.svg",
"inputSchema": {
"type": "object",
"properties": {
"filePath": {
"type": "string",
"description": "The absolute path to the .qs file. If this file is part of a project, as defined by being in a folder with a qsharp.json file, the whole project will be compiled as the program."
},
"shots": {
"type": "number",
"description": "The number of times to run the program. Defaults to 1 if not specified."
}
},
"required": [
"filePath"
],
"additionalProperties": false
}
},
{
"name": "qsharp-generate-circuit",
"tags": [
"azure-quantum",
"qsharp",
"qdk"
],
"toolReferenceName": "qsharpGenerateCircuit",
"displayName": "Generate Q# Circuit Diagram",
"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. The diagram will be displayed in a dedicated circuit panel.",
"canBeReferencedInPrompt": true,
"icon": "./resources/file-icon-light.svg",
"inputSchema": {
"type": "object",
"properties": {
"filePath": {
"type": "string",
"description": "The absolute path to the .qs file. If this file is part of a project, as defined by being in a folder with a qsharp.json file, the whole project will be compiled as the program."
}
},
"required": [
"filePath"
],
"additionalProperties": false
}
},
{
"name": "qsharp-run-resource-estimator",
"tags": [
"azure-quantum",
"qsharp",
"qdk"
],
"toolReferenceName": "qsharpRunResourceEstimator",
"displayName": "Run Q# Resource Estimator",
"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.",
"canBeReferencedInPrompt": true,
"icon": "./resources/file-icon-light.svg",
"inputSchema": {
"type": "object",
"properties": {
"filePath": {
"type": "string",
"description": "The absolute path to the .qs file. If this file is part of a project, as defined by being in a folder with a qsharp.json file, the whole project will be compiled as the program."
}
},
"required": [
"filePath"
],
"additionalProperties": false
}
}
]
},
Expand Down
Loading
Loading