-
Notifications
You must be signed in to change notification settings - Fork 130
Contextuality: MagicSquare game #448
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
base: main
Are you sure you want to change the base?
Conversation
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Runs the MagicSquareGame.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the magic square game? This comment does not provide much value. I would expand this comment (or alternatively remove it) to explain what the game is and link to somewhere with more information.
| alice_choices[2, :, :, :2] = 1 - self.alice_measurements[2, :, :, :2] | ||
| bob_choices[:, 0, :, 0] = self.bob_measurements[:, 0, :, 1] | ||
| bob_choices[:, 0, :, 1] = self.bob_measurements[:, 0, :, 0] | ||
| bob_choices[:, 1:, :, :2] = self.bob_measurements[:, 1:, :, :2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of unexplained matrix manipulation. Can we add a line or two to the docstring to explain how Alice and Bob's choices are generated.
| first two. | ||
| Returns: | ||
| Alice and Bob's choices in the game. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are returned as two numpy arrays. Can we explain in what format Alice and Bob's choices are returned?
| self, | ||
| ) -> tuple[np.ndarray, np.ndarray]: | ||
| """Generate choices from Alice and Bob's measurements by measuring | ||
| two one-body obserbables and making a classical multiplication to get the result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ovservables.
| alice_choices[2, :, :, :2] = 1 - self.alice_measurements[2, :, :, :2] | ||
| bob_choices[:, 0, :, 0] = self.bob_measurements[:, 0, :, 1] | ||
| bob_choices[:, 0, :, 1] = self.bob_measurements[:, 0, :, 0] | ||
| bob_choices[:, 1:, :, :2] = self.bob_measurements[:, 1:, :, :2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very similar to the above code. Is there a way we can combine them?
Same with below.
| if np.sum(alice_triad) % 2 == 0 and np.sum(bob_triad) % 2 == 1: | ||
| number_of_matches += 1 | ||
| if alice_triad[col] == bob_triad[row]: | ||
| win_matrix[row, col] += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like repeated code from get_multiply_matrix below. Can we call that instead?
|
|
||
| def get_agree_matrix(self, game, seed: int | None = None) -> np.ndarray: | ||
| """Find the fraction of the time that Alice and Bob | ||
| Alice and Bob "agree"(in the intersection) . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: weird spacing here.
| idx = 0 | ||
|
|
||
| # Useful for classical multiplication | ||
| def multiply_bool(bool_0: list[bool] | Any, bool_1: list[bool] | Any): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split this out instead of making it an inline function (and add a docstring).
| q = alice_qubits[1:3] # data qubits | ||
| m = (alice_qubits[0], alice_qubits[3]) # measure qubits | ||
| if mermin_row == 0: | ||
| # print("print me ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
| @@ -0,0 +1,749 @@ | |||
| # Copyright 2025 Google | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add tests for this file.
No description provided.