From 56f2110696fd5937856a990ea08e3e859c91e53a Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Mon, 8 Jul 2024 19:38:55 -0700 Subject: [PATCH 01/20] Add Migrate Nonlocal Games - 1596 - CHSH classical --- katas/content/index.json | 1 + .../chsh_classical_strategy/Placeholder.qs | 13 ++++ .../chsh_classical_strategy/Solution.qs | 9 +++ .../chsh_classical_strategy/Verification.qs | 27 ++++++++ .../chsh_classical_strategy/index.md | 8 +++ .../chsh_classical_strategy/solution.md | 7 ++ .../Placeholder.qs | 7 ++ .../chsh_classical_win_condition/Solution.qs | 5 ++ .../Verification.qs | 24 +++++++ .../chsh_classical_win_condition/index.md | 7 ++ .../chsh_classical_win_condition/solution.md | 10 +++ katas/content/nonlocal_games/index.md | 68 +++++++++++++++++++ 12 files changed, 186 insertions(+) create mode 100644 katas/content/nonlocal_games/chsh_classical_strategy/Placeholder.qs create mode 100644 katas/content/nonlocal_games/chsh_classical_strategy/Solution.qs create mode 100644 katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs create mode 100644 katas/content/nonlocal_games/chsh_classical_strategy/index.md create mode 100644 katas/content/nonlocal_games/chsh_classical_strategy/solution.md create mode 100644 katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs create mode 100644 katas/content/nonlocal_games/chsh_classical_win_condition/Solution.qs create mode 100644 katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs create mode 100644 katas/content/nonlocal_games/chsh_classical_win_condition/index.md create mode 100644 katas/content/nonlocal_games/chsh_classical_win_condition/solution.md create mode 100644 katas/content/nonlocal_games/index.md diff --git a/katas/content/index.json b/katas/content/index.json index 5f64246444..8aa4e062d9 100644 --- a/katas/content/index.json +++ b/katas/content/index.json @@ -19,5 +19,6 @@ "marking_oracles", "deutsch_algo", "deutsch_jozsa", + "nonlocal_games", "qec_shor" ] diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/Placeholder.qs b/katas/content/nonlocal_games/chsh_classical_strategy/Placeholder.qs new file mode 100644 index 0000000000..f368233adf --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_strategy/Placeholder.qs @@ -0,0 +1,13 @@ +namespace Kata { + function AliceClassical (x : Bool) : Bool { + // Implement your solution here... + + return false; + } + + function BobClassical (y : Bool) : Bool { + // Implement your solution here... + + return true; + } +} diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/Solution.qs b/katas/content/nonlocal_games/chsh_classical_strategy/Solution.qs new file mode 100644 index 0000000000..21d8c8b4b6 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_strategy/Solution.qs @@ -0,0 +1,9 @@ +namespace Kata { + function AliceClassical (x : Bool) : Bool { + return false; + } + + function BobClassical (y : Bool) : Bool { + return false; + } +} diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs b/katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs new file mode 100644 index 0000000000..09cf9500f8 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs @@ -0,0 +1,27 @@ +namespace Kata.Verification { + open Microsoft.Quantum.Convert; + open Microsoft.Quantum.Random; + + @EntryPoint() + operation CheckSolution() : Bool { + mutable wins = 0; + for i in 1..1000 { + let x = DrawRandomInt(0, 1) == 1 ? true | false; + let y = DrawRandomInt(0, 1) == 1 ? true | false; + let (a, b) = (Kata.AliceClassical(x), Kata.BobClassical(y)); + if ((x and y) == (a != b)) { + set wins = wins + 1; + } + } + Message($"Win rate {IntAsDouble(wins) / 1000.}"); + if (wins < 700) { + Message("Alice and Bob's classical strategy is not optimal"); + return false; + } + else { + Message("Correct!"); + } + true + } + +} diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/index.md b/katas/content/nonlocal_games/chsh_classical_strategy/index.md new file mode 100644 index 0000000000..a65472e357 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_strategy/index.md @@ -0,0 +1,8 @@ +In this task you have to implement two functions, one for Alice's classical strategy and one for Bob's. +Note that they are covered by one test, so you have to implement both to pass the test. + +**Input:** +* Alice and Bob's starting bits (X and Y). + +**Output:** + Alice and Bob's output bits (A and B) to maximize their chance of winning. diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/solution.md b/katas/content/nonlocal_games/chsh_classical_strategy/solution.md new file mode 100644 index 0000000000..c37d399139 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_strategy/solution.md @@ -0,0 +1,7 @@ +If Alice and Bob always return TRUE, they will have a 75% win rate, since TRUE ⊕ TRUE = FALSE, and the AND operation on their input bits will be false with 75% probability. +Alternatively, Alice and Bob could agree to always return FALSE to achieve the same 75% win probability. A classical strategy cannot achieve a higher success probability. + +@[solution]({ + "id": "nonlocal_games__chsh_classical_strategy_solution", + "codePath": "Solution.qs" +}) diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs b/katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs new file mode 100644 index 0000000000..5ac3ecec05 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs @@ -0,0 +1,7 @@ +namespace Kata { + function WinCondition (x : Bool, y : Bool, a : Bool, b : Bool) : Bool { + // Implement your solution here... + + return false; + } +} \ No newline at end of file diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/Solution.qs b/katas/content/nonlocal_games/chsh_classical_win_condition/Solution.qs new file mode 100644 index 0000000000..b9d1321c8e --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/Solution.qs @@ -0,0 +1,5 @@ +namespace Kata { + function WinCondition (x : Bool, y : Bool, a : Bool, b : Bool) : Bool { + return (x and y) == (a != b); + } +} diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs b/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs new file mode 100644 index 0000000000..a146a09949 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs @@ -0,0 +1,24 @@ +namespace Kata.Verification { + open Microsoft.Quantum.Convert; + + function WinCondition_Reference(x : Bool, y : Bool, a : Bool, b : Bool) : Bool { + return (x and y) == (a != b); + } + + @EntryPoint() + function CheckSolution() : Bool { + for i in 0..1 <<< 4 - 1 { + let bits = IntAsBoolArray(i, 4); + let actual = WinCondition_Reference(bits[0], bits[1], bits[2], bits[3]); + let expected = Kata.WinCondition(bits[0], bits[1], bits[2], bits[3]); + + if actual != expected { + Message("Win condition is wrong for " + $"X = {bits[0]}, " + $"Y = {bits[1]}, " + + $"A = {bits[2]}, " + $"B = {bits[3]}"); + return false; + } + } + Message("Correct!"); + true + } +} diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/index.md b/katas/content/nonlocal_games/chsh_classical_win_condition/index.md new file mode 100644 index 0000000000..4485f2f549 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/index.md @@ -0,0 +1,7 @@ +**Input:** +* Alice and Bob's starting bits (X and Y). +* Alice and Bob's output bits (A and B). + +**Output:** + True if Alice and Bob won the CHSH game, that is, if X ∧ Y = A ⊕ B, and false otherwise. + diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md new file mode 100644 index 0000000000..1d8359dcf0 --- /dev/null +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md @@ -0,0 +1,10 @@ +There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability. +In order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise. + +To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.logical) library offers you logical functions `And` and `Xor` which you can use for this computation. Alternatively, you can compute these values using built-in operators: $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. + + +@[solution]({ + "id": "nonlocal_games__chsh_classical_win_condition_solution", + "codePath": "Solution.qs" +}) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md new file mode 100644 index 0000000000..97c03ca351 --- /dev/null +++ b/katas/content/nonlocal_games/index.md @@ -0,0 +1,68 @@ +# Nonlocal Games + +@[section]({ + "id": "nonlocal_games__overview", + "title": "Overview" +}) + +For our context, "nonlocal" means that the playing parties are separated by a great distance, +so they cannot communicate with each other during the game. +In a new kata, we discuss three quantum nonlocal games that display "quantum pseudo-telepathy" - +the use of quantum entanglement to eliminate the need for classical communication. +Another characteristics of these games is that they are "refereed", which means the players try to win against the referee. + +**This kata covers the following topics:** + - Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game) + - Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game) + - The Mermin-Peres Magic Square (entanglement) game + +**What you should know to start working on this kata:** + - Basic linear algebra + - Single and multi-qubit systems + - Single and multi-qubit gates + - Single-qubit system measurements + +@[section]({ + "id": "nonlocal_games__chsh_game", + "title": "CHSH game" +}) + +The **CHSH Game** quantum kata is a series of exercises designed +to get you familiar with the CHSH game. + +In it, two players (Alice and Bob) try to win the following game: + +Each of them is given a bit (Alice gets X and Bob gets Y), and +they have to return new bits (Alice returns A and Bob returns B) +so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the game. + +> * ∧ is the standard bitwise AND operator. +> * ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. + +* You can read more about CHSH game in the [lecture notes](https://cs.uwaterloo.ca/~watrous/QC-notes/QC-notes.20.pdf) by + John Watrous. +* At the end of the section you can find an implementation of the CHSH game that includes an explanation of the history and theory behind the game. + +@[section]({ + "id": "nonlocal_games__chsh_game_classical", + "title": "Part I. Classical CHSH" +}) + +@[exercise]({ + "id": "nonlocal_games__chsh_classical_win_condition", + "title": "Win Condition", + "path": "./chsh_classical_win_condition/" +}) + +@[exercise]({ + "id": "nonlocal_games__chsh_classical_strategy", + "title": "Alice and Bob's classical strategy", + "path": "./chsh_classical_strategy/" +}) + +@[section]({ + "id": "nonlocal_games__conclusion", + "title": "Conclusion" +}) + +Congratulations! In this kata you learned how to communicate using quantum entanglement in nonlocal quantum games. From 2319d0ac1480ca00c3877284df101fd3084a4c34 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 9 Jul 2024 15:57:11 -0700 Subject: [PATCH 02/20] Address code review comments --- katas/content/index.json | 1 - .../nonlocal_games/chsh_classical_win_condition/Placeholder.qs | 2 +- .../nonlocal_games/chsh_classical_win_condition/solution.md | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/katas/content/index.json b/katas/content/index.json index 8aa4e062d9..5f64246444 100644 --- a/katas/content/index.json +++ b/katas/content/index.json @@ -19,6 +19,5 @@ "marking_oracles", "deutsch_algo", "deutsch_jozsa", - "nonlocal_games", "qec_shor" ] diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs b/katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs index 5ac3ecec05..1ba27f995c 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/Placeholder.qs @@ -4,4 +4,4 @@ namespace Kata { return false; } -} \ No newline at end of file +} diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md index 1d8359dcf0..d78ac83bf0 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md @@ -1,7 +1,7 @@ There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability. In order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise. -To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.logical) library offers you logical functions `And` and `Xor` which you can use for this computation. Alternatively, you can compute these values using built-in operators: $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. +To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library offers you logical function `Xor` which you can use for this computation. Alternatively, you can compute these values using [`built-in operators`](https://learn.microsoft.com/en-us/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. @[solution]({ From 6a1706fe49895796cf4b46ec572ec802972b8230 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 9 Jul 2024 17:00:24 -0700 Subject: [PATCH 03/20] Remove en-us from QDK link --- .../nonlocal_games/chsh_classical_win_condition/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md index d78ac83bf0..68481c54a8 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md @@ -1,7 +1,7 @@ There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability. In order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise. -To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library offers you logical function `Xor` which you can use for this computation. Alternatively, you can compute these values using [`built-in operators`](https://learn.microsoft.com/en-us/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. +To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library offers you logical function `Xor` which you can use for this computation. Alternatively, you can compute these values using [`built-in operators`](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. @[solution]({ From e7b6d26b27d9d57d59dd7ef3ccb9623a2f2b9c23 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Tue, 9 Jul 2024 17:02:15 -0700 Subject: [PATCH 04/20] Remove en-us from QDK link --- .../nonlocal_games/chsh_classical_win_condition/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md index 68481c54a8..c59321ca7f 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md @@ -1,7 +1,7 @@ There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability. In order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise. -To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/en-us/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library offers you logical function `Xor` which you can use for this computation. Alternatively, you can compute these values using [`built-in operators`](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. +To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library offers you logical function `Xor` which you can use for this computation. Alternatively, you can compute these values using [`built-in operators`](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. @[solution]({ From b8db86a59cd2c8f9a6948a6d25b02d9ab8b16811 Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:47:00 -0700 Subject: [PATCH 05/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index 97c03ca351..2a668ef1e1 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -5,10 +5,10 @@ "title": "Overview" }) -For our context, "nonlocal" means that the playing parties are separated by a great distance, -so they cannot communicate with each other during the game. -In a new kata, we discuss three quantum nonlocal games that display "quantum pseudo-telepathy" - +This kata introduces three quantum nonlocal games that display "quantum pseudo-telepathy" - the use of quantum entanglement to eliminate the need for classical communication. +In this context, "nonlocal" means that the playing parties are separated by a great distance, +so they cannot communicate with each other during the game. Another characteristics of these games is that they are "refereed", which means the players try to win against the referee. **This kata covers the following topics:** From f37b9b704f7e1a1df67862a682ccd10c6f541d6f Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:47:21 -0700 Subject: [PATCH 06/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index 2a668ef1e1..39e86bfcac 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -14,7 +14,7 @@ Another characteristics of these games is that they are "refereed", which means **This kata covers the following topics:** - Clauser, Horne, Shimony, and Hold thought experiment (often abbreviated as CHSH game) - Greenberger-Horne-Zeilinger game (often abbreviated as GHZ game) - - The Mermin-Peres Magic Square (entanglement) game + - The Mermin-Peres Magic Square game **What you should know to start working on this kata:** - Basic linear algebra From 54aa6f2923acb86b3568d68dcd65ee2c1fb87e9a Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:47:44 -0700 Subject: [PATCH 07/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index 39e86bfcac..cd94467294 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -18,9 +18,7 @@ Another characteristics of these games is that they are "refereed", which means **What you should know to start working on this kata:** - Basic linear algebra - - Single and multi-qubit systems - - Single and multi-qubit gates - - Single-qubit system measurements + - Basic knowledge of quantum gates and measurements @[section]({ "id": "nonlocal_games__chsh_game", From 77f83db66181b79f01163808fbd4bc510df08f5c Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:47:52 -0700 Subject: [PATCH 08/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index cd94467294..de71e3ed0b 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -22,7 +22,7 @@ Another characteristics of these games is that they are "refereed", which means @[section]({ "id": "nonlocal_games__chsh_game", - "title": "CHSH game" + "title": "CHSH Game" }) The **CHSH Game** quantum kata is a series of exercises designed From b85b080340c4cfa84c11a300371e34fa38740c5d Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:48:15 -0700 Subject: [PATCH 09/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index de71e3ed0b..b0708a1028 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -25,10 +25,7 @@ Another characteristics of these games is that they are "refereed", which means "title": "CHSH Game" }) -The **CHSH Game** quantum kata is a series of exercises designed -to get you familiar with the CHSH game. - -In it, two players (Alice and Bob) try to win the following game: +In **CHSH Game**, two players (Alice and Bob) try to win the following game: Each of them is given a bit (Alice gets X and Bob gets Y), and they have to return new bits (Alice returns A and Bob returns B) From 67cbd3def724d74db720ce648bd3c429494f45fa Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:48:44 -0700 Subject: [PATCH 10/20] Update katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs Co-authored-by: Mariia Mykhailova --- .../chsh_classical_win_condition/Verification.qs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs b/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs index a146a09949..3cfcd3b007 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs @@ -13,8 +13,8 @@ namespace Kata.Verification { let expected = Kata.WinCondition(bits[0], bits[1], bits[2], bits[3]); if actual != expected { - Message("Win condition is wrong for " + $"X = {bits[0]}, " + $"Y = {bits[1]}, " + - $"A = {bits[2]}, " + $"B = {bits[3]}"); + Message($"Win condition is wrong for X = {bits[0]}, Y = {bits[1]}, " + + $"A = {bits[2]}, B = {bits[3]}"); return false; } } From 95239372c32ee1c209586d144ea112065c4b3b9b Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:48:59 -0700 Subject: [PATCH 11/20] Update katas/content/nonlocal_games/chsh_classical_win_condition/solution.md Co-authored-by: Mariia Mykhailova --- .../nonlocal_games/chsh_classical_win_condition/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md index c59321ca7f..dcfa9d6139 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md @@ -1,7 +1,7 @@ There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability. In order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise. -To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. [`Microsoft.Quantum.Logical`](https://learn.microsoft.com/qsharp/api/qsharp-lang/microsoft.quantum.logical/xor) library offers you logical function `Xor` which you can use for this computation. Alternatively, you can compute these values using [`built-in operators`](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. +To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. You can compute these values using [`built-in operators`](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. @[solution]({ From 4ae50af14ff6f6a734a7f63871b6dd2bedfaf4ea Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:49:12 -0700 Subject: [PATCH 12/20] Update katas/content/nonlocal_games/chsh_classical_strategy/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/chsh_classical_strategy/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/index.md b/katas/content/nonlocal_games/chsh_classical_strategy/index.md index a65472e357..927a4c32bf 100644 --- a/katas/content/nonlocal_games/chsh_classical_strategy/index.md +++ b/katas/content/nonlocal_games/chsh_classical_strategy/index.md @@ -2,7 +2,7 @@ In this task you have to implement two functions, one for Alice's classical stra Note that they are covered by one test, so you have to implement both to pass the test. **Input:** -* Alice and Bob's starting bits (X and Y). +Alice and Bob's starting bits (X and Y). **Output:** Alice and Bob's output bits (A and B) to maximize their chance of winning. From d57ff0e76fcadd69364523d959affca657fd4c60 Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:49:25 -0700 Subject: [PATCH 13/20] Update katas/content/nonlocal_games/chsh_classical_strategy/solution.md Co-authored-by: Mariia Mykhailova --- .../content/nonlocal_games/chsh_classical_strategy/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/solution.md b/katas/content/nonlocal_games/chsh_classical_strategy/solution.md index c37d399139..fb22c98290 100644 --- a/katas/content/nonlocal_games/chsh_classical_strategy/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_strategy/solution.md @@ -1,4 +1,4 @@ -If Alice and Bob always return TRUE, they will have a 75% win rate, since TRUE ⊕ TRUE = FALSE, and the AND operation on their input bits will be false with 75% probability. +If Alice and Bob always return TRUE, they will have a 75% win rate, since TRUE ⊕ TRUE = FALSE, and the AND operation on their input bits will be FALSE with 75% probability. Alternatively, Alice and Bob could agree to always return FALSE to achieve the same 75% win probability. A classical strategy cannot achieve a higher success probability. @[solution]({ From 462856d85d619f6078cfe393647deed9905560de Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Fri, 12 Jul 2024 16:54:21 -0700 Subject: [PATCH 14/20] Message update for win condition (actual vs expected) --- .../chsh_classical_win_condition/Verification.qs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs b/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs index 3cfcd3b007..82a16cd2d8 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/Verification.qs @@ -9,11 +9,11 @@ namespace Kata.Verification { function CheckSolution() : Bool { for i in 0..1 <<< 4 - 1 { let bits = IntAsBoolArray(i, 4); - let actual = WinCondition_Reference(bits[0], bits[1], bits[2], bits[3]); - let expected = Kata.WinCondition(bits[0], bits[1], bits[2], bits[3]); + let expected = WinCondition_Reference(bits[0], bits[1], bits[2], bits[3]); + let actual = Kata.WinCondition(bits[0], bits[1], bits[2], bits[3]); if actual != expected { - Message($"Win condition is wrong for X = {bits[0]}, Y = {bits[1]}, " + + Message($"Win condition '{actual}' isn't as expected for X = {bits[0]}, Y = {bits[1]}, " + $"A = {bits[2]}, B = {bits[3]}"); return false; } From b4041df6014a3a83338b3bdaa598f4672c0bfdbb Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:58:27 -0700 Subject: [PATCH 15/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index b0708a1028..a22ccd57bd 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -51,7 +51,7 @@ so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the gam @[exercise]({ "id": "nonlocal_games__chsh_classical_strategy", - "title": "Alice and Bob's classical strategy", + "title": "Alice and Bob's Classical Strategy", "path": "./chsh_classical_strategy/" }) From b42863b364956a5319a9c6bd931dad19b0bb7891 Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:58:44 -0700 Subject: [PATCH 16/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index a22ccd57bd..248cd00e0f 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -60,4 +60,4 @@ so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the gam "title": "Conclusion" }) -Congratulations! In this kata you learned how to communicate using quantum entanglement in nonlocal quantum games. +Congratulations! In this kata you learned how to use quantum entanglement in nonlocal quantum games to get results that are better than any classical strategy can offer. From 82787421a48fb0d75d13e3e34c37f2aec7c7e3de Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:00:22 -0700 Subject: [PATCH 17/20] Update katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs Co-authored-by: Mariia Mykhailova --- .../nonlocal_games/chsh_classical_strategy/Verification.qs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs b/katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs index 09cf9500f8..d407458d85 100644 --- a/katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs +++ b/katas/content/nonlocal_games/chsh_classical_strategy/Verification.qs @@ -18,9 +18,7 @@ namespace Kata.Verification { Message("Alice and Bob's classical strategy is not optimal"); return false; } - else { - Message("Correct!"); - } + Message("Correct!"); true } From 4c32452e36419b1810fbe7cf741292beb11252cd Mon Sep 17 00:00:00 2001 From: Mariia Mykhailova Date: Fri, 12 Jul 2024 17:27:56 -0700 Subject: [PATCH 18/20] Update katas/content/nonlocal_games/chsh_classical_win_condition/solution.md --- .../nonlocal_games/chsh_classical_win_condition/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md index dcfa9d6139..f80b0552ae 100644 --- a/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md +++ b/katas/content/nonlocal_games/chsh_classical_win_condition/solution.md @@ -1,7 +1,7 @@ There are four input pairs (X, Y) possible, (0,0), (0,1), (1,0), and (1,1), each with 25% probability. In order to win, Alice and Bob have to output different bits if the input is (1,1), and same bits otherwise. -To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. You can compute these values using [`built-in operators`](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. +To check whether the win condition holds, you need to compute $x ∧ y$ and $a ⊕ b$ and to compare these values: if they are equal, Alice and Bob won. You can compute these values using [built-in operators](https://learn.microsoft.com/azure/quantum/user-guide/language/expressions/logicalexpressions): $x ∧ y$ as `x and y` and $a ⊕ b$ as `a != b`. @[solution]({ From d45d6fd0509f9a70ae9c81c2178c13a93507e180 Mon Sep 17 00:00:00 2001 From: Gregory Gridin Date: Fri, 12 Jul 2024 17:39:42 -0700 Subject: [PATCH 19/20] Removing external link (John Watrous) --- katas/content/nonlocal_games/index.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index b0708a1028..2a8eb30db2 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -34,15 +34,13 @@ so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the gam > * ∧ is the standard bitwise AND operator. > * ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. -* You can read more about CHSH game in the [lecture notes](https://cs.uwaterloo.ca/~watrous/QC-notes/QC-notes.20.pdf) by - John Watrous. -* At the end of the section you can find an implementation of the CHSH game that includes an explanation of the history and theory behind the game. - @[section]({ "id": "nonlocal_games__chsh_game_classical", "title": "Part I. Classical CHSH" }) +To start with, let's take a look at how you would play the classical variant of this game without access to any quantum tools. + @[exercise]({ "id": "nonlocal_games__chsh_classical_win_condition", "title": "Win Condition", From 901b0fd28a3942ddeed934dd5936c032b6ab5125 Mon Sep 17 00:00:00 2001 From: Gregory Gridin <51379812+ggridin@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:40:09 -0700 Subject: [PATCH 20/20] Update katas/content/nonlocal_games/index.md Co-authored-by: Mariia Mykhailova --- katas/content/nonlocal_games/index.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/katas/content/nonlocal_games/index.md b/katas/content/nonlocal_games/index.md index 248cd00e0f..0a2a7f6d0e 100644 --- a/katas/content/nonlocal_games/index.md +++ b/katas/content/nonlocal_games/index.md @@ -34,9 +34,6 @@ so that X ∧ Y = A ⊕ B. The trick is, they can not communicate during the gam > * ∧ is the standard bitwise AND operator. > * ⊕ is the exclusive or, or XOR operator, so (P ⊕ Q) is true if exactly one of P and Q is true. -* You can read more about CHSH game in the [lecture notes](https://cs.uwaterloo.ca/~watrous/QC-notes/QC-notes.20.pdf) by - John Watrous. -* At the end of the section you can find an implementation of the CHSH game that includes an explanation of the history and theory behind the game. @[section]({ "id": "nonlocal_games__chsh_game_classical",