page_type | languages | products | description | urlFragment | jupyter | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
Using facts and assertions to diagnose quantum programs in Q#. |
facts-and-assertions |
|
This sample demonstrates:
- Using facts to check conditions on the values of Q# variables.
- Using assertions on quantum simulators to check conditions on the state of quantum registers.
In this sample, you can use Q# to check the correctness of quantum programs with both facts (functions that check conditions on the values of their inputs) and assertions (operations that check conditions on the state of their inputs). Both facts and assertions can be used together to help understand bugs in quantum programs, and to write unit tests that help ensure that your Q# programs work correctly.
- The Microsoft Quantum Development Kit.
This sample is designed to be run from Jupyter Notebook. To set up your development environment to run Jupyter Notebooks, follow the steps explained in the Q# Quickstart: Jupyter guide.
Once this is set up, from the terminal, you can run the following command:
jupyter notebook
Alternatively, these notebooks can be started and run in the VSCode editor. To get set up with VSCode, please follow the steps laid out in the Q# Quickstart: VSCode guide.
- Facts and Assertions.ipynb: Main Q# notebook for this sample.