Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 7c79ecb

Browse files
jimcristofonoScottCarda-MStcNickolas
authored
[Superposition] Add workbook solutions for tasks 13-17 (#282)
Co-authored-by: Scott Carda <55811729+ScottCarda-MS@users.noreply.github.com> Co-authored-by: Mariia Mykhailova <mamykhai@microsoft.com>
1 parent d6656f5 commit 7c79ecb

File tree

4 files changed

+710
-15
lines changed

4 files changed

+710
-15
lines changed

Superposition/ReferenceImplementation.qs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,14 @@ namespace Quantum.Kata.Superposition {
307307
//
308308
// Goal: create an equal superposition of the four basis states given by the bit strings.
309309
operation FourBitstringSuperposition_Reference (qs : Qubit[], bits : Bool[][]) : Unit is Adj {
310-
let N = Length(qs);
311-
312310
using (anc = Qubit[2]) {
313311
// Put two ancillas into equal superposition of 2-qubit basis states
314312
ApplyToEachA(H, anc);
315313

316314
// Set up the right pattern on the main qubits with control on ancillas
317315
for (i in 0 .. 3) {
318-
for (j in 0 .. N - 1) {
319-
if ((bits[i])[j]) {
316+
for (j in 0 .. Length(qs) - 1) {
317+
if (bits[i][j]) {
320318
(ControlledOnInt(i, X))(anc, qs[j]);
321319
}
322320
}

Superposition/Superposition.ipynb

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,14 @@
470470
"cell_type": "markdown",
471471
"metadata": {},
472472
"source": [
473-
"### Task 12*. Hardy state.\n",
473+
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#threestates-twoqubits).*"
474+
]
475+
},
476+
{
477+
"cell_type": "markdown",
478+
"metadata": {},
479+
"source": [
480+
"### <a name=\"hardy-state\"></a>Task 12*. Hardy state.\n",
474481
"\n",
475482
"**Input:** Two qubits in the $|00\\rangle$ state.\n",
476483
"\n",
@@ -500,7 +507,14 @@
500507
"cell_type": "markdown",
501508
"metadata": {},
502509
"source": [
503-
"### Task 13. Superposition of $|0 \\dots 0\\rangle$ and the given bit string.\n",
510+
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#hardy-state).*"
511+
]
512+
},
513+
{
514+
"cell_type": "markdown",
515+
"metadata": {},
516+
"source": [
517+
"### <a name=\"superposition-of-zero-and-given-bit-string\"></a>Task 13. Superposition of $|0 \\dots 0\\rangle$ and the given bit string.\n",
504518
"\n",
505519
"**Inputs:** \n",
506520
"\n",
@@ -529,7 +543,14 @@
529543
"cell_type": "markdown",
530544
"metadata": {},
531545
"source": [
532-
"### Task 14. Superposition of two bit strings.\n",
546+
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#superposition-of-zero-and-given-bit-string).*"
547+
]
548+
},
549+
{
550+
"cell_type": "markdown",
551+
"metadata": {},
552+
"source": [
553+
"### <a name=\"superposition-of-two-bit-strings\"></a>Task 14. Superposition of two bit strings.\n",
533554
"\n",
534555
"**Inputs:** \n",
535556
"\n",
@@ -560,12 +581,19 @@
560581
"cell_type": "markdown",
561582
"metadata": {},
562583
"source": [
563-
"### Task 15*. Superposition of four bit strings.\n",
584+
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#superposition-of-two-bit-strings).*"
585+
]
586+
},
587+
{
588+
"cell_type": "markdown",
589+
"metadata": {},
590+
"source": [
591+
"### <a name=\"superposition-of-four-bit-strings\"></a>Task 15*. Superposition of four bit strings.\n",
564592
"\n",
565593
"**Inputs:** \n",
566594
"\n",
567595
"1. $N$ ($N \\ge 1$) qubits in the $|0 \\dots 0\\rangle$ state.\n",
568-
"2. Four bit strings of length $N$, represented as `Bool[][]` `bits`. `bits` is an $4 \\times N$ which describes the bit strings as follows: `bits[i]` describes the `i`-th bit string and has $N$ elements. You are guaranteed that all four bit strings will be distinct.\n",
596+
"2. Four bit strings of length $N$, represented as `Bool[][]` `bits`. `bits` is an $4 \\times N$ array which describes the bit strings as follows: `bits[i]` describes the `i`-th bit string and has $N$ elements. You are guaranteed that all four bit strings will be distinct.\n",
569597
"\n",
570598
"**Goal:** Change the state of the qubits to an equal superposition of the four basis states given by the bit strings.\n",
571599
"\n",
@@ -595,7 +623,14 @@
595623
"cell_type": "markdown",
596624
"metadata": {},
597625
"source": [
598-
"### Task 16**. W state on $2^k$ qubits.\n",
626+
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#superposition-of-four-bit-strings).*"
627+
]
628+
},
629+
{
630+
"cell_type": "markdown",
631+
"metadata": {},
632+
"source": [
633+
"### <a name=\"wstate-on-2k-qubits\"></a>Task 16**. W state on $2^k$ qubits.\n",
599634
"\n",
600635
"**Input:** $N = 2^k$ qubits in the $|0 \\dots 0\\rangle$ state.\n",
601636
"\n",
@@ -627,7 +662,14 @@
627662
"cell_type": "markdown",
628663
"metadata": {},
629664
"source": [
630-
"### Task 17**. W state on an arbitrary number of qubits.\n",
665+
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#wstate-on-2k-qubits).*"
666+
]
667+
},
668+
{
669+
"cell_type": "markdown",
670+
"metadata": {},
671+
"source": [
672+
"### <a name=\"wstate-on-arbitray-number-of-qubits\"></a>Task 17**. W state on an arbitrary number of qubits.\n",
631673
"\n",
632674
"**Input:** $N$ qubits in the $|0 \\dots 0\\rangle$ state ($N$ is not necessarily a power of 2).\n",
633675
"\n",
@@ -654,6 +696,13 @@
654696
" // ...\n",
655697
"}"
656698
]
699+
},
700+
{
701+
"cell_type": "markdown",
702+
"metadata": {},
703+
"source": [
704+
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition_Part2.ipynb#wstate-on-arbitray-number-of-qubits).*"
705+
]
657706
}
658707
],
659708
"metadata": {
@@ -666,7 +715,7 @@
666715
"file_extension": ".qs",
667716
"mimetype": "text/x-qsharp",
668717
"name": "qsharp",
669-
"version": "0.4"
718+
"version": "0.10"
670719
}
671720
},
672721
"nbformat": 4,

Superposition/Tasks.qs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ namespace Quantum.Kata.Superposition {
202202
// Inputs:
203203
// 1) N qubits in |0...0⟩ state
204204
// 2) four bit string represented as Bool[][] bits
205-
// bits is an array of size 4 x N which describes the bit strings as follows:
205+
// bits is an array of size 4 x N array which describes the bit strings as follows:
206206
// bits[i] describes the i-th bit string and has N elements.
207207
// All four bit strings will be distinct.
208208
//

0 commit comments

Comments
 (0)