You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- content: 'Which of these statements is true about the random number generator that you built in this module?'
22
-
choices:
23
-
- content: "The quantum random number generator takes the current time from the CPU's clock as a seed to generate random numbers."
24
-
isCorrect: false
25
-
explanation: "The quantum random number generator doesn't use the CPU's clock to generate random numbers. A classical pseudo-random number generator would do that."
26
-
- content: "The quantum random number generator creates one qubit, measures it, and the result of the measurement is a random decimal number."
27
-
isCorrect: false
28
-
explanation: "The result of the measurement of a qubit is a random bit, not a random decimal number. This isn't the logic behind the random number generator that you built in this module."
29
-
- content: "The quantum random number generator creates a bit string from the repetition of measurements of a qubit in superposition. Then, it takes the bit string and converts it to a decimal number."
30
-
isCorrect: true
31
-
explanation: "This is the logic behind the random number generator that you built in this module."
32
-
33
-
- content: 'Which of the following structures are required for a Q# program to run successfully?'
34
-
choices:
35
-
- content: 'To run successfully, a Q# program must have a function.'
36
-
isCorrect: false
37
-
explanation: "A function is not required in a Q# program."
38
-
- content: "To run successfully, a Q# program must have an entry point, which is the `Main` operation."
39
-
isCorrect: true
40
-
explanation: "Every Q# program must have an entry point, which is the `Main` operation, so the Q# compiler knows where to start the program."
41
-
- content: "To run successfully, a Q# program must have an entry point and at least one allocated qubit."
42
-
isCorrect: false
43
-
explanation: "You can write Q# programs that don't need to perform operations on a qubit. A Q# program without a qubit allocated can run successfully."
44
-
45
-
- content: "Consider a quantum operation `A` that acts on a single qubit. If you want to write a Q# program that applies `A` to a qubit `q`, which of the following statements is true?"
46
-
choices:
47
-
- content: "You allocate a qubit using `q = Qubit();` and then apply `A` to `q` using `A(q);`."
48
-
isCorrect: false
49
-
explanation: "To allocate a qubit, you must use the `use` keyword, `use q = Qubit();`."
50
-
- content: "You allocate a qubit using `use q = Qubit();` and then apply `A` to `q` using `A(q);`."
51
-
isCorrect: true
52
-
explanation: "You first allocate a qubit using `use` and then apply `A` to the qubit allocated using `A(q);`."
53
-
- content: "You allocate a qubit using `use q = Qubit();` and then apply `A` to `q` using `A[q];`."
54
-
isCorrect: false
55
-
explanation: "To apply an operation to a qubit, you must use parentheses, `A(q);`."
- content: 'Which of these statements is true about the random number generator that you built in this module?'
22
+
choices:
23
+
- content: "The quantum random number generator takes the current time from the CPU's clock as a seed to generate random numbers."
24
+
isCorrect: false
25
+
explanation: "The quantum random number generator doesn't use the CPU's clock to generate random numbers. A classical pseudo-random number generator would do that."
26
+
- content: "The quantum random number generator creates one qubit, measures it, and the result of the measurement is a random decimal number."
27
+
isCorrect: false
28
+
explanation: "The result of the measurement of a qubit is a random bit, not a random decimal number. This answer doesn't describe the logic behind the random number generator that you built in this module."
29
+
- content: "The quantum random number generator creates a bit string from the repetition of measurements of a qubit in superposition. Then, it takes the bit string and converts it to a decimal number."
30
+
isCorrect: true
31
+
explanation: "This statement describes the logic behind the random number generator that you built in this module."
32
+
33
+
- content: 'Which of the following structures are required for a Q# program to run successfully?'
34
+
choices:
35
+
- content: 'To run successfully, a Q# program must have a function.'
36
+
isCorrect: false
37
+
explanation: "A function isn't required in a Q# program."
38
+
- content: "To run successfully, a Q# program must have an entry point, which is the `Main` operation."
39
+
isCorrect: true
40
+
explanation: "Every Q# program must have an entry point, which is the `Main` operation, so the Q# compiler knows where to start the program."
41
+
- content: "To run successfully, a Q# program must have an entry point and at least one allocated qubit."
42
+
isCorrect: false
43
+
explanation: "You can write Q# programs that don't need to perform operations on a qubit. A Q# program without a qubit allocated can run successfully."
44
+
45
+
- content: "Consider a quantum operation `A` that acts on a single qubit. If you want to write a Q# program that applies `A` to a qubit `q`, which of the following statements is true?"
46
+
choices:
47
+
- content: "You allocate a qubit using `q = Qubit();` and then apply `A` to `q` using `A(q);`."
48
+
isCorrect: false
49
+
explanation: "To allocate a qubit, you must use the `use` keyword, `use q = Qubit();`."
50
+
- content: "You allocate a qubit using `use q = Qubit();` and then apply `A` to `q` using `A(q);`."
51
+
isCorrect: true
52
+
explanation: "You first allocate a qubit using `use` and then apply `A` to the qubit allocated using `A(q);`."
53
+
- content: "You allocate a qubit using `use q = Qubit();` and then apply `A` to `q` using `A[q];`."
54
+
isCorrect: false
55
+
explanation: "To apply an operation to a qubit, you must use parentheses, `A(q);`."
Copy file name to clipboardExpand all lines: learn-pr/quantum/qsharp-create-first-quantum-development-kit/includes/1-introduction.md
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,4 @@ After completing this module, you're able to:
18
18
- Basic knowledge of classical programming concepts.
19
19
- Install the latest version of [Visual Studio Code](https://code.visualstudio.com/download).
20
20
- Install the latest version of the [Azure Quantum Development Kit](https://marketplace.visualstudio.com/items?itemName=quantum.qsharp-lang-vscode) extension.
21
-
- You can also open [Visual Studio Code for the web](https://vscode.dev/quantum), which already includes the Quantum Development Kit extension.
22
-
23
-
21
+
- You can also open [Visual Studio Code for the web](https://vscode.dev/quantum), which already includes the Quantum Development Kit extension.
Copy file name to clipboardExpand all lines: learn-pr/quantum/qsharp-create-first-quantum-development-kit/includes/2-qsharp-structure.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
2
2
Before you start writing quantum programs, it's important to understand the structure and components of a Q# program.
3
3
4
-
In this unit, you'll review the main components of a Q# program.
4
+
In this unit, you review the main components of a Q# program.
5
5
6
6
## The `Main` operation
7
7
8
-
Every Q# program must contain at least one operation, which is usually the `Main` operation. The `Main` operation is the entry point of your program. By default, the Q# compiler starts executing a program from the `Main()` operation. Optionally, you can use the `@EntryPoint()` attribute to specify any operation in the program as the point of execution.
8
+
Every Q# program must contain at least one operation, which is usually the `Main` operation. The `Main` operation is the entry point of your program. By default, the Q# compiler starts executing a program from the `Main()` operation. Optionally, you can use the `@EntryPoint()` attribute to specify any operation in the program as the point of execution.
9
9
10
10
For example, the following code defines an entry point operation, `MeasureOneQubit`:
11
11
@@ -39,7 +39,7 @@ operation MeasureOneQubit() : Result {
39
39
40
40
## Quantum libraries
41
41
42
-
The Q# libraries contain functions and operations that you can use in quantum programs. When you call a function or operation from a library, you use the `import` directive and specify the library's namespace. For example, to use the `Message` function from the `Microsoft.Quantum.Intrinsic` namespace in the Standard quantum library, you do the following:
42
+
The Q# libraries contain functions and operations that you can use in quantum programs. When you call a function or operation from a library, you use the `import` directive and specify the library's namespace. For example, to use the `Message` function from the `Microsoft.Quantum.Intrinsic` namespace in the Standard quantum library, you use the following code:
43
43
44
44
```qsharp
45
45
// imports all functions and operations from Microsoft.Quantum.Intrinsic
@@ -79,10 +79,9 @@ To implement a measurement in the computational basis $\lbrace\ket{0},\ket{1}\rb
79
79
80
80
## Resetting qubits
81
81
82
-
In Q#, qubits must be in the $\ket{0}$ state by the time they are released. When you have finished using a qubit, you use the `Reset` operation to reset the qubit to the $\ket{0}$.
82
+
In Q#, qubits must be in the $\ket{0}$ state by the time they're released. When you finish using a qubit, you use the `Reset` operation to reset the qubit to the $\ket{0}$ state.
Copy file name to clipboardExpand all lines: learn-pr/quantum/qsharp-create-first-quantum-development-kit/includes/3-random-bit-generator.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ You build out your quantum random number generator in two phases. In this unit,
5
5
## Create the Q# program
6
6
7
7
1. Open Visual Studio Code and select **File > New Text File** to create a new file.
8
-
1. Save the file as `Main.qs`. This file will contain the Q# code for your program.
8
+
1. Save the file as `Main.qs`. This file contains the Q# code for your program.
9
9
10
10
## Define the `Main` operation
11
11
@@ -34,7 +34,7 @@ operation Main(): Result{
34
34
35
35
## Put the qubit into superposition
36
36
37
-
The qubit is in the $\ket{0}$ state, which isn't very useful for generating random numbers. You need to put the qubit into superposition. To do this, you apply the **Hadamard operation**, `H`, to the qubit. The Hadamard operation changes the state of the qubit and puts it into an equal superposition of $\ket{0}$ and $\ket{1}$.
37
+
The qubit is in the $\ket{0}$ state, which isn't useful for generating random numbers. You need to put the qubit into superposition. To do this, you apply the **Hadamard operation**, `H`, to the qubit. The Hadamard operation changes the state of the qubit and puts it into an equal superposition of $\ket{0}$ and $\ket{1}$.
38
38
39
39
$$ H \ket{0} = \frac{1}{\sqrt{2}} (\ket{0} + \ket{1}) $$
40
40
@@ -50,7 +50,7 @@ operation Main(): Result{
50
50
51
51
## Measure the qubit
52
52
53
-
At this point the qubit `q` has 50% chance of being measured in the |0〉 state and 50% chance of being measured in the |1〉 state. Thus, if you measure the qubit, you'll get a random bit, either 0 or 1, with equal 50% probability. The value of this bit is truly random, there's no way of knowing in advance the result of the measurement.
53
+
At this point, the qubit `q` has 50% chance of being measured in the |0〉 state and 50% chance of being measured in the |1〉 state. Thus, if you measure the qubit, you get a random bit, either 0 or 1, with equal 50% probability. The value of this bit is truly random, there's no way of knowing in advance the result of the measurement.
54
54
55
55
To measure the qubit value, use the `M` operation and store the measurement value in the `result` variable.
56
56
@@ -65,7 +65,7 @@ operation Main(): Result{
65
65
66
66
## Reset the qubit
67
67
68
-
In Q#, every qubit must be in the $\ket{0}$ state by the time they are released. You use `Reset(q)` to reset the qubit to the zero state.
68
+
In Q#, every qubit must be in the $\ket{0}$ state by the time they're released. You use `Reset(q)` to reset the qubit to the zero state.
69
69
70
70
```qsharp
71
71
operation Main(): Result{
@@ -109,7 +109,6 @@ operation Main() : Result {
109
109
H(q);
110
110
111
111
// Measure the qubit and store the result.
112
-
113
112
let result = M(q);
114
113
115
114
// Reset qubit to the |0〉 state.
@@ -122,7 +121,7 @@ operation Main() : Result {
122
121
123
122
## Run the program
124
123
125
-
To run your program on the built-in simulator, click**Run** above the `Main` operation or press **Ctrl+F5**. Your output appears in the debug console in the terminal.
124
+
To run your program on the built-in simulator, select**Run** above the `Main` operation or press **Ctrl+F5**. Your output appears in the debug console in the terminal.
126
125
127
126
The result is either `One` or `Zero`, which represents a truly random bit. You can run the program again to see a different result.
Copy file name to clipboardExpand all lines: learn-pr/quantum/qsharp-create-first-quantum-development-kit/includes/4-random-number-generator.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ In this unit, you implement the second phase of your quantum random number gener
4
4
5
5
In the previous unit, you created a random bit generator that generates a random bit by putting a qubit into superposition and measuring it.
6
6
7
-
When you measure the qubit, you'll get a random bit, either 0 or 1, with equal 50% probability. The value of this bit is truly random, there's no way of knowing what you get after the measurement. But how can you use this behavior to generate larger random numbers?
7
+
When you measure the qubit, you get a random bit, either 0 or 1, with equal 50% probability. The value of this bit is truly random, there's no way of knowing what you get after the measurement. But how can you use this behavior to generate larger random numbers?
8
8
9
9
Let's say you repeat the process four times, generating this sequence of binary digits:
10
10
@@ -42,7 +42,7 @@ Here, you expand on the `Main.qs` file to build larger random numbers.
42
42
43
43
### Import the required libraries
44
44
45
-
First, you need to import the required namespaces from the Q# Standard library to the program. The Q# compiler loads many common functions and operations automatically, however for the complete quantum random number generator, you need some additional functions and operations from two Q# namespaces: `Microsoft.Quantum.Math`and `Microsoft.Quantum.Convert`.
45
+
First, you need to import the required namespaces from the Q# Standard library to the program. The Q# compiler loads many common functions and operations automatically, however for the complete quantum random number generator, you need some more functions and operations from two Q# namespaces: `Microsoft.Quantum.Math`and `Microsoft.Quantum.Convert`.
46
46
47
47
Copy and paste the following `import` directives to the top of your `Main.qs` file:
48
48
@@ -65,8 +65,7 @@ The `GenerateRandomBit` operation should look like this:
65
65
// Set the qubit into superposition of 0 and 1 using the Hadamard
66
66
H(q);
67
67
68
-
// Measure the qubit and store the result.
69
-
68
+
// Measure the qubit and store the result.
70
69
let result = M(q);
71
70
72
71
// Reset qubit to the |0〉 state.
@@ -111,7 +110,7 @@ Let's take a moment to review the new code.
111
110
112
111
### Add an entry point
113
112
114
-
Finally, you add an entry point to the program. By default, the Q# compiler looks for a `Main` operation and starts processing there, no matter where it's located. The `Main` operation calls the `GenerateRandomNumberInRange` operation to generate a random number between 0 and a `max` number. In this example, you define the maximum value as 100.
113
+
Finally, you add an entry point to the program. By default, the Q# compiler looks for a `Main` operation and starts processing there, no matter where the operation is located. The `Main` operation calls the `GenerateRandomNumberInRange` operation to generate a random number between 0 and a `max` number. In this example, you define the maximum value as 100.
115
114
116
115
Copy and paste the following code to your `Main.qs` file:
1. Before running the program, you need to set the target profile to **Unrestricted**. Select **View** > **Command Palette**, search for QIR, select **Q#: Set the Azure Quantum QIR target profile**, and then select **Q#: unrestricted**.
184
-
1. To run your program, select **Run** from the list of commands above the `Main` operation or press **Ctrl+F5**. Your output will appear in the debug console.
182
+
1. Before running the program, you need to set the target profile to **Unrestricted**. Select **View** > **Command Palette**, search for *QIR*, select **Q#: Set the Azure Quantum QIR target profile**, and then select **Q#: unrestricted**.
183
+
1. To run your program, select **Run** from the list of commands above the `Main` operation or press **Ctrl+F5**. Your output displays in the debug console.
185
184
1. Run the program again to see a different result.
186
185
187
186
> [!NOTE]
188
-
> If the target profile is not set to **Unrestricted**, you will get an error when you run the program.
187
+
> If the target profile isn't set to **Unrestricted**, you get an error when you run the program.
189
188
190
189
Congratulations! Now you know how to combine classical logic with Q# to create a quantum random number generator.
Copy file name to clipboardExpand all lines: learn-pr/quantum/qsharp-create-first-quantum-development-kit/includes/6-summary.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,18 +4,17 @@ The Quantum Development Kit provides you with everything you need to start writi
4
4
5
5
In this module, we covered a lot. Here are a few key concepts to keep in mind:
6
6
7
-
* A Q# program must have an entry point, which is the `Main` operation.
8
-
* In Q#, you allocate a qubit by using the `use` keyword and the `Qubit` type. The qubit is always in the $\ket{0}$ state.
9
-
* Superposition is a quantum phenomenon where a qubit is in a combination of both zero and one states. If a qubit is in the $\ket{0}$ state, you can put it into superposition by using the `H` operation.
10
-
* In Q#, you use the `M` operation to measure qubits in the Z-basis. When measured, a qubit goes from being in superposition to one of the classical states.
11
-
* You can combine classical code with quantum code. This combination enables you to perform quantum computations and work with the results, all in the same program.
7
+
- A Q# program must have an entry point, which is the `Main` operation.
8
+
- In Q#, you allocate a qubit by using the `use` keyword and the `Qubit` type. The qubit is always in the $\ket{0}$ state.
9
+
- Superposition is a quantum phenomenon where a qubit is in a combination of both zero and one states. If a qubit is in the $\ket{0}$ state, you can put it into superposition by using the `H` operation.
10
+
- In Q#, you use the `M` operation to measure qubits in the Z-basis. When measured, a qubit goes from being in superposition to one of the classical states.
11
+
- You can combine classical code with quantum code. This combination enables you to perform quantum computations and work with the results, all in the same program.
12
12
13
13
## Next steps
14
14
15
-
The Quantum Development Kit includes a set of built-in Q# samples that you can use to learn more about Q# and quantum computing. To view the samples, open a blank Q# file in Visual Studio Code and type `sample`, then select the sample you want to view from the list of options. For example, you can find the Q# code in unit 2 under "Random Bit sample".
15
+
The Quantum Development Kit includes a set of built-in Q# samples that you can use to learn more about Q# and quantum computing. To view the samples, open a blank Q# file in Visual Studio Code and type `sample`, then select the sample you want to view from the list of options. For example, you can find the Q# code we used in unit 2 by selecting *Random Bit sample*.
16
16
17
17
## Learn more
18
18
19
-
* Explore the [Azure Quantum documentation](/quantum/?azure-portal=true).
20
-
* Learn quantum computing with the [Quantum Katas](https://quantum.microsoft.com/tools/quantum-katas).
21
-
19
+
- Explore the [Azure Quantum documentation](/quantum/?azure-portal=true).
20
+
- Learn quantum computing with the [Quantum Katas](https://quantum.microsoft.com/tools/quantum-katas).
0 commit comments