Skip to content

Conversation

hoisinberg
Copy link
Collaborator

@hoisinberg hoisinberg commented Jul 22, 2025

The new unit test assertion involving a product of 1025 sweeps crashes the current implementation with a "max recursion depth exceeded" error, but passes with the new implementation. This is particularly relevant when dict_to_product_sweep is called with a large input dictionary.

This re-introduces the change reverted in #7522 and addresses the issue which caused the failure:

itertools.chain.from_iterable produces an Iterator as its output, meaning the output object can only be iterated through once before it is exhausted. However, Params is a type alias for Iterable[tuple['cirq.TParamKey', 'cirq.TParamVal']], meaning it is expected for a given Params to be iterated through repeatedly. This is also necessary in order for the Params produced by a Product sweep to function correctly, as the Params yielded by the individual factors' param_tuples() can appear multiple times in the compound Params of the product's param_tuples(). To properly allow the yielded Params to be iterated through repeatedly, we now use lambda values: tuple(itertools.chain.from_iterable(values) on line 234 of sweeps.py whereas the previous implementation effectively had lambda values: itertools.chain.from_iterables(values). Collecting into a tuple guarantees that we yield a repeatedly-iterable Params object.

In addition to the new test test_nested_product_zip() which reproduced the error in the previous implementation, this change has also been tested against the internal library tests which were broken by the previous implementation.

@hoisinberg hoisinberg requested review from vtomole and a team as code owners July 22, 2025 02:33
@github-actions github-actions bot added the size: S 10< lines changed <50 label Jul 22, 2025
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (11c769d) to head (3190f5d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7523      +/-   ##
==========================================
- Coverage   98.68%   98.68%   -0.01%     
==========================================
  Files        1091     1091              
  Lines       96950    96951       +1     
==========================================
- Hits        95676    95672       -4     
- Misses       1274     1279       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pavoljuhas pavoljuhas added this pull request to the merge queue Jul 22, 2025
Merged via the queue into main with commit 3031b1f Jul 22, 2025
69 of 70 checks passed
@pavoljuhas pavoljuhas deleted the u/hoisinberg/sweep-product-params branch July 22, 2025 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants