qsharp-lang 1.0.34-dev → 1.1.0-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/browser.d.ts +2 -2
- package/dist/browser.js +1 -0
- package/dist/compiler/common.d.ts +1 -1
- package/dist/compiler/compiler.d.ts +1 -1
- package/dist/compiler/compiler.js +1 -2
- package/dist/debug-service/debug-service.d.ts +0 -1
- package/dist/debug-service/debug-service.js +2 -44
- package/dist/katas-content.generated.js +18 -18
- package/dist/language-service/language-service.d.ts +15 -18
- package/dist/language-service/language-service.js +17 -189
- package/dist/main.d.ts +1 -0
- package/dist/main.js +1 -0
- package/dist/samples.generated.d.ts +8 -2
- package/dist/samples.generated.js +18 -0
- package/dist/utils.d.ts +24 -0
- package/dist/{ux/ticks.js → utils.js} +23 -0
- package/lib/node/qsc_wasm.cjs +23 -23
- package/lib/node/qsc_wasm.d.cts +36 -36
- package/lib/node/qsc_wasm_bg.wasm +0 -0
- package/lib/web/qsc_wasm.d.ts +36 -36
- package/lib/web/qsc_wasm.js +23 -23
- package/lib/web/qsc_wasm_bg.wasm +0 -0
- package/package.json +1 -1
- package/ux/data.ts +0 -3
- package/ux/estimatesOverview.tsx +148 -81
- package/ux/estimatesPanel.tsx +94 -0
- package/ux/generate_report_code.py +1 -1
- package/ux/histogram.tsx +0 -1
- package/ux/index.ts +1 -0
- package/ux/output_data.md +1 -1
- package/ux/qsharp-ux.css +63 -20
- package/ux/report.ts +3 -3
- package/ux/resultsTable.tsx +55 -32
- package/ux/scatterChart.tsx +216 -285
- package/ux/tsconfig.json +0 -1
- package/dist/ux/ticks.d.ts +0 -6
- package/dist/vsdiagnostic.d.ts +0 -19
- package/dist/vsdiagnostic.js +0 -127
package/dist/browser.d.ts
CHANGED
|
@@ -23,11 +23,11 @@ export { type CompilerState } from "./compiler/compiler.js";
|
|
|
23
23
|
export { QscEventTarget } from "./compiler/events.js";
|
|
24
24
|
export { getAllKatas, getExerciseSources, getKata, type ContentItem, type Example, type Exercise, type ExplainedSolution, type ExplainedSolutionItem, type Kata, type KataSection, type Lesson, type LessonItem, type Question, } from "./katas.js";
|
|
25
25
|
export { default as samples } from "./samples.generated.js";
|
|
26
|
-
export { type VSDiagnostic } from "./vsdiagnostic.js";
|
|
27
26
|
export { log, type LogLevel, type TargetProfile };
|
|
28
27
|
export type { ICompilerWorker, ICompiler };
|
|
29
28
|
export type { ILanguageServiceWorker, ILanguageService };
|
|
30
29
|
export type { IDebugServiceWorker, IDebugService };
|
|
31
|
-
export type { IBreakpointSpan, IStackFrame } from "../lib/web/qsc_wasm.js";
|
|
30
|
+
export type { IBreakpointSpan, IStackFrame, IPosition, IRange, ILocation, VSDiagnostic, } from "../lib/web/qsc_wasm.js";
|
|
32
31
|
export { type IStructStepResult, StepResultId } from "../lib/web/qsc_wasm.js";
|
|
33
32
|
export { type LanguageServiceEvent } from "./language-service/language-service.js";
|
|
33
|
+
export * as utils from "./utils.js";
|
package/dist/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VSDiagnostic } from "
|
|
1
|
+
import { type VSDiagnostic } from "../../lib/web/qsc_wasm.js";
|
|
2
2
|
import { IServiceProxy, ServiceState } from "../worker-proxy.js";
|
|
3
3
|
import { IQscEventTarget } from "./events.js";
|
|
4
4
|
type Wasm = typeof import("../../lib/node/qsc_wasm.cjs");
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import { log } from "../log.js";
|
|
4
|
-
import { mapDiagnostics } from "../vsdiagnostic.js";
|
|
5
4
|
import { eventStringToMsg } from "./common.js";
|
|
6
5
|
import { makeEvent } from "./events.js";
|
|
7
6
|
export class Compiler {
|
|
@@ -24,7 +23,7 @@ export class Compiler {
|
|
|
24
23
|
languageService.stop_background_work();
|
|
25
24
|
await work;
|
|
26
25
|
languageService.free();
|
|
27
|
-
return
|
|
26
|
+
return diags;
|
|
28
27
|
}
|
|
29
28
|
async getQir(sources) {
|
|
30
29
|
return this.wasm.get_qir(sources);
|
|
@@ -19,7 +19,6 @@ export type IDebugServiceWorker = IDebugService & IServiceProxy;
|
|
|
19
19
|
export declare class QSharpDebugService implements IDebugService {
|
|
20
20
|
private wasm;
|
|
21
21
|
private debugService;
|
|
22
|
-
private code;
|
|
23
22
|
constructor(wasm: QscWasm);
|
|
24
23
|
loadSource(sources: [string, string][], target: TargetProfile, entry: string | undefined): Promise<string>;
|
|
25
24
|
getStackFrames(): Promise<IStackFrame[]>;
|
|
@@ -3,46 +3,17 @@
|
|
|
3
3
|
import { eventStringToMsg } from "../compiler/common.js";
|
|
4
4
|
import { makeEvent } from "../compiler/events.js";
|
|
5
5
|
import { log } from "../log.js";
|
|
6
|
-
import { mapUtf8UnitsToUtf16Units } from "../vsdiagnostic.js";
|
|
7
6
|
export class QSharpDebugService {
|
|
8
7
|
constructor(wasm) {
|
|
9
|
-
// We need to keep a copy of the code for mapping diagnostics to utf16 offsets
|
|
10
|
-
this.code = {};
|
|
11
8
|
log.info("Constructing a QSharpDebugService instance");
|
|
12
9
|
this.wasm = wasm;
|
|
13
10
|
this.debugService = new wasm.DebugService();
|
|
14
11
|
}
|
|
15
12
|
async loadSource(sources, target, entry) {
|
|
16
|
-
for (const [path, source] of sources) {
|
|
17
|
-
this.code[path] = source;
|
|
18
|
-
}
|
|
19
13
|
return this.debugService.load_source(sources, target, entry);
|
|
20
14
|
}
|
|
21
15
|
async getStackFrames() {
|
|
22
|
-
|
|
23
|
-
const stack_frames = await Promise.all(stack_frame_list.frames.map(async (frame) => {
|
|
24
|
-
// get any missing sources if possible
|
|
25
|
-
if (!(frame.path in this.code)) {
|
|
26
|
-
const content = await this.wasm.get_library_source_content(frame.path);
|
|
27
|
-
if (content) {
|
|
28
|
-
this.code[frame.path] = content;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (frame.path in this.code) {
|
|
32
|
-
const mappedSpan = mapUtf8UnitsToUtf16Units([frame.lo, frame.hi], this.code[frame.path]);
|
|
33
|
-
return {
|
|
34
|
-
...frame,
|
|
35
|
-
lo: mappedSpan[frame.lo],
|
|
36
|
-
hi: mappedSpan[frame.hi],
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
// We don't have a source file for this frame,
|
|
41
|
-
// and we couldn't load it, so just return it as-is
|
|
42
|
-
return frame;
|
|
43
|
-
}
|
|
44
|
-
}));
|
|
45
|
-
return stack_frames;
|
|
16
|
+
return this.debugService.get_stack_frames().frames;
|
|
46
17
|
}
|
|
47
18
|
async evalNext(bps, eventHandler) {
|
|
48
19
|
const event_cb = (msg) => onCompilerEvent(msg, eventHandler);
|
|
@@ -65,20 +36,7 @@ export class QSharpDebugService {
|
|
|
65
36
|
return this.debugService.eval_continue(event_cb, ids);
|
|
66
37
|
}
|
|
67
38
|
async getBreakpoints(path) {
|
|
68
|
-
|
|
69
|
-
// Get a map of the Rust source positions to the JavaScript source positions
|
|
70
|
-
const positions = [];
|
|
71
|
-
breakpoint_list.spans.forEach((span) => {
|
|
72
|
-
positions.push(span.lo);
|
|
73
|
-
positions.push(span.hi);
|
|
74
|
-
});
|
|
75
|
-
const positionMap = mapUtf8UnitsToUtf16Units(positions, this.code[path]);
|
|
76
|
-
const breakpoint_spans = breakpoint_list.spans.map((span) => ({
|
|
77
|
-
id: span.id,
|
|
78
|
-
lo: positionMap[span.lo],
|
|
79
|
-
hi: positionMap[span.hi],
|
|
80
|
-
}));
|
|
81
|
-
return breakpoint_spans;
|
|
39
|
+
return this.debugService.get_breakpoints(path).spans;
|
|
82
40
|
}
|
|
83
41
|
async captureQuantumState() {
|
|
84
42
|
const state = this.debugService.capture_quantum_state();
|
|
@@ -71,8 +71,8 @@ export default {
|
|
|
71
71
|
"items": [
|
|
72
72
|
{
|
|
73
73
|
"type": "text-content",
|
|
74
|
-
"asHtml": "<p>The basic building block of a classical computer is the bit - a single memory cell that is either in state $0$ or in state $1$. Similarly, the basic building block of a quantum computer is the quantum bit, or <strong>qubit</strong>. Like the classical bit, a qubit can be in state $0$ or in state $1$. Unlike the classical bit, however, the qubit isn't limited to just those two states - it may also be in a combination, or <strong>superposition</strong> of those states.</p>\n<blockquote>\n<p>A common misconception about quantum computing is that a qubit is always in state $1$ or state $0$, we just don't know which one until we "measure" it. That is not the case. A qubit in a superposition is in a linear combination of the states 0 and 1. When a qubit is measured, it is forced to collapse into one state or the other - in other words, measuring a qubit is a drastic process that changes its initial state.</p>\n</blockquote>\n<h2>Matrix Representation</h2>\n<p>The state of a qubit is represented by a complex vector of size 2:</p>\n<p>$$\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$$</p>\n<p>Here $\\alpha$ and $\\beta$ are complex numbers. $\\alpha$ represents how "close" the qubit is to state $0$, and $\\beta$ represents how "close" the qubit is to state $1$. This vector is normalized: $|\\alpha|^2 + |\\beta|^2 = 1$.\n
|
|
75
|
-
"asMarkdown": "\nThe basic building block of a classical computer is the bit - a single memory cell that is either in state $0$ or in state $1$. Similarly, the basic building block of a quantum computer is the quantum bit, or **qubit**. Like the classical bit, a qubit can be in state $0$ or in state $1$. Unlike the classical bit, however, the qubit isn't limited to just those two states - it may also be in a combination, or **superposition** of those states.\n\n> A common misconception about quantum computing is that a qubit is always in state $1$ or state $0$, we just don't know which one until we \"measure\" it. That is not the case. A qubit in a superposition is in a linear combination of the states 0 and 1. When a qubit is measured, it is forced to collapse into one state or the other - in other words, measuring a qubit is a drastic process that changes its initial state.\n\n## Matrix Representation\n\nThe state of a qubit is represented by a complex vector of size 2:\n\n$$\\begin{bmatrix} \\alpha \\\\\\ \\beta \\end{bmatrix}$$\n\nHere $\\alpha$ and $\\beta$ are complex numbers. $\\alpha$ represents how \"close\" the qubit is to state $0$, and $\\beta$ represents how \"close\" the qubit is to state $1$. This vector is normalized: $|\\alpha|^2 + |\\beta|^2 = 1$.\n
|
|
74
|
+
"asHtml": "<p>The basic building block of a classical computer is the bit - a single memory cell that is either in state $0$ or in state $1$. Similarly, the basic building block of a quantum computer is the quantum bit, or <strong>qubit</strong>. Like the classical bit, a qubit can be in state $0$ or in state $1$. Unlike the classical bit, however, the qubit isn't limited to just those two states - it may also be in a combination, or <strong>superposition</strong> of those states.</p>\n<blockquote>\n<p>A common misconception about quantum computing is that a qubit is always in state $1$ or state $0$, we just don't know which one until we "measure" it. That is not the case. A qubit in a superposition is in a linear combination of the states 0 and 1. When a qubit is measured, it is forced to collapse into one state or the other - in other words, measuring a qubit is a drastic process that changes its initial state.</p>\n</blockquote>\n<h2>Matrix Representation</h2>\n<p>The state of a qubit is represented by a complex vector of size 2:</p>\n<p>$$\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$$</p>\n<p>Here $\\alpha$ and $\\beta$ are complex numbers. $\\alpha$ represents how "close" the qubit is to state $0$, and $\\beta$ represents how "close" the qubit is to state $1$. This vector is normalized: $|\\alpha|^2 + |\\beta|^2 = 1$.\n$\\alpha$ and $\\beta$ are known as the probability amplitudes of states $0$ and $1$, respectively.</p>\n<h2>Basis States</h2>\n<p>A qubit in state $0$ would be represented by the following vector:</p>\n<p>$$\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$$</p>\n<p>Likewise, a qubit in state $1$ would be represented by this vector:</p>\n<p>$$\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$$</p>\n<p>Note that you can use scalar multiplication and vector addition to express any qubit state $\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix}$ as a sum of these two vectors with certain probability amplitudes $\\alpha$ and $\\beta$, known as linear combination.</p>\n<p>$$\n\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\ 0 \\end{bmatrix} + \\begin{bmatrix} 0 \\\\ \\beta \\end{bmatrix} =\n\\alpha \\cdot \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} + \\beta \\cdot \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}\n$$</p>\n<p>Because of this, qubit states $0$ and $1$ are known as basis states. These two vectors have two properties.</p>\n<ol>\n<li>They are normalized.</li>\n</ol>\n<p>$$\n\\langle \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} , \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\rangle =\n\\langle \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} , \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} \\rangle = 1\n$$</p>\n<ol start=\"2\">\n<li>They are orthogonal to each other.</li>\n</ol>\n<p>$$\n\\langle \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} , \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} \\rangle =\n\\langle \\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} , \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\rangle = 0\n$$</p>\n<blockquote>\n<p>As a reminder, $\\langle V , W \\rangle$ is the inner product of $V$ and $W$.</p>\n</blockquote>\n<p>This means that these vectors form an <strong>orthonormal basis</strong>. The basis of $\\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix}$ and $\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix}$ is called the <strong>computational basis</strong>, also known as the <strong>canonical basis</strong>.</p>\n<blockquote>\n<p>There exist other orthonormal bases, for example, the <strong>Hadamard basis</strong>, formed by the vectors</p>\n<p>$$\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix} \\text{ and } \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ -\\frac{1}{\\sqrt{2}} \\end{bmatrix}$$</p>\n<p>You can check that these vectors are normalized, and orthogonal to each other. Any qubit state can be expressed as a linear combination of these vectors:</p>\n<p>$$\n\\begin{bmatrix} \\alpha \\\\ \\beta \\end{bmatrix} =\n\\frac{\\alpha + \\beta}{\\sqrt{2}} \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix} +\n\\frac{\\alpha - \\beta}{\\sqrt{2}} \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\ -\\frac{1}{\\sqrt{2}} \\end{bmatrix}\n$$</p>\n<p>The Hadamard basis is widely used in quantum computing, for example, in the <a href=\"https://en.wikipedia.org/wiki/BB84\" target=\"_blank\">BB84 quantum key distribution protocol</a>.</p>\n</blockquote>\n",
|
|
75
|
+
"asMarkdown": "\nThe basic building block of a classical computer is the bit - a single memory cell that is either in state $0$ or in state $1$. Similarly, the basic building block of a quantum computer is the quantum bit, or **qubit**. Like the classical bit, a qubit can be in state $0$ or in state $1$. Unlike the classical bit, however, the qubit isn't limited to just those two states - it may also be in a combination, or **superposition** of those states.\n\n> A common misconception about quantum computing is that a qubit is always in state $1$ or state $0$, we just don't know which one until we \"measure\" it. That is not the case. A qubit in a superposition is in a linear combination of the states 0 and 1. When a qubit is measured, it is forced to collapse into one state or the other - in other words, measuring a qubit is a drastic process that changes its initial state.\n\n## Matrix Representation\n\nThe state of a qubit is represented by a complex vector of size 2:\n\n$$\\begin{bmatrix} \\alpha \\\\\\ \\beta \\end{bmatrix}$$\n\nHere $\\alpha$ and $\\beta$ are complex numbers. $\\alpha$ represents how \"close\" the qubit is to state $0$, and $\\beta$ represents how \"close\" the qubit is to state $1$. This vector is normalized: $|\\alpha|^2 + |\\beta|^2 = 1$.\n$\\alpha$ and $\\beta$ are known as the probability amplitudes of states $0$ and $1$, respectively.\n\n## Basis States\n\nA qubit in state $0$ would be represented by the following vector:\n\n$$\\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix}$$\n\nLikewise, a qubit in state $1$ would be represented by this vector:\n\n$$\\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix}$$\n\nNote that you can use scalar multiplication and vector addition to express any qubit state $\\begin{bmatrix} \\alpha \\\\\\ \\beta \\end{bmatrix}$ as a sum of these two vectors with certain probability amplitudes $\\alpha$ and $\\beta$, known as linear combination.\n\n$$\n\\begin{bmatrix} \\alpha \\\\\\ \\beta \\\\end{bmatrix} =\n\\begin{bmatrix} \\alpha \\\\\\ 0 \\end{bmatrix} + \\begin{bmatrix} 0 \\\\\\ \\beta \\\\end{bmatrix} =\n\\alpha \\cdot \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} + \\beta \\cdot \\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix}\n$$\n\nBecause of this, qubit states $0$ and $1$ are known as basis states. These two vectors have two properties.\n\n1. They are normalized.\n\n$$\n\\langle \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} , \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\rangle =\n\\langle \\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix} , \\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix} \\rangle = 1\n$$\n\n2. They are orthogonal to each other.\n\n$$\n\\langle \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} , \\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix} \\rangle =\n\\langle \\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix} , \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\\\rangle = 0\n$$\n\n> As a reminder, $\\langle V , W \\rangle$ is the inner product of $V$ and $W$.\n\nThis means that these vectors form an **orthonormal basis**. The basis of $\\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix}$ and $\\begin{bmatrix} 0 \\\\\\ 1 \\end{bmatrix}$ is called the **computational basis**, also known as the **canonical basis**.\n\n> There exist other orthonormal bases, for example, the **Hadamard basis**, formed by the vectors\n>\n> $$\\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix} \\text{ and } \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\\\ -\\frac{1}{\\sqrt{2}} \\end{bmatrix}$$\n>\n> You can check that these vectors are normalized, and orthogonal to each other. Any qubit state can be expressed as a linear combination of these vectors:\n>\n> $$\n> \\begin{bmatrix} \\alpha \\\\\\ \\beta \\end{bmatrix} =\n> \\frac{\\alpha + \\beta}{\\sqrt{2}} \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\\\ \\frac{1}{\\sqrt{2}} \\end{bmatrix} +\n> \\frac{\\alpha - \\beta}{\\sqrt{2}} \\begin{bmatrix} \\frac{1}{\\sqrt{2}} \\\\\\ -\\frac{1}{\\sqrt{2}} \\end{bmatrix}\n> $$\n>\n> The Hadamard basis is widely used in quantum computing, for example, in the <a href=\"https://en.wikipedia.org/wiki/BB84\" target=\"_blank\">BB84 quantum key distribution protocol</a>."
|
|
76
76
|
}
|
|
77
77
|
]
|
|
78
78
|
},
|
|
@@ -117,8 +117,8 @@ export default {
|
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
119
|
"type": "text-content",
|
|
120
|
-
"asHtml": "<p>The exact behavior of this operation called <code>RunExample</code> depends on the quantum simulator or processor you are using.</p>\n<p>On the simulator used in these demos, this function prints the information on each basis state that has a non-zero amplitude, one basis state per row.\nThis includes information about the amplitude of the state, the probability of measuring that state, and the phase of the state.</p>\n<p>Note that each row has the following format:</p>\n<table>\n <thead>\n <tr>\n <th>Basis State<br>(
|
|
121
|
-
"asMarkdown": "\nThe exact behavior of this operation called `RunExample` depends on the quantum simulator or processor you are using.\n\nOn the simulator used in these demos, this function prints the information on each basis state that has a non-zero amplitude, one basis state per row.\nThis includes information about the amplitude of the state, the probability of measuring that state, and the phase of the state.\n\nNote that each row has the following format:\n\n<table>\n <thead>\n <tr>\n <th>Basis State<br>(
|
|
120
|
+
"asHtml": "<p>The exact behavior of this operation called <code>RunExample</code> depends on the quantum simulator or processor you are using.</p>\n<p>On the simulator used in these demos, this function prints the information on each basis state that has a non-zero amplitude, one basis state per row.\nThis includes information about the amplitude of the state, the probability of measuring that state, and the phase of the state.</p>\n<p>Note that each row has the following format:</p>\n<table>\n <thead>\n <tr>\n <th>Basis State<br>(|𝜓₁…𝜓ₙ⟩)</th>\n <th>Amplitude</th>\n <th>Measurement Probability</th>\n <th>Phase</th>\n </tr>\n </thead>\n</table>\n\n<p>For example, the state $|0\\rangle$ would be represented as follows:</p>\n<table>\n <tbody>\n <tr>\n <td>|0⟩</td>\n <td>1.0000+0.0000𝑖</td>\n <td>100.0000%</td>\n <td>↑ 0.0000</td></tr>\n </tbody>\n</table>\n\n<blockquote>\n<p>It is important to note that although we reason about quantum systems in terms of their state, Q# does not have any representation of the quantum state in the language. Instead, state is an internal property of the quantum system, modified using gates. For more information, see <a href=\"https://docs.microsoft.com/azure/quantum/concepts-dirac-notation#q-gate-sequences-equivalent-to-quantum-states\" target=\"_blank\">Q# documentation on quantum states</a>.</p>\n</blockquote>\n",
|
|
121
|
+
"asMarkdown": "\nThe exact behavior of this operation called `RunExample` depends on the quantum simulator or processor you are using.\n\nOn the simulator used in these demos, this function prints the information on each basis state that has a non-zero amplitude, one basis state per row.\nThis includes information about the amplitude of the state, the probability of measuring that state, and the phase of the state.\n\nNote that each row has the following format:\n\n<table>\n <thead>\n <tr>\n <th>Basis State<br>(|𝜓₁…𝜓ₙ⟩)</th>\n <th>Amplitude</th>\n <th>Measurement Probability</th>\n <th>Phase</th>\n </tr>\n </thead>\n</table>\n\nFor example, the state $|0\\rangle$ would be represented as follows:\n\n<table>\n <tbody>\n <tr>\n <td>|0⟩</td>\n <td>1.0000+0.0000𝑖</td>\n <td>100.0000%</td>\n <td>↑ 0.0000</td></tr>\n </tbody>\n</table>\n\n> It is important to note that although we reason about quantum systems in terms of their state, Q# does not have any representation of the quantum state in the language. Instead, state is an internal property of the quantum system, modified using gates. For more information, see <a href=\"https://docs.microsoft.com/azure/quantum/concepts-dirac-notation#q-gate-sequences-equivalent-to-quantum-states\" target=\"_blank\">Q# documentation on quantum states</a>."
|
|
122
122
|
}
|
|
123
123
|
]
|
|
124
124
|
},
|
|
@@ -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 - |01\\rangle\\big) = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\\\ 0 \\\\ 0 \\end{bmatrix}$.</p>\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $|0\\rangle \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) = \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\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 - |01\\rangle\\big) = \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix}$.\n\n<details>\n <summary><b>Need a hint?</b></summary>\n Represent the target state as a tensor product $|0\\rangle \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big) = \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\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 \\\\ -1 \\\\ 0 \\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\ 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ -1 \\end{bmatrix} = |0\\rangle \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big)$$</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 \\\\\\ -1 \\\\\\ 0 \\\\\\ 0 \\end{bmatrix} = \\begin{bmatrix} 1 \\\\\\ 0 \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ -1 \\end{bmatrix} = |0\\rangle \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle - |1\\rangle\\big)$$\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<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<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/4}|01\\rangle + e^{i\\pi/2}|10\\rangle + e^{3i\\pi/4}|11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\ e^{i\\pi/4} \\ e^{i\\pi/2} \\ e^{3i\\pi/4} \\end{bmatrix}$.</p>\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/2}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|1\\rangle\\big) = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/4} \\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/4}|01\\rangle + e^{i\\pi/2}|10\\rangle + e^{3i\\pi/4}|11\\rangle\\big) = \\frac{1}{2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\\\ e^{i\\pi/2} \\\\ e^{3i\\pi/4} \\end{bmatrix}$.\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/2}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|1\\rangle\\big) = \\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/4} \\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/4} \\\\ e^{i\\pi/2} \\\\ e^{3i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\ e^{i\\pi/2} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\ e^{i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/2}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|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/4} \\\\\\ e^{i\\pi/2} \\\\\\ e^{3i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2} \\begin{bmatrix} 1 \\\\\\ e^{i\\pi/2} \\end{bmatrix} \\otimes \\frac{1}{\\sqrt2}\\begin{bmatrix} 1 \\\\\\ e^{i\\pi/4} \\end{bmatrix} =\n\\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/2}|1\\rangle\\big) \\otimes \\frac{1}{\\sqrt2}\\big(|0\\rangle + e^{i\\pi/4}|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",
|
|
@@ -1751,8 +1751,8 @@ export default {
|
|
|
1751
1751
|
"title": "Generate a Number of Arbitrary Size",
|
|
1752
1752
|
"description": {
|
|
1753
1753
|
"type": "text-content",
|
|
1754
|
-
"asHtml": "<p>Let's take it a step further and generate an $N$-bit number
|
|
1755
|
-
"asMarkdown": "Let's take it a step further and generate an $N$-bit number
|
|
1754
|
+
"asHtml": "<p>Let's take it a step further and generate an $N$-bit number.</p>\n<p><strong>Input:</strong> An integer $N$ ($1 \\le N \\le 10$).</p>\n<p><strong>Goal:</strong> Generate a random number in the range $[0, 2^N - 1]$ with an equal probability of getting each of the numbers in this range.</p>\n<blockquote>\n<p>Useful Q# documentation:</p>\n<ul>\n<li><a href=\"https://docs.microsoft.com/azure/quantum/user-guide/language/statements/iterations\" target=\"_blank\">for loops</a></li>\n<li><a href=\"https://docs.microsoft.com/azure/quantum/user-guide/language/typesystem/immutability\" target=\"_blank\">mutable variables</a></li>\n<li><a href=\"https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.math.powi\" target=\"_blank\">exponents</a></li>\n</ul>\n</blockquote>\n<details>\n <summary><b>Need a hint?</b></summary>\n Remember that you can use previously defined operations to implement your solution. For convenience, the <b>RandomBit</b> operation is already available for you to use in this exercise.\n</details>\n",
|
|
1755
|
+
"asMarkdown": "Let's take it a step further and generate an $N$-bit number.\n\n**Input:** An integer $N$ ($1 \\le N \\le 10$).\n\n**Goal:** Generate a random number in the range $[0, 2^N - 1]$ with an equal probability of getting each of the numbers in this range.\n\n> Useful Q# documentation:\n>\n> * <a href=\"https://docs.microsoft.com/azure/quantum/user-guide/language/statements/iterations\" target=\"_blank\">for loops</a>\n> * <a href=\"https://docs.microsoft.com/azure/quantum/user-guide/language/typesystem/immutability\" target=\"_blank\">mutable variables</a>\n> * <a href=\"https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.math.powi\" target=\"_blank\">exponents</a>\n\n<details>\n <summary><b>Need a hint?</b></summary>\n Remember that you can use previously defined operations to implement your solution. For convenience, the <b>RandomBit</b> operation is already available for you to use in this exercise.\n</details>\n"
|
|
1756
1756
|
},
|
|
1757
1757
|
"sourceIds": [
|
|
1758
1758
|
"random_numbers__random_n_bits__verification.qs",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ICompletionList, IHover, ILocation, ISignatureHelp, INotebookMetadata, IWorkspaceConfiguration, IWorkspaceEdit, ITextEdit } from "../../lib/node/qsc_wasm.cjs";
|
|
2
|
-
import { VSDiagnostic } from "../vsdiagnostic.js";
|
|
1
|
+
import type { ICompletionList, IHover, ILocation, ISignatureHelp, INotebookMetadata, IWorkspaceConfiguration, IWorkspaceEdit, ITextEdit, IPosition, VSDiagnostic } from "../../lib/node/qsc_wasm.cjs";
|
|
3
2
|
import { IServiceProxy } from "../worker-proxy.js";
|
|
4
3
|
type QscWasm = typeof import("../../lib/node/qsc_wasm.cjs");
|
|
5
4
|
export type LanguageServiceEvent = {
|
|
@@ -20,13 +19,13 @@ export interface ILanguageService {
|
|
|
20
19
|
}[]): Promise<void>;
|
|
21
20
|
closeDocument(uri: string): Promise<void>;
|
|
22
21
|
closeNotebookDocument(notebookUri: string): Promise<void>;
|
|
23
|
-
getCompletions(documentUri: string,
|
|
24
|
-
getHover(documentUri: string,
|
|
25
|
-
getDefinition(documentUri: string,
|
|
26
|
-
getReferences(documentUri: string,
|
|
27
|
-
getSignatureHelp(documentUri: string,
|
|
28
|
-
getRename(documentUri: string,
|
|
29
|
-
prepareRename(documentUri: string,
|
|
22
|
+
getCompletions(documentUri: string, position: IPosition): Promise<ICompletionList>;
|
|
23
|
+
getHover(documentUri: string, position: IPosition): Promise<IHover | undefined>;
|
|
24
|
+
getDefinition(documentUri: string, position: IPosition): Promise<ILocation | undefined>;
|
|
25
|
+
getReferences(documentUri: string, position: IPosition, includeDeclaration: boolean): Promise<ILocation[]>;
|
|
26
|
+
getSignatureHelp(documentUri: string, position: IPosition): Promise<ISignatureHelp | undefined>;
|
|
27
|
+
getRename(documentUri: string, position: IPosition, newName: string): Promise<IWorkspaceEdit | undefined>;
|
|
28
|
+
prepareRename(documentUri: string, position: IPosition): Promise<ITextEdit | undefined>;
|
|
30
29
|
dispose(): Promise<void>;
|
|
31
30
|
addEventListener<T extends LanguageServiceEvent["type"]>(type: T, listener: (event: Extract<LanguageServiceEvent, {
|
|
32
31
|
type: T;
|
|
@@ -40,13 +39,11 @@ export type ILanguageServiceWorker = ILanguageService & IServiceProxy;
|
|
|
40
39
|
export declare class QSharpLanguageService implements ILanguageService {
|
|
41
40
|
private languageService;
|
|
42
41
|
private eventHandler;
|
|
43
|
-
private code;
|
|
44
42
|
private readFile;
|
|
45
43
|
private backgroundWork;
|
|
46
44
|
constructor(wasm: QscWasm, readFile?: (uri: string) => Promise<string | null>, listDir?: (uri: string) => Promise<[string, number][]>, getManifest?: (uri: string) => Promise<{
|
|
47
45
|
manifestDirectory: string;
|
|
48
46
|
} | null>);
|
|
49
|
-
loadFile(uri: string): Promise<string | null>;
|
|
50
47
|
updateConfiguration(config: IWorkspaceConfiguration): Promise<void>;
|
|
51
48
|
updateDocument(documentUri: string, version: number, code: string): Promise<void>;
|
|
52
49
|
updateNotebookDocument(notebookUri: string, version: number, metadata: INotebookMetadata, cells: {
|
|
@@ -56,13 +53,13 @@ export declare class QSharpLanguageService implements ILanguageService {
|
|
|
56
53
|
}[]): Promise<void>;
|
|
57
54
|
closeDocument(documentUri: string): Promise<void>;
|
|
58
55
|
closeNotebookDocument(documentUri: string): Promise<void>;
|
|
59
|
-
getCompletions(documentUri: string,
|
|
60
|
-
getHover(documentUri: string,
|
|
61
|
-
getDefinition(documentUri: string,
|
|
62
|
-
getReferences(documentUri: string,
|
|
63
|
-
getSignatureHelp(documentUri: string,
|
|
64
|
-
getRename(documentUri: string,
|
|
65
|
-
prepareRename(documentUri: string,
|
|
56
|
+
getCompletions(documentUri: string, position: IPosition): Promise<ICompletionList>;
|
|
57
|
+
getHover(documentUri: string, position: IPosition): Promise<IHover | undefined>;
|
|
58
|
+
getDefinition(documentUri: string, position: IPosition): Promise<ILocation | undefined>;
|
|
59
|
+
getReferences(documentUri: string, position: IPosition, includeDeclaration: boolean): Promise<ILocation[]>;
|
|
60
|
+
getSignatureHelp(documentUri: string, position: IPosition): Promise<ISignatureHelp | undefined>;
|
|
61
|
+
getRename(documentUri: string, position: IPosition, newName: string): Promise<IWorkspaceEdit | undefined>;
|
|
62
|
+
prepareRename(documentUri: string, position: IPosition): Promise<ITextEdit | undefined>;
|
|
66
63
|
dispose(): Promise<void>;
|
|
67
64
|
addEventListener<T extends LanguageServiceEvent["type"]>(type: T, listener: (event: Extract<LanguageServiceEvent, {
|
|
68
65
|
type: T;
|