microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
.github/copilot-instructions.md
108lines · modecode
| 1 | # Copilot instructions for the `qsharp` repo |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | This repo contains the Microsoft Quantum Development Kit (QDK), which provides tooling for the Q# language. Q# is an open-source programming language designed for developing and running quantum algorithms. This repo is publicly available at https://github.com/microsoft/qdk . |
| 6 | |
| 7 | ## Architecture |
| 8 | |
| 9 | All internal source code for the compiler and related tooling has been moved under the `source/` directory at the repository root. This does not include Q# libraries (`library/`), samples (`samples/`), katas (`katas/`), or any standard files and folders typically found at the root of a repository (such as configuration, documentation, or build scripts). |
| 10 | |
| 11 | Most of the core components are implemented in Rust. These components are packaged in two ways: |
| 12 | |
| 13 | 1. Compiled as a native Python module and packaged into the `qdk` Python package |
| 14 | 2. Compiled into WebAssembly and packaged into the `qsharp-lang` npm package |
| 15 | |
| 16 | ## Repo Contents |
| 17 | |
| 18 | **Rust** |
| 19 | |
| 20 | - **allocator/**: A copy of `mimalloc`, used for memory allocation in the Rust components of the QDK |
| 21 | - **compiler/**: Core compiler and language processing components |
| 22 | - **qsc/**: Core compiler logic |
| 23 | - **qsc_ast/**: Abstract syntax tree definition and utilities |
| 24 | - **qsc_circuit/**: Circuit diagram representation and generation |
| 25 | - **qsc_codegen/**: Code generation utilities (QIR, Q#) |
| 26 | - **qsc_data_structures/**: Common data structures used by the compiler |
| 27 | - **qsc_doc_gen/**: Documentation generation tools |
| 28 | - **qsc_eval/**: Runtime evaluation and simulation |
| 29 | - **qsc_fir/**: Flat IR |
| 30 | - **qsc_formatter/**: Q# code formatter |
| 31 | - **qsc_frontend/**: Compiler frontend components |
| 32 | - **qsc_hir/**: High-level Intermediate Representation |
| 33 | - **qsc_linter/**: Code quality and style checking |
| 34 | - **qsc_lowerer/**: IR lowering transformations |
| 35 | - **qsc_parse/**: Q# parser |
| 36 | - **qsc_partial_eval/**: Partial evaluation and optimization |
| 37 | - **qsc_passes/**: HIR passes |
| 38 | - **qsc_project/**: Project system and manifest handling |
| 39 | - **qsc_openqasm_compiler/**: OpenQASM compiler frontend |
| 40 | - **qsc_openqasm_parser/**: OpenQASM parser frontend |
| 41 | - **qsc_rca/**: Resource counting and analysis |
| 42 | - **qsc_rir/**: Runtime Intermediate Representation |
| 43 | - **fuzz/**: Fuzz testing infrastructure for the compiler |
| 44 | - **language_service/**: Q# language service for editor features |
| 45 | - **noisy_simulator/**: Simulator for quantum noise modeling |
| 46 | - **resource_estimator/**: Quantum Resource Estimator implementation |
| 47 | - **wasm/**: WebAssembly bindings for core components |
| 48 | |
| 49 | **Build & Release** |
| 50 | |
| 51 | - **docker/**: Docker container configurations |
| 52 | |
| 53 | **Python** |
| 54 | |
| 55 | - **qdk_package/**: The `qdk` Python package (core package with native Rust extension) |
| 56 | - **pip/**: The `qsharp` Python package (thin deprecation shim that re-exports from `qdk`) |
| 57 | - **jupyterlab/**: JupyterLab extension for Q# |
| 58 | - **widgets/**: Q# Jupyter widgets |
| 59 | |
| 60 | **Q# Content** |
| 61 | |
| 62 | - **katas/**: Quantum computing tutorials and exercises |
| 63 | - **library/**: Q# standard and domain-specific libraries |
| 64 | - **chemistry/**: Chemistry-specific quantum operations |
| 65 | - **core/**: Q# core library |
| 66 | - **fixed_point/**: Fixed-point arithmetic support |
| 67 | - **qtest/**: Testing utilities |
| 68 | - **rotations/**: Quantum rotation operations |
| 69 | - **signed/**: Signed arithmetic operations |
| 70 | - **std/**: Q# standard library |
| 71 | - **samples/**: Example Q# programs demonstrating language features |
| 72 | - **samples_test/**: Tests for sample code |
| 73 | |
| 74 | **JavaScript/TypeScript** |
| 75 | |
| 76 | - **npm/**: The `qsharp-lang` npm package |
| 77 | - **playground/**: Q# Playground website |
| 78 | - **vscode/**: Visual Studio Code extension for Q# |
| 79 | - **src/**: Product source |
| 80 | - **test/**: Integration tests |
| 81 | |
| 82 | ## Development Workflow |
| 83 | |
| 84 | - `./build.py` runs full CI checks, including lints and unit tests. |
| 85 | - `./build.py --wasm --npm --vscode` only builds the VS Code extension, including its dependencies the WASM module and the `qsharp-lang` npm package. |
| 86 | - `./build.py --qdk` only builds the `qdk` Python package, including its native dependencies. |
| 87 | - `./build.py --pip` only builds the `qsharp` shim package (requires `qdk` to be built first). |
| 88 | - Pass `--no-check` to `./build.py`, in combination with any other command line options, to skip the lints and formatting checks. |
| 89 | - When working in Rust parts of the codebase, using `cargo` commands is usually more efficient than building via `./build.py`. |
| 90 | - Many lints can be auto-fixed via `cargo clippy --fix`. |
| 91 | - When working in JavaScript/TypeScript parts of the codebase, using `npm` scripts is usually more efficient than building via `./build.py`. |
| 92 | |
| 93 | ## Coding Standards |
| 94 | |
| 95 | - When adding new tests, follow the patterns established in existing tests in the same file or suite. Often, tests will use helper functions for brevity and readability. Design your tests to reuse these helpers where possible. |
| 96 | - Before opening a PR, ensure the following. |
| 97 | - Code **must** be formatted by running `cargo fmt` and `npm run prettier:fix`. |
| 98 | - `./build.py` without any command-line arguments **must** run without errors or warnings. |
| 99 | |
| 100 | ## Specific Guidelines for Parts of the Codebase |
| 101 | |
| 102 | ### VS Code Integration Tests (`vscode/test/`) |
| 103 | |
| 104 | - `npm test` from the `vscode/` directory runs the integration tests. |
| 105 | - `npm test -- --suite=language-service`: Run only the `language-service` test suite |
| 106 | - Tests use the VS Code for Web testing framework (`@vscode/test-web`), which uses `playwright` under the covers to automate headless Chrome. |
| 107 | - `mocha` interface is used to declare tests, `chai` for asserts. No mocking library is used. Do _not_ add dependencies to the test suite. |
| 108 | - Tests run in the real VS Code environment, in the extension host, which means they can directly interact with the VS Code API. |
| 109 | |