qsharp-lang 1.0.32-dev → 1.0.34-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/katas-content.generated.js +17 -17
- package/dist/log.js +2 -3
- package/dist/ux/ticks.d.ts +6 -0
- package/dist/ux/ticks.js +125 -0
- package/lib/node/qsc_wasm.cjs +85 -92
- package/lib/node/qsc_wasm.d.cts +1 -1
- package/lib/node/qsc_wasm_bg.wasm +0 -0
- package/lib/web/qsc_wasm.d.ts +1 -1
- package/lib/web/qsc_wasm.js +80 -90
- package/lib/web/qsc_wasm_bg.wasm +0 -0
- package/package.json +1 -1
- package/ux/colormap.ts +51 -0
- package/ux/data.ts +68 -0
- package/ux/estimatesOverview.tsx +238 -0
- package/ux/generate_report_code.py +243 -0
- package/ux/index.ts +4 -2
- package/ux/output_data.md +537 -0
- package/ux/qsharp-ux.css +37 -0
- package/ux/reTable.tsx +7 -28
- package/ux/report.ts +591 -0
- package/ux/resultsTable.tsx +35 -49
- package/ux/scatterChart.tsx +369 -0
- package/ux/spaceChart.tsx +2 -2
|
@@ -665,8 +665,8 @@ export default {
|
|
|
665
665
|
"title": "Prepare a Superposition of Two Basis States",
|
|
666
666
|
"description": {
|
|
667
667
|
"type": "text-content",
|
|
668
|
-
"asHtml": "<p><strong>Input:</strong> A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \\end{bmatrix}$.</p>\n<p><strong>Goal:</strong> Transform the system into the state $\\frac{1}{\\sqrt2}\\big(|00\\rangle - |
|
|
669
|
-
"asMarkdown": "**Input:** A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}$.\n\n**Goal:** Transform the system into the state $\\frac{1}{\\sqrt2}\\big(|00\\rangle - |
|
|
668
|
+
"asHtml": "<p><strong>Input:</strong> A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \\end{bmatrix}$.</p>\n<p><strong>Goal:</strong> Transform the system into the state $\\frac{1}{\\sqrt2}\\big(|00\\rangle - |10\\rangle\\big) = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ 0 \\\\ -1 \\\\ 0 \\end{bmatrix}$.</p>\n<blockquote>\n<p>Note that the quantum states are represented in little-endian format For a state $|qs_1 qs_0\\rangle$, the "first" qubit (<code>qs[0]</code> in a Q# qubit register) refers to the least-significant qubit $qs_0$, while the "second" qubit (<code>qs[1]</code> in a Q# register) refers to the most-significant qubit $qs_1$.</p>\n</blockquote>\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $\\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes |0\\rangle = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix}$.\n</details>\n",
|
|
669
|
+
"asMarkdown": "**Input:** A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}$.\n\n**Goal:** Transform the system into the state $\\frac{1}{\\sqrt2}\\big(|00\\rangle - |10\\rangle\\big) = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ -1 \\\\\\ 0 \\end{bmatrix}$.\n\n> Note that the quantum states are represented in little-endian format For a state $|qs_1 qs_0\\rangle$, the \"first\" qubit (`qs[0]` in a Q# qubit register) refers to the least-significant qubit $qs_0$, while the \"second\" qubit (`qs[1]` in a Q# register) refers to the most-significant qubit $qs_1$.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $\\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes |0\\rangle = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix}$.\n</details>\n"
|
|
670
670
|
},
|
|
671
671
|
"sourceIds": [
|
|
672
672
|
"KatasLibrary.qs",
|
|
@@ -679,8 +679,8 @@ export default {
|
|
|
679
679
|
"items": [
|
|
680
680
|
{
|
|
681
681
|
"type": "text-content",
|
|
682
|
-
"asHtml": "<p>We begin in the same state as the previous excercise:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle$$</p>\n<p>The goal state can be separated as follows:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\
|
|
683
|
-
"asMarkdown": "\nWe begin in the same state as the previous excercise:\n$$ \\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle$$\n\nThe goal state can be separated as follows:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\
|
|
682
|
+
"asHtml": "<p>We begin in the same state as the previous excercise:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle$$</p>\n<p>The goal state can be separated as follows:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 0 \\\\ -1 \\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes |0\\rangle$$</p>\n<p>This means that the first qubit is already in the state we want it to be, but the second qubit needs to be transformed from the $ \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} $ into $ \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\ -1\\end{bmatrix}$ state.</p>\n<p>First, we apply the <strong>X</strong> gate to the second qubit; this performs the following transformation:\n$$ X |0\\rangle = \\begin{bmatrix}0 & 1 \\\\ 1 & 0 \\end{bmatrix} \\cdot \\begin{bmatrix}1 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = |1\\rangle $$</p>\n<p>Second, we apply the <strong>H</strong> gate to the second qubit; this transforms its state into the desired one:\n$$ H|1\\rangle = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix}$$</p>\n",
|
|
683
|
+
"asMarkdown": "\nWe begin in the same state as the previous excercise:\n$$ \\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle$$\n\nThe goal state can be separated as follows:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ -1 \\\\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes |0\\rangle$$\n\nThis means that the first qubit is already in the state we want it to be, but the second qubit needs to be transformed from the $ \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} $ into $ \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1 \\\\\\ -1\\end{bmatrix}$ state.\n\nFirst, we apply the **X** gate to the second qubit; this performs the following transformation:\n$$ X |0\\rangle = \\begin{bmatrix}0 & 1 \\\\\\ 1 & 0 \\end{bmatrix} \\cdot \\begin{bmatrix}1 \\\\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix} = |1\\rangle $$\n\nSecond, we apply the **H** gate to the second qubit; this transforms its state into the desired one:\n$$ H|1\\rangle = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix}$$"
|
|
684
684
|
},
|
|
685
685
|
{
|
|
686
686
|
"type": "solution",
|
|
@@ -696,8 +696,8 @@ export default {
|
|
|
696
696
|
"title": " Prepare a Superposition with Real Amplitudes",
|
|
697
697
|
"description": {
|
|
698
698
|
"type": "text-content",
|
|
699
|
-
"asHtml": "<p><strong>Input:</strong> A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}$.</p>\n<p><strong>Goal:</strong> Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle
|
|
700
|
-
"asMarkdown": "\n**Input:** A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix}$.\n\n**Goal:** Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle
|
|
699
|
+
"asHtml": "<p><strong>Input:</strong> A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}$.</p>\n<p><strong>Goal:</strong> Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle + |01\\rangle - |10\\rangle - |11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\ 1 \\\\ -1 \\\\ -1 \\end{bmatrix}$.</p>\n<blockquote>\n<p>Note that the quantum states are represented in little-endian format For a state $|qs_1 qs_0\\rangle$, the "first" qubit (<code>qs[0]</code> in a Q# qubit register) refers to the least-significant qubit $qs_0$, while the "second" qubit (<code>qs[1]</code> in a Q# register) refers to the most-significant qubit $qs_1$.</p>\n</blockquote>\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $\\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + |1\\rangle\\big) = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ 1 \\end{bmatrix}$.\n</details>\n",
|
|
700
|
+
"asMarkdown": "\n**Input:** A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix}$.\n\n**Goal:** Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle + |01\\rangle - |10\\rangle - |11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\\\ 1 \\\\\\ -1 \\\\\\ -1 \\end{bmatrix}$.\n\n> Note that the quantum states are represented in little-endian format For a state $|qs_1 qs_0\\rangle$, the \"first\" qubit (`qs[0]` in a Q# qubit register) refers to the least-significant qubit $qs_0$, while the \"second\" qubit (`qs[1]` in a Q# register) refers to the most-significant qubit $qs_1$.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $\\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + |1\\rangle\\big) = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ 1 \\end{bmatrix}$.\n</details>\n"
|
|
701
701
|
},
|
|
702
702
|
"sourceIds": [
|
|
703
703
|
"KatasLibrary.qs",
|
|
@@ -710,8 +710,8 @@ export default {
|
|
|
710
710
|
"items": [
|
|
711
711
|
{
|
|
712
712
|
"type": "text-content",
|
|
713
|
-
"asHtml": "<p>Again, to start we will represent the goal state as a tensor product of single-qubit states; this gives us the following representation:</p>\n<p>$$ \\frac{1}{2}\\big(|00\\rangle
|
|
714
|
-
"asMarkdown": "\nAgain, to start we will represent the goal state as a tensor product of single-qubit states; this gives us the following representation:\n\n$$ \\frac{1}{2}\\big(|00\\rangle
|
|
713
|
+
"asHtml": "<p>Again, to start we will represent the goal state as a tensor product of single-qubit states; this gives us the following representation:</p>\n<p>$$ \\frac{1}{2}\\big(|00\\rangle + |01\\rangle - |10\\rangle - |11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\ 1 \\\\ -1 \\\\ -1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + |1\\rangle\\big)$$</p>\n<p>This time we need to transform both the first and the second qubits. Let's start with the first qubit. Applying the <strong>H</strong> gate transforms its state as follows:</p>\n<p>$$ H|0\\rangle = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(|0\\rangle + |1\\rangle\\big)$$</p>\n<p>For the second qubit we can use the same transformation we've seen in the "Prepare a Superposition of Two Basis States" exercise; this will give the desired end state.</p>\n",
|
|
714
|
+
"asMarkdown": "\nAgain, to start we will represent the goal state as a tensor product of single-qubit states; this gives us the following representation:\n\n$$ \\frac{1}{2}\\big(|00\\rangle + |01\\rangle - |10\\rangle - |11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\\\ 1 \\\\\\ -1 \\\\\\ -1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + |1\\rangle\\big)$$\n\nThis time we need to transform both the first and the second qubits. Let's start with the first qubit. Applying the **H** gate transforms its state as follows:\n\n$$ H|0\\rangle = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 & 1 \\\\\\ 1 & -1 \\end{bmatrix} \\cdot \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2}\\big(|0\\rangle + |1\\rangle\\big)$$\n\nFor the second qubit we can use the same transformation we've seen in the \"Prepare a Superposition of Two Basis States\" exercise; this will give the desired end state."
|
|
715
715
|
},
|
|
716
716
|
{
|
|
717
717
|
"type": "solution",
|
|
@@ -727,8 +727,8 @@ export default {
|
|
|
727
727
|
"title": "Prepare a Superposition with Complex Amplitudes",
|
|
728
728
|
"description": {
|
|
729
729
|
"type": "text-content",
|
|
730
|
-
"asHtml": "<p><strong>Input:</strong> A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \\end{bmatrix}$.</p>\n<p><strong>Goal:</strong> Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle + e^{i\\pi/
|
|
731
|
-
"asMarkdown": "\n**Input:** A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}$.\n\n**Goal:** Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle + e^{i\\pi/
|
|
730
|
+
"asHtml": "<p><strong>Input:</strong> A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \\end{bmatrix}$.</p>\n<p><strong>Goal:</strong> Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle + e^{i\\pi/2}|01\\rangle + e^{i\\pi/4}|10\\rangle + e^{3i\\pi/4}|11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\ e^{i\\pi/2} \\ e^{i\\pi/4} \\ e^{3i\\pi/4} \\end{bmatrix}$.</p>\n<blockquote>\n<p>Note that the quantum states are represented in little-endian format For a state $|qs_1 qs_0\\rangle$, the "first" qubit (<code>qs[0]</code> in a Q# qubit register) refers to the least-significant qubit $qs_0$, while the "second" qubit (<code>qs[1]</code> in a Q# register) refers to the most-significant qubit $qs_1$.</p>\n</blockquote>\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $\\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/2}|1\\rangle\\big) = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/4} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\end{bmatrix}$.\n</details>\n",
|
|
731
|
+
"asMarkdown": "\n**Input:** A two-qubit system in the basis state $|00\\rangle = \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix}$.\n\n**Goal:** Transform the system into the state $\\frac{1}{2}\\big(|00\\rangle + e^{i\\pi/2}|01\\rangle + e^{i\\pi/4}|10\\rangle + e^{3i\\pi/4}|11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\\\ e^{i\\pi/4} \\\\ e^{3i\\pi/4} \\end{bmatrix}$.\n\n> Note that the quantum states are represented in little-endian format For a state $|qs_1 qs_0\\rangle$, the \"first\" qubit (`qs[0]` in a Q# qubit register) refers to the least-significant qubit $qs_0$, while the \"second\" qubit (`qs[1]` in a Q# register) refers to the most-significant qubit $qs_1$.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $\\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/2}|1\\rangle\\big) = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/4} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\end{bmatrix}$.\n</details>\n"
|
|
732
732
|
},
|
|
733
733
|
"sourceIds": [
|
|
734
734
|
"KatasLibrary.qs",
|
|
@@ -741,8 +741,8 @@ export default {
|
|
|
741
741
|
"items": [
|
|
742
742
|
{
|
|
743
743
|
"type": "text-content",
|
|
744
|
-
"asHtml": "<p>The start state is the same as the previous exercises:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle $$</p>\n<p>The goal state, factored as a tensor product, looks like this (remember that $e^{3i\\pi/4} = e^{i\\pi/4} e^{i\\pi/2}$):</p>\n<p>$$\n\\frac{1}{2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/
|
|
745
|
-
"asMarkdown": "\nThe start state is the same as the previous exercises:\n$$ \\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle $$\n\nThe goal state, factored as a tensor product, looks like this (remember that $e^{3i\\pi/4} = e^{i\\pi/4} e^{i\\pi/2}$):\n\n$$\n\\frac{1}{2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/
|
|
744
|
+
"asHtml": "<p>The start state is the same as the previous exercises:\n$$ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle $$</p>\n<p>The goal state, factored as a tensor product, looks like this (remember that $e^{3i\\pi/4} = e^{i\\pi/4} e^{i\\pi/2}$):</p>\n<p>$$\n\\frac{1}{2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\\\ e^{i\\pi/4} \\\\ e^{3i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\end{bmatrix} =\n\\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/2}|1\\rangle\\big) $$</p>\n<p>We will again need to adjust the states of both qubits independently.</p>\n<p>For the first qubit, we'll start by applying the <strong>H</strong> gate, getting the state $\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix}$, as we've seen in the previous task. Afterwards we'll apply the <strong>S</strong> gate with the following result:</p>\n<p>$$ \\begin{bmatrix} 1 & 0 \\\\ 0 & i \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ i \\end{bmatrix}$$</p>\n<p>If we recall that $i = e^{i\\pi/2}$, we can write the final state of the first qubit as:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\end{bmatrix} $$</p>\n<p>For the second qubit. we'll apply the <strong>H</strong> gate, followed by the <strong>T</strong> gate, with the following result:\n$$ \\begin{bmatrix} 1 & 0 \\\\ 0 & e^{i\\pi/4} \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\end{bmatrix} $$</p>\n",
|
|
745
|
+
"asMarkdown": "\nThe start state is the same as the previous exercises:\n$$ \\begin{bmatrix} 1 \\\\\\ 0 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\otimes \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} = |0\\rangle \\otimes |0\\rangle $$\n\nThe goal state, factored as a tensor product, looks like this (remember that $e^{3i\\pi/4} = e^{i\\pi/4} e^{i\\pi/2}$):\n\n$$\n\\frac{1}{2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\\\\\ e^{i\\pi/4} \\\\\\ e^{3i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/4} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\end{bmatrix} =\n\\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/2}|1\\rangle\\big) $$\n\nWe will again need to adjust the states of both qubits independently.\n\nFor the first qubit, we'll start by applying the **H** gate, getting the state $\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ 1 \\end{bmatrix}$, as we've seen in the previous task. Afterwards we'll apply the **S** gate with the following result:\n\n$$ \\begin{bmatrix} 1 & 0 \\\\\\ 0 & i \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ i \\end{bmatrix}$$\n\nIf we recall that $i = e^{i\\pi/2}$, we can write the final state of the first qubit as:\n$$ \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\end{bmatrix} $$\n\nFor the second qubit. we'll apply the **H** gate, followed by the **T** gate, with the following result:\n$$ \\begin{bmatrix} 1 & 0 \\\\\\ 0 & e^{i\\pi/4} \\end{bmatrix} \\cdot \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ 1 \\end{bmatrix} = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/4} \\end{bmatrix} $$"
|
|
746
746
|
},
|
|
747
747
|
{
|
|
748
748
|
"type": "solution",
|
|
@@ -2341,23 +2341,23 @@ export default {
|
|
|
2341
2341
|
},
|
|
2342
2342
|
{
|
|
2343
2343
|
"id": "multi_qubit_systems__common.qs",
|
|
2344
|
-
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.
|
|
2344
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation CheckEqualOnZeroState(\n testImpl : (Qubit[] => Unit is Adj + Ctl),\n refImpl : (Qubit[] => Unit is Adj + Ctl)) : Bool {\n\n let isCorrect = CheckOperationsEquivalenceOnZeroStateStrict(testImpl, refImpl, 2);\n\n // Output different feedback to the user depending on whether the exercise was correct.\n if isCorrect {\n Message(\"Correct!\");\n } else {\n Message(\"Incorrect.\");\n use target = Qubit[2]; // |00〉\n ShowQuantumStateComparison(target, testImpl, refImpl);\n ResetAll(target);\n }\n isCorrect\n }\n\n}\n"
|
|
2345
2345
|
},
|
|
2346
2346
|
{
|
|
2347
2347
|
"id": "multi_qubit_systems__prepare_basis_state__verification.qs",
|
|
2348
|
-
"code": "namespace Kata.Verification {\n operation PrepareBasisState_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[0]);\n X(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n
|
|
2348
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareBasisState_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[0]);\n X(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n CheckEqualOnZeroState(Kata.PrepareBasisState, PrepareBasisState_Reference)\n }\n}\n"
|
|
2349
2349
|
},
|
|
2350
2350
|
{
|
|
2351
2351
|
"id": "multi_qubit_systems__prepare_superposition__verification.qs",
|
|
2352
|
-
"code": "namespace Kata.Verification {\n operation PrepareSuperposition_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[1]);\n H(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n
|
|
2352
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareSuperposition_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n X(qs[1]);\n H(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n CheckEqualOnZeroState(Kata.PrepareSuperposition, PrepareSuperposition_Reference)\n }\n}\n"
|
|
2353
2353
|
},
|
|
2354
2354
|
{
|
|
2355
2355
|
"id": "multi_qubit_systems__prepare_with_real__verification.qs",
|
|
2356
|
-
"code": "namespace Kata.Verification {\n operation PrepareWithReal_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n X(qs[1]);\n H(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n
|
|
2356
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareWithReal_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n X(qs[1]);\n H(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n CheckEqualOnZeroState(Kata.PrepareWithReal, PrepareWithReal_Reference)\n }\n}\n"
|
|
2357
2357
|
},
|
|
2358
2358
|
{
|
|
2359
2359
|
"id": "multi_qubit_systems__prepare_with_complex__verification.qs",
|
|
2360
|
-
"code": "namespace Kata.Verification {\n operation PrepareWithComplex_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n H(qs[1]);\n S(qs[0]);\n T(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n
|
|
2360
|
+
"code": "namespace Kata.Verification {\n open Microsoft.Quantum.Katas;\n\n operation PrepareWithComplex_Reference(qs : Qubit[]) : Unit is Adj + Ctl {\n H(qs[0]);\n H(qs[1]);\n S(qs[0]);\n T(qs[1]);\n }\n\n @EntryPoint()\n operation CheckSolution() : Bool {\n CheckEqualOnZeroState(Kata.PrepareWithComplex, PrepareWithComplex_Reference)\n }\n}\n"
|
|
2361
2361
|
},
|
|
2362
2362
|
{
|
|
2363
2363
|
"id": "multi_qubit_gates__compound_gate__Verification.qs",
|
package/dist/log.js
CHANGED
|
@@ -55,9 +55,8 @@ export const log = {
|
|
|
55
55
|
* @param args - The format string and args to log, e.g. ["Index of %s is %i", str, index]
|
|
56
56
|
*/
|
|
57
57
|
logWithLevel(level, target, ...args) {
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const outArgs = [`[%s] ${args[0]}`, target || "", ...trailingArgs];
|
|
58
|
+
const [firstArg, ...trailingArgs] = args;
|
|
59
|
+
const outArgs = [`[${target || ""}] ${firstArg}`, ...trailingArgs];
|
|
61
60
|
switch (level) {
|
|
62
61
|
case 1:
|
|
63
62
|
log.error(...outArgs);
|
package/dist/ux/ticks.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
export function CreateIntegerTicks(min, max) {
|
|
4
|
+
if (max < min || min <= 0) {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
const numberFormat = new Intl.NumberFormat();
|
|
8
|
+
const l = Math.round(10 ** Math.floor(Math.log10(min)));
|
|
9
|
+
const r = Math.round(10 ** Math.ceil(Math.log10(max)));
|
|
10
|
+
const result = [];
|
|
11
|
+
for (let i = l; i <= r; i *= 10) {
|
|
12
|
+
if (i >= min && i <= max) {
|
|
13
|
+
result.push({ value: i, label: numberFormat.format(i) });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (result.length == 0) {
|
|
17
|
+
let step = l;
|
|
18
|
+
while (step >= 1) {
|
|
19
|
+
let i = Math.ceil(min / step) * step;
|
|
20
|
+
while (i <= max) {
|
|
21
|
+
result.push({ value: i, label: numberFormat.format(i) });
|
|
22
|
+
i += step;
|
|
23
|
+
}
|
|
24
|
+
if (result.length > 0) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
step /= 10;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
const predefinedTimeTicks = [
|
|
33
|
+
{ tick: { value: 1, label: "1 nanosecond" }, plural: "nanoseconds" },
|
|
34
|
+
{ tick: { value: 1e3, label: "1 microsecond" }, plural: "microseconds" },
|
|
35
|
+
{ tick: { value: 1e6, label: "1 millisecond" }, plural: "milliseconds" },
|
|
36
|
+
{ tick: { value: 1e9, label: "1 second" }, plural: "seconds" },
|
|
37
|
+
{ tick: { value: 6e10, label: "1 minute" }, plural: "minutes" },
|
|
38
|
+
{ tick: { value: 3.6e12, label: "1 hour" }, plural: "hours" },
|
|
39
|
+
{ tick: { value: 8.64e13, label: "1 day" }, plural: "days" },
|
|
40
|
+
{ tick: { value: 6.048e14, label: "1 week" }, plural: "weeks" },
|
|
41
|
+
{ tick: { value: 2.592e15, label: "1 month" }, plural: "months" },
|
|
42
|
+
{ tick: { value: 3.1536e16, label: "1 year" }, plural: "years" },
|
|
43
|
+
{ tick: { value: 3.1536e17, label: "1 decade" }, plural: "decades" },
|
|
44
|
+
{ tick: { value: 3.1536e18, label: "1 century" }, plural: "centuries" },
|
|
45
|
+
];
|
|
46
|
+
export function CreateTimeTicks(min, max) {
|
|
47
|
+
if (max < min || min <= 0) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
let l = 0;
|
|
51
|
+
while (l < predefinedTimeTicks.length &&
|
|
52
|
+
predefinedTimeTicks[l].tick.value <= min) {
|
|
53
|
+
l++;
|
|
54
|
+
}
|
|
55
|
+
let r = l;
|
|
56
|
+
if (l > 0) {
|
|
57
|
+
l--;
|
|
58
|
+
}
|
|
59
|
+
if (r >= predefinedTimeTicks.length) {
|
|
60
|
+
r = predefinedTimeTicks.length - 1;
|
|
61
|
+
}
|
|
62
|
+
while (r < predefinedTimeTicks.length - 1 &&
|
|
63
|
+
predefinedTimeTicks[r].tick.value <= max) {
|
|
64
|
+
r++;
|
|
65
|
+
}
|
|
66
|
+
const result = [];
|
|
67
|
+
for (let i = l; i <= r; i++) {
|
|
68
|
+
if (predefinedTimeTicks[i].tick.value >= min &&
|
|
69
|
+
predefinedTimeTicks[i].tick.value <= max) {
|
|
70
|
+
result.push(predefinedTimeTicks[i].tick);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (result.length == 0) {
|
|
74
|
+
if (l < predefinedTimeTicks.length - 1) {
|
|
75
|
+
let coeff = 10 **
|
|
76
|
+
Math.floor(Math.log10(predefinedTimeTicks[l + 1].tick.value /
|
|
77
|
+
predefinedTimeTicks[l].tick.value));
|
|
78
|
+
do {
|
|
79
|
+
let i = 1;
|
|
80
|
+
let val = 0;
|
|
81
|
+
do {
|
|
82
|
+
val = predefinedTimeTicks[l].tick.value * i * coeff;
|
|
83
|
+
if (val >= min && val <= max) {
|
|
84
|
+
result.push({
|
|
85
|
+
value: val,
|
|
86
|
+
label: (i * coeff).toString() + " " + predefinedTimeTicks[l].plural,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
i++;
|
|
90
|
+
} while (
|
|
91
|
+
// just a single tick in case of 1, 10 or 100
|
|
92
|
+
(i > 2 || result.length < 1) &&
|
|
93
|
+
val < predefinedTimeTicks[l + 1].tick.value);
|
|
94
|
+
coeff /= 10;
|
|
95
|
+
} while (result.length < 1 && coeff >= 1);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// > century
|
|
99
|
+
let l = predefinedTimeTicks.length - 1;
|
|
100
|
+
do {
|
|
101
|
+
let coeff = 10 ** Math.floor(Math.log10(max / predefinedTimeTicks[l].tick.value));
|
|
102
|
+
do {
|
|
103
|
+
let i = 1;
|
|
104
|
+
let val = 0;
|
|
105
|
+
do {
|
|
106
|
+
val = predefinedTimeTicks[l].tick.value * i * coeff;
|
|
107
|
+
if (val >= min && val <= max) {
|
|
108
|
+
result.push({
|
|
109
|
+
value: val,
|
|
110
|
+
label: (i * coeff).toString() + " " + predefinedTimeTicks[l].plural,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
i++;
|
|
114
|
+
} while (
|
|
115
|
+
// just a single tick in case of 1, 10 or 100
|
|
116
|
+
(i > 2 || result.length < 1) &&
|
|
117
|
+
val < max);
|
|
118
|
+
coeff /= 10;
|
|
119
|
+
} while (result.length < 1 && coeff >= 1);
|
|
120
|
+
l--;
|
|
121
|
+
} while (result.length < 1 && l >= 0);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|