Skip to content

Conversation

@alejogoogle
Copy link

No description provided.

@dstrain115 dstrain115 self-requested a review December 17, 2025 00:37
# See the License for the specific language governing permissions and
# limitations under the License.

"""Runs the MagicSquareGame."""
Copy link
Collaborator

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]
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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]
Copy link
Collaborator

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
Copy link
Collaborator

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) .
Copy link
Collaborator

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):
Copy link
Collaborator

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 ")
Copy link
Collaborator

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
Copy link
Collaborator

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.

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.

2 participants