Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Nonlocal Games katas to quantum.microsoft.com #1596

Open
1 of 3 tasks
tcNickolas opened this issue May 31, 2024 · 10 comments
Open
1 of 3 tasks

Migrate Nonlocal Games katas to quantum.microsoft.com #1596

tcNickolas opened this issue May 31, 2024 · 10 comments
Labels
enhancement New feature or request katas

Comments

@tcNickolas
Copy link
Contributor

tcNickolas commented May 31, 2024

Current CHSH game, GHZ game, and Mermin-Peres magic square game katas cannot be used with the modern QDK. It would be nice to have them available as part of the new katas experience.

I think each of them is too small to warrant a separate kata in the new experience, so it would make sense to merge them together into one kata called "Nonlocal Games: CHSH, GHZ, and Mermin-Peres".

We'll probably want to explain each quantum strategy ahead of the exercises that implement it, same as we did in QEC Shor kata, since it's tricky to come up with independently (especially for the magic square!)

  • CHSH game: Keep task 1.1, merge two cells in task 1.2 in one task by defining an operation that returns a tuple of two operations, one for Alice and one for Bob, drop 2.1 and 2.3, keep 2.2 and 2.4-2.5 (possibly make 2.5 a demo), keep the discussion of quantum strategy and its win probability.
  • GHZ game: Keep task 1.1, merge 1.2 and 1.3 in a more open-ended task that evaluates success probability of a classical strategy, keep 1.4 and 2.1-2.3 (possibly make 2.3 a demo), keep the discussion of quantum strategy and its win probability.
  • Mermin-Peres: Merge 1.1.1 and 1.1.2 into one task with Boolean flag isAlice, keep 1.2 and 1.3 (merge two cells in 1.3 in one task returning a tuple), keep 2.1, drop 2.2 (it will be verified in 2.3 automatically), keep 2.3-2.7.
@tcNickolas tcNickolas added enhancement New feature or request katas labels May 31, 2024
@ggridin
Copy link
Contributor

ggridin commented Jul 3, 2024

I'd like to work on these issues

Here are a few clarifying questions:
What do you think is a good section structure for nonlocal games?
Should I move quantum demos and discussions to separate sections?

Suggestion for sections (total 10, maybe 13):

  1. Overview (to be written? This section will contain the idea of nonlocal games + the topic summary + prerequisite knowledge)
  2. CHSH game (overview moved from CHSH overview
  3. Classical CHSH (Tasks 1.1, 1.2 The content is from the above link, readme, and workbook)
  4. Quantum CHSH (Tasks 2.2, 2.4, 2.5(demo and Discussion: probability of victory for quantum strategy ) )
  5. GHZ game (overview moved from GHZ overview )
  6. Classical GHZ (Tasks 1.1, 1.2/3, 1.4)
  7. Quantum GHZ (Tasks 2.1, 2.2, 2.3 + discussion + demo)
  8. Magic Square Game (overview moved from Magic Square overview)
  9. Classical Magic Square Game (Tasks 1.1, 1.2, 1.3)
  10. Quantum Magic Square Game (Tasks 2.1, 2.3, 2.4, 2.5, 2.6, 2.7 + demo + experiments)

@tcNickolas
Copy link
Contributor Author

tcNickolas commented Jul 4, 2024

This breakdown sounds about right, yes.
The limitation we have for the infrastructure is that each exercise is its own section, and after an exercise you must have a new section immediately, you can't have any follow-up text. So whenever you have exercises and then a demo/discussion, you'll need to create a section to hold these, titled something like "Quantum CHSH End to End". You can have a discussion immediately after a demo without a new section, though, since demos don't define their own sections

You'll probably want to start with adding just the first game to the kata in one PR, and then send two more PRs with the other games. This way the scope of each review would be smaller and I'll be able to do it faster :-)

@ggridin
Copy link
Contributor

ggridin commented Jul 5, 2024

@tcNickolas Maria - thank you for information.
Question for CHSH game, Task 1.2:
Does it make sense "...one task by defining an operation that returns a tuple" ?
Alice and Bob must not communicate during the game, but single operation that return a tuple allows a "peeking".
Two separate functions, like below, support isolation:

namespace Kata {
function AliceClassical (x : Bool) : Bool {
// Implement your solution here...
return false;
}
function BobClassical (y : Bool) : Bool {
// Implement your solution here...
return true;
}
}

I think, it make sense to merge 2 cells into 1 exercise but ask student to implement both of functions.

@tcNickolas
Copy link
Contributor Author

If the operation returns a tuple of functions, how would you implement peeking from one of them into the other? They still cannot share a state, since Q# doesn't have global variables, and sharing some function code wouldn't help.

My idea is to still have two separate functions for Alice and Bob, yes, but use the wrapper that returns both these functions, similar to task Entanglement Swapping in Teleportation kata. The learner then implements both functions indeed, but they live in one exercise.

@ggridin
Copy link
Contributor

ggridin commented Jul 8, 2024

@tcNickolas - thank you for clarification. I confused 2 values tuple with 2 functions tuple.
Where do you think, the good place for nonlocal games in katas list?
I consider to put them between marking oracles and deutsch algorithms.

@tcNickolas
Copy link
Contributor Author

