microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/testing/states/README.md
23lines · modecode
| 1 | # Testing Quantum States |
| 2 | |
| 3 | This sample project demonstrates testing Q# code that has to end up with a certain quantum state. |
| 4 | |
| 5 | ## Testing Method |
| 6 | |
| 7 | The most convenient way to validate the quantum state of the program in Q# is using `dump_machine` Python API. |
| 8 | |
| 9 | 1. **Check that the amplitudes match the dense array of expected amplitudes:** |
| 10 | Use the `as_dense_state()` method of `StateDump` class to convert it to an array of amplitudes and compare it with the expected one. |
| 11 | |
| 12 | 2. **Check that the state matches the expected one up to a global phase:** |
| 13 | Use the `check_eq()` method of `StateDump` class to compare it to the given array of amplitudes, taking into account the possible global phase difference. |
| 14 | |
| 15 | |
| 16 | ## Project Structure |
| 17 | |
| 18 | This sample project is a multi-file Q# project that showcases both testing methods. The project structure is as follows: |
| 19 | |
| 20 | - src |
| 21 | - `StatePrep.qs`: Q# file containing the state preparation operations to be tested. |
| 22 | - `qsharp.json`: Q# project manifest file, instructing the compiler to include all files in `src` directory. |
| 23 | - `test_states.py`: Python wrapper containing tests. |
| 24 | |