microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.25.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/testing/operations/README.md

22lines · modecode

1# Testing Unitary Implementations
2This sample project demonstrates different approaches to testing operations that implement unitary transformations in the QDK, both via Python and within Q# itself.
3
4## Testing Methods
5
6There are two primary ways to test operations in the QDK:
7
81. **Using operation matrix representation:**
9 Use the `dump_operation` Python API to retrieve the operation's representation as a matrix and compare it against the expected matrix.
10
111. **`CheckOperationsAreEqual` operation and `Fact` assertion:**
12 Use a `Fact` function in your Q# code that uses the `CheckOperationsAreEqual` operation to verify if two operations are identical up to a global phase. The `Fact` function asserts that the check returns `true`.
13
14## Project Structure
15This sample project is a multi-file Q# project that showcases both testing methods. The project structure is as follows:
16
17- src
18 - `BellState.qs`: Q# file containing the `AllBellStates` operation to be tested
19 - `CustomOperation.qs`: Q# file containing the `ApplySWAP` operation to be tested
20 - `OperationEquivalence.qs`: Q# file containing the `TestEquivalence` operation to be called in Python wrapper
21- `qsharp.json`: Q# project manifest file, instructing compiler to include all files in `src` directory.
22- `test_dump_operation.py`: Python wrapper containing tests.
23