I'd put it either after Superdense Coding and before Oracles or after all the oracular algorithms before QEC. Oracles and oracular algorithms are one unit logically, so I wouldn't break them up. These games don't rely on the concept of an oracle, so they can go before, together with the "simple algorithms". On the other hand, they're an optional topic (I don't cover them in my course, for example) so they can be closer to the end.

@ggridin
Copy link
Contributor

ggridin commented Jul 12, 2024

@tcNickolas I am ready to submit PR for quantum CHSH but it depends on #1710 (particularly: nonlocal_games/index.md)
Could you review?

@tcNickolas
Copy link
Contributor Author

I reviewed now! Thank you for your patience, I needed to wrap up some urgent work on other katas, and the heat this week was not helpful.
Heads up, I'll be traveling throughout next week, so will get back to reviews on July 22nd.

github-merge-queue bot pushed a commit that referenced this issue Jul 16, 2024
The link to the issue: #1596

This pull requests is covering 
1. inital folder structure for nonlocal_games
2. CHSH classical tasks (1.1 and 1.2/3)

Other PRs will follow after this commit.

Details of this PR:

Context is (mostly) copied from previous version QuantumKatas.
1. index.md for nonlocal_games is added.
   - Brief overview for nonlocal games is new.
2. chsh_classical_win_condition (task 1.1) is added.
- index.md: Reference to Q# samples is rephrased to point to this the
kata (reference implementation will be added in next quantum PR).
3. chsh_classical_strategy (combined tasks 1.2 1.3) is added.
4. Conclusion section sentence is new.

Testing done:
0. Build "python ./build.py --npm" is successful
1. Placeholder cases are syntactically correct but failing
verifications.
2. Solutions are successful.
3. Some other failure scenarios were tested manually.
4. Content screenshots are attached. 
![CHSH game Classical
-1](https://github.com/microsoft/qsharp/assets/51379812/1c1b36e1-fddc-4f54-b843-fab9b1e06046)
![CHSH game Classical Win Condition -
2](https://github.com/microsoft/qsharp/assets/51379812/8aaed771-6ba8-4b4c-8e1a-31798785fb32)
![CHSH game Classical Strategy
-3](https://github.com/microsoft/qsharp/assets/51379812/b8c1b3c3-d345-40ac-8b83-e6c216bfb80b)

---------

Co-authored-by: Mariia Mykhailova <[email protected]>
ggridin added a commit to ggridin/qsharp that referenced this issue Jul 16, 2024
@ggridin
Copy link
Contributor

ggridin commented Jul 22, 2024

@tcNickolas
As far as understand, historically, GHZ game kata is based on Michael Walter and John Watrous lectures. As entangled triple, they are using $\frac{1}{2} \big(|000\rangle - |011\rangle - |101\rangle - |110\rangle \big)$ rather than commonly used $\frac{1}{\sqrt{2}} \big(|000\rangle + |111\rangle \big)$.
As mentioned in external lectures, these states are identical up to local unitary operations.

However, the difference might cause learners confusion.
I think there are 2 ways to resolve the problem:

  1. Keep the current approach
    • add notes and the proof (because we are removing external links...) that entangled triples are identical.
    • as optional task, ask students to implement GHZ game using $\frac{1}{\sqrt{2}} \big(|000\rangle + |111\rangle \big)$ entangled state.
  2. Move to traditional GHZ state implementation. Here are 2 ways to proceed:
    • Implement approach 1 and create enhancement issue to use commonly used GHZ state
    • Switch to new implementation right now. Quantum code implementation is quite easy. Section "Discussion" will need a rework.

What do you think?

@tcNickolas
Copy link
Contributor Author

Good question!!

I like that in this variant of the game the measurements are done in Z and X bases, since they are quite commonly used in other katas, unlike the measurement in Y basis that Wikipedia suggests for the game with GHZ state. I also like that the solution for this variant is already written up :-) I would lean towards the first option you suggested, keep the current approach and add a note that this game is equivalent to the game with GHZ state itself, and mention the strategy for that state, but we probably don't need to write up the proof of these two games being equivalent, just mention that if the learner is curious they can do it as an exercise.

github-merge-queue bot pushed a commit that referenced this issue Aug 1, 2024
The link to the issue: #1596

This pull request is covering
1. CHSH quantum tasks (2.2, 2.4; 2.5 is converted to a demo)
2. CHSH discussion
3. Few changes in CHSH classical

---------

Co-authored-by: Mariia Mykhailova <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Aug 8, 2024
The link to the issue: #1596

This pull request is covering

1. GHZ classic tasks 1.1
2. GHZ task 1.2 (random) is dropped. Task 1.3 is expanded into
implementation of 3 strategies (Alice, Bob and Charlie)
This approach allow to create more complicated output like [true, false,
false] or [r, DrawRandomBool(0.8), not t]
3. GHZ classic task 1.4

---------

Co-authored-by: Mariia Mykhailova <[email protected]>
ggridin added a commit to ggridin/qsharp that referenced this issue Aug 13, 2024
ggridin added a commit to ggridin/qsharp that referenced this issue Aug 13, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 8, 2025
The link to the issue: #1596

This pull request covering
1. GHZ quantum tasks 2.1 (creating entangled triple).
2. GHZ quantum task 2.2 (quantum strategies).
3. Quantum strategy discussion.
4. GHZ quantum task 2.3 (quantum game) is converted to demo.

---------

Co-authored-by: Mariia Mykhailova <[email protected]>
Co-authored-by: César Zaragoza Cortés <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request katas
Projects
None yet
Development

No branches or pull requests

2 participants