forked from microsoft/QuantumKatas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTasks.qs
129 lines (104 loc) · 5.3 KB
/
Tasks.qs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
namespace Quantum.Kata.GHZGame {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Logical;
//////////////////////////////////////////////////////////////////
// Welcome!
//////////////////////////////////////////////////////////////////
// The "GHZ Game" quantum kata is a series of exercises designed
// to get you familiar with the GHZ game.
// In it three players (Alice, Bob and Charlie) try to win the
// following game:
// Each of them is given a bit (r, s and t respectively), and
// they have to return new bits (a, b and c respectively) so
// that r ∨ s ∨ t = a ⊕ b ⊕ c.* The input bits will have
// zero or two bits set to true and three or one bits set to false.
// The trick is, the players can not communicate during the game.
// * '∨' is the standard bitwise OR operator
// * '⊕' is the exclusive or, or XOR operator, so 'P ⊕ Q' is true if exactly one of P and Q is true.
// Each task is wrapped in one operation preceded by the
// description of the task. Each task has a unit test associated
// with it, which initially fails. Your goal is to fill in the
// blank (marked with // ... comment) with some Q# code to make
// the failing test pass.
//////////////////////////////////////////////////////////////////
// Part I. Classical GHZ
//////////////////////////////////////////////////////////////////
// Task 1.1. Win condition
// Input:
// 1) Alice, Bob and Charlie's input bits (r, s and t), stored as an array of length 3,
// 2) Alice, Bob and Charlie's output bits (a, b and c), stored as an array of length 3.
// The input bits will have zero or two bits set to true.
// Output:
// True if Alice, Bob and Charlie won the GHZ game, that is, if r ∨ s ∨ t = a ⊕ b ⊕ c,
// and false otherwise.
function WinCondition (rst : Bool[], abc : Bool[]) : Bool {
// ...
fail "Task 1.1 not implemented yet";
}
// Task 1.2. Random classical strategy
// Input: The input bit for one of the players (r, s or t).
// Output: A random bit that this player will output (a, b or c).
// If all players use this strategy, they will win about 50% of the time.
operation RandomClassicalStrategy (input : Bool) : Bool {
// ...
fail "Task 1.2 not implemented yet";
}
// Task 1.3. Best classical strategy
// Input: The input bit for one of the players (r, s or t).
// Output: A bit that this player will output (a, b or c) to maximize their chance of winning.
// All players will use the same strategy.
// The best classical strategy should win about 75% of the time.
operation BestClassicalStrategy (input : Bool) : Bool {
// ...
fail "Task 1.3 not implemented yet";
}
// Task 1.4. Referee classical GHZ game
// Inputs:
// 1) an operation which implements a classical strategy
// (i.e., takes an input bit and produces and output bit),
// 2) an array of 3 input bits that should be passed to the players.
// Output:
// An array of 3 bits that will be produced if each player uses this strategy.
operation PlayClassicalGHZ (strategy : (Bool => Bool), inputs : Bool[]) : Bool[] {
// ...
fail "Task 1.4 not implemented yet";
}
//////////////////////////////////////////////////////////////////
// Part II. Quantum GHZ
//////////////////////////////////////////////////////////////////
// In the quantum version of the game, the players still can not
// communicate during the game, but they are allowed to share
// qubits from an entangled triple before the start of the game.
// Task 2.1. Entangled triple
// Input: An array of three qubits in the |000⟩ state.
// Goal: Create the entangled state |ψ⟩ = (|000⟩ - |011⟩ - |101⟩ - |110⟩) / 2 on these qubits.
operation CreateEntangledTriple (qs : Qubit[]) : Unit {
// ...
fail "Task 2.1 not implemented yet";
}
// Task 2.2. Quantum strategy
// Inputs:
// 1) The input bit for one of the players (r, s or t),
// 2) That player's qubit of the entangled triple shared between the players.
// Goal: Measure the qubit in the Z basis if the bit is 0 (false),
// or the X basis if the bit is 1 (true), and return the result.
// The state of the qubit after the operation does not matter.
operation QuantumStrategy (input : Bool, qubit : Qubit) : Bool {
// ...
fail "Task 2.2 not implemented yet";
}
// Task 2.3. Play the GHZ game using the quantum strategy
// Input: Operations that return Alice, Bob and Charlie's output bits (a, b and c) based on
// their quantum strategies and given their respective qubits from the entangled triple.
// The players have already been told what their starting bits (r, s and t) are.
// Goal: Return an array of players' output bits (a, b and c).
operation PlayQuantumGHZ (strategies : (Qubit => Bool)[]) : Bool[] {
// ...
fail "Task 2.3 not implemented yet";
}
}