Skip to content

Feature: Add Magic Square game for Contextuality demonstration - #448

Merged
mhucka merged 27 commits into
quantumlib:mainfrom
alejogoogle:mermin-peres-game
Jul 17, 2026
Merged

Feature: Add Magic Square game for Contextuality demonstration#448
mhucka merged 27 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 thread recirq/contextuality/magic_square_game.py Outdated

@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.

LGTM. Thank you for all the hard work!

@mhucka
mhucka enabled auto-merge July 17, 2026 18:31
@mhucka
mhucka added this pull request to the merge queue Jul 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 17, 2026
@mhucka
mhucka added this pull request to the merge queue Jul 17, 2026
Merged via the queue into quantumlib:main with commit 6a58742 Jul 17, 2026
16 checks passed
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