microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/testing/operations/README.md
22lines · modecode
| 1 | # Testing Unitary Implementations |
| 2 | This 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 | |
| 6 | There are two primary ways to test operations in the QDK: |
| 7 | |
| 8 | 1. **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 | |
| 11 | 1. **`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 |
| 15 | This 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 | |