Skip to content

Fix test assertion in raw_types_test.py. #7401

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

codrut3
Copy link
Contributor

@codrut3 codrut3 commented Jun 1, 2025

This fixes a small issue that I found while working on #7291

TaggedOperation _decompose_ calls protocols.decompose_once (see here). So it must be compared against cirq.decompose_once.

@codrut3 codrut3 requested review from vtomole and a team as code owners June 1, 2025 10:02
@codrut3 codrut3 requested a review from 95-martin-orion June 1, 2025 10:02
@github-actions github-actions bot added the Size: XS <10 lines changed label Jun 1, 2025
Copy link

codecov bot commented Jun 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.69%. Comparing base (d1d25f8) to head (52f5f7c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7401      +/-   ##
==========================================
- Coverage   98.69%   98.69%   -0.01%     
==========================================
  Files        1112     1112              
  Lines       97754    97753       -1     
==========================================
- Hits        96477    96475       -2     
- Misses       1277     1278       +1     

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

Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

I wonder if we should be testing the _decompose_ method directly or rather its effect on the public cirq.decompose API.

How about changing it like this:

diff --git a/cirq-core/cirq/ops/raw_types_test.py b/cirq-core/cirq/ops/raw_types_test.py
index c4fda0413..b819ade48 100644
--- a/cirq-core/cirq/ops/raw_types_test.py
+++ b/cirq-core/cirq/ops/raw_types_test.py
@@ -652,6 +652,5 @@ def test_tagged_operation_forwards_protocols() -> None:
     np.testing.assert_equal(cirq.unitary(tagged_h), cirq.unitary(h))
     assert cirq.has_unitary(tagged_h)
-    assert cirq.decompose(tagged_h) == cirq.decompose(h)
-    assert [*tagged_h._decompose_()] == cirq.decompose(h)
+    assert cirq.decompose(tagged_h) == cirq.decompose_once(h)
     assert cirq.pauli_expansion(tagged_h) == cirq.pauli_expansion(h)
     assert cirq.equal_up_to_global_phase(h, tagged_h)

Otherwise LGTM.

We can verify the call of `decompose_once` via public API.
@pavoljuhas
Copy link
Collaborator

@codrut3 - I have pushed a small tweak from my comment above - #7401 (review).

Please let me know if it is OK with you. LGTM for myself.

@codrut3
Copy link
Contributor Author

codrut3 commented Jun 4, 2025

@codrut3 - I have pushed a small tweak from my comment above - #7401 (review).

Please let me know if it is OK with you. LGTM for myself.

I'm not sure this is correct. My understanding is that cirq.decompose() attempts to recursively decompose using dfs, so it shouldn't be equivalent to a single step of decomposition. On the other hand, the _decompose_ method of a gate / operation is expected to be a single step (like here for ControlledGate - only does one step), so it must be compared with cirq.decompose_once.

So if you don't want to test _decompose_, just leave the first line:

assert cirq.decompose(tagged_h) == cirq.decompose(h)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: XS <10 lines changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants