Q# project and solution is created using the following commands:
dotnet new console -lang Q# --output FirstQuantum
Visual Studio Code is used to open the project. The project will have two files Driver.cs
(C# driver) and Operations.qs
(Q# ). The Operations.qs
is renamed as Quantum.qs
.
The code snippet below shows the Quantum.qs
after adding the operation Set and StateTest
:
Code Snippet :Quantum Q#Example
namespace FirstQuantum { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Primitive; operation Set (desired: Result, q1: Qubit) : Unit { let current = M(q1); if (desired != current) { X(q1); } }
The set operation updates the qubit to a desired state of zero or one. The qubit is measured which collapses the state to either 0
or 1
. If the desired is not equal to the current, X (NOT gate) flips it otherwise nothing is changed.
operation StateTest (count : Int, initial: Result) : (Int, Int) { ...