microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.25.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/testing/states/README.md

23lines · modecode

1# Testing Quantum States
2
3This sample project demonstrates testing Q# code that has to end up with a certain quantum state.
4
5## Testing Method
6
7The most convenient way to validate the quantum state of the program in Q# is using `dump_machine` Python API.
8
91. **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
122. **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
18This 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