Skip to content

Update contextuality module to match published Science paper - #505

Merged
mhucka merged 3 commits into
quantumlib:mainfrom
shashwatk1998:contextuality-science-update
Nov 24, 2026
Merged

mhucka merged 3 commits into
quantumlib:mainfrom
shashwatk1998:contextuality-science-update

Conversation

@shashwatk1998

Copy link
Copy Markdown
Contributor

Making changes to match the content in the published paper: Science 394, 870-874 (2026) (DOI 10.1126/science.aec3042)

  • Remove withdrawn effective_layers metric from ShallowCircuitResults and replace with classical_bound (4 / classical_layers, matching Fig. 4B).
  • Update shallow_circuits_experiment_test.py to test classical_bound against valid-outcome probabilities.
  • Update module docstrings across recirq/contextuality to cite the paper, and standardize Bell-Kochen-Specker (BKS) and magic square naming.

- Remove withdrawn effective_layers metric from ShallowCircuitResults and replace with classical_bound (4 / classical_layers, matching Fig. 4B).
- Update shallow_circuits_experiment_test.py to test classical_bound against valid-outcome probabilities.
- Update module docstrings across recirq/contextuality to cite Science 394, 870-874 (2026) (DOI 10.1126/science.aec3042), and standardize Bell-Kochen-Specker (BKS) and magic square naming.
@shashwatk1998

Copy link
Copy Markdown
Contributor Author

@mhucka ready for review!

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

Thanks for doing the updates so quickly!

In addition to the specific comments below, can you also please do a sweep for non-inclusive terms? In particular,

  • avoid "master" (e.g., in "master list")
  • avoid "dummy" (e.g., in "dummy index")

Possible replacements include "main list" or "primary list", and "placeholder index" or just "index".

Comment on lines +412 to +414
for num_qubits in self.total_dof.keys():
classical_layers[num_qubits] = math.ceil(np.log2(self.total_dof[num_qubits]))
classical_bound[num_qubits] = 4.0 / classical_layers[num_qubits]

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.

I think this may have some problems:

  • When n_qubits == 1 (accepted by both hlf_circuit_biased_dropout and ShallowCircuitExperiment), total_cz == 0 so total_dof == 1 and classical_layers[1] == 0. Previously _analyze() succeeded because it guarded if score > 0: before dividing; now 4.0 / 0 raises ZeroDivisionError inside _analyze(), breaking all three properties (probability_of_valid_outcomes, classical_layers, and classical_bound) for any run containing n_qubits=1 (or total_dof <= 1).

  • For n_qubits in {2, 3, 4} on a 2D grid (total_dof <= 8), classical_layers is 2 or 3, yielding classical_bound values of 2.0 or 1.333... (> 1.0), which is invalid for a success-probability bound.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great point, the probability should not be grater than 1. Fixing it.

Comment thread recirq/contextuality/kochen_specker.py Outdated

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.

Possibly missed:

Suggested change
"""Estimate chi_BKS (with uncertainty) from a context_to_parities mapping."""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

Comment thread recirq/contextuality/kochen_specker.py Resolved
return self._classical_layers

@property
def classical_bound(self) -> dict[int, float] | None:

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.

Suggested change
def classical_bound(self) -> dict[int, float] | None:
def classical_bound(self) -> dict[int, float]:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

Comment thread recirq/contextuality/kochen_specker.py Outdated
Comment on lines +117 to +120
"""Builds a Bell-Kochen-Specker (BKS) experiment, which measures state-independent contextuality.

See https://arxiv.org/pdf/2512.02284 for more details.
See Google Quantum AI and Collaborators, Science 394, 870-874 (2026)
(https://doi.org/10.1126/science.aec3042) for more details.

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.

I'm not sure why the CI didn't pick this up, but the line length is > 100.

Suggested change
"""Builds a Bell-Kochen-Specker (BKS) experiment, which measures state-independent contextuality.
See https://arxiv.org/pdf/2512.02284 for more details.
See Google Quantum AI and Collaborators, Science 394, 870-874 (2026)
(https://doi.org/10.1126/science.aec3042) for more details.
"""Builds a Bell-Kochen-Specker (BKS) experiment, which measures state-independent
contextuality. See Google Quantum AI and Collaborators, Science 394, 870-874 (2026)
(https://doi.org/10.1126/science.aec3042) for more details.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed it!

Comment thread recirq/contextuality/kochen_specker.py Outdated
Comment on lines 372 to 373
list of tuples containing whether each tuples of previous context, where each
tuple contains the axis context corresponds to a row or column context. For the

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.

I can't figure out what this sentence means. Maybe something got garbled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clarified!

- Clamp classical_bound at 1.0 when classical_layers <= 4 (fixing ZeroDivisionError at total_dof=1 and bounds > 1.0) and tighten its return type to dict[int, float].
- Add key-set equality assertions in test_experiment() and a direct unit test covering small total_dof edge cases and lazy initialization of classical_bound.
- Add module docstring to kochen_specker.py, apply exact docstring suggestions, and clarify estimate_coincidences docstring.
- Replace non-inclusive terms (master -> primary, dummy -> placeholder).
@shashwatk1998

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, @mhucka! Addressed all comments in the latest commit. Ready for another look.

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

@mhucka
mhucka enabled auto-merge November 24, 2026 18:28
@mhucka
mhucka added this pull request to the merge queue Nov 24, 2026
Merged via the queue into quantumlib:main with commit e9f8b5a Nov 24, 2026
18 of 21 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.

2 participants