Skip to content

Feature: Add Magic Square game for Contextuality demonstration#448

Open
alejogoogle wants to merge 26 commits into
quantumlib:mainfrom
alejogoogle:mermin-peres-game
Open

Feature: Add Magic Square game for Contextuality demonstration#448
alejogoogle wants to merge 26 commits into
quantumlib:mainfrom
alejogoogle:mermin-peres-game

Conversation

@alejogoogle

@alejogoogle alejogoogle commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

This PR adds a new experimental module to the ReCirq repository that implements the Mermin-Peres Magic Square game (a form of quantum pseudo-telepathy).

Specifically, this code:

  • Adds new functionality: It provides a framework to run the game using cirq on both simulators and quantum hardware.

  • Implements three experimental variations:

    1. infer_3rd: Measuring two observables and calculating the third classically.

    2. measure_3rd_classical_multiplication: Measuring components and multiplying the outcomes.

    3. measure_3rd_quantum_multiplication: Using two-qubit interactions to directly measure the product observable.

  • Provides analysis tools: Includes a ContextualityResult class to calculate win rates, agreement matrices, and parity check fractions to verify quantum non-locality.

Relevance to Contextuality Work
The Magic Square game is a cornerstone "warm-up" experiment for demonstrating quantum contextuality (https://arxiv.org/pdf/2512.02284). It proves that measurement outcomes cannot be pre-determined independently of their "context" (which other measurements are performed simultaneously).

No new external libraries are required.

@dstrain115 dstrain115 self-requested a review December 17, 2025 00:37
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py
@mhucka

mhucka commented Jan 15, 2026

Copy link
Copy Markdown
Collaborator

In addition to addressing Doug's comments about the code, I think also it's important to add a description to the pull request. Here are some points to address:

  • What is this PR for? What does it actually do? From the title, one can infer it concerns a game, but that's about it – the title doesn't say if this PR adds code for a game, or fixes a problem with exiting code, or something else. (We shouldn't assume that the reader of the PR will take time to read the code in order to deduce these things.)

  • What is the relevance to the contextuality work? Is this game mentioned in the paper, or is it just a fun supplement, or something else? (We shouln't assume that the reader will go look at the paper to figure that out.)

  • Is this related to any other PR or issue in the ReCirq repo?

  • Does this game require new libraries that aren't already in the project's requirements?

I realize it's more work to write a description, and I'm sorry for that. Perhaps an AI tool can help with this in some way.

Comment thread recirq/contextuality/magic_square_game.py Outdated
@alejogoogle alejogoogle changed the title Contextuality: MagicSquare game Feature: Add Magic Square game for Contextuality demonstration Feb 20, 2026

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of these items are nit-picky details, and I tried to make it easy to accept or reject the changes using GitHub's interface for suggested edits. Hopefully that'll make this easier.

Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
Comment thread recirq/contextuality/magic_square_game.py Outdated
@alejogoogle alejogoogle requested a review from mhucka July 13, 2026 16:54

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! One

Comment on lines +264 to +267
"""Find the fraction of the time that Alice and Bob
Alice and Bob "agree" (in the intersection)
and
they "multiply correctly" (alice to -1 and bob to +1).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like something happened to the formatting of this docstring. Suggested fix:

Suggested change
"""Find the fraction of the time that Alice and Bob
Alice and Bob "agree" (in the intersection)
and
they "multiply correctly" (alice to -1 and bob to +1).
"""Find the fraction of the time that Alice and Bob "agree" (in the intersection)
and they "multiply correctly" (alice to -1 and bob to +1).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, @alejogoogle should that really say alice to -1 and bob to +1? I thought Alice was +1 and Bob was -1.

alejogoogle and others added 2 commits July 14, 2026 10:02
Co-authored-by: Michael Hucka <mhucka@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants