Skip to content

Add corresponding serialization for TwoPulseFSimTag#7971

Merged
pavoljuhas merged 3 commits intomainfrom
u/ybc/two_pulse_tag_ser
Mar 25, 2026
Merged

Add corresponding serialization for TwoPulseFSimTag#7971
pavoljuhas merged 3 commits intomainfrom
u/ybc/two_pulse_tag_ser

Conversation

@BichengYing
Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions github-actions bot added the size: L 250< lines changed <1000 label Mar 24, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.63%. Comparing base (fe93650) to head (5c1caf9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7971   +/-   ##
=======================================
  Coverage   99.62%   99.63%           
=======================================
  Files        1110     1110           
  Lines       99647    99662   +15     
=======================================
+ Hits        99278    99294   +16     
+ Misses        369      368    -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.

@BichengYing BichengYing marked this pull request as ready for review March 24, 2026 19:40
Copy link
Copy Markdown
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 think we should put translate_via_model and translate_to_two_pulse under a oneof in the proto since only one of those two flags may be set.

Otherwise LGTM.

Comment on lines +218 to +226
@@ -219,6 +219,11 @@ message FSimGate {
// cirq.FSimGate(...).with_tags(cirq_google.FSimViaModelTag()).
// This field controls how we translate the gate implementation.
bool translate_via_model = 3;

// If true, this is equivalent to:
// cirq.FSimGate(...).with_tags(cirq_google.TwoPulseFSimTag()).
// This field controls how we translate the gate implementation.
bool translate_to_two_pulse = 4;
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.

Can we put them under a oneof translation_flag or such?

This would make it explicit in the proto that only one of these can be set.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I really prefer not to do it because likely it can cause backward compatibility and this code is tied with internal pyle code. I will have headache for the sync between internal and external version for this minor improvement. I think the raise Value check is sufficient (and I don't think anyone will use this way). Does that make sense?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Discussed offline, it seems backwards compatible. So no such concern. Updated the code to use one-of

Comment on lines +375 to +376
if msg.fsimgate.translate_via_model and msg.fsimgate.translate_to_two_pulse:
raise ValueError("You cannot add both FSimViaModelTag and TwoPulseFSimTag")
Copy link
Copy Markdown
Collaborator

@pavoljuhas pavoljuhas Mar 24, 2026

Choose a reason for hiding this comment

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

Maybe let us have the message in a passive voice as do the other exceptions in the module:

Suggested change
if msg.fsimgate.translate_via_model and msg.fsimgate.translate_to_two_pulse:
raise ValueError("You cannot add both FSimViaModelTag and TwoPulseFSimTag")
if msg.fsimgate.translate_via_model and msg.fsimgate.translate_to_two_pulse:
raise ValueError("The operation cannot have both FSimViaModelTag and TwoPulseFSimTag")

BTW, if we do the oneof in proto, the condition at 375 will be never true.
Perhaps we should collect a set of special tags instead and handle it accordingly, e.g.,

translation_tags = {tag for tag in op.tags if isinstance(tag, (FSimViaModelTag, TwoPulseFSimTag))}
if len(translation_tags) > 1: ...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah, this is almost impossible case. With this oneof, I think we can just simply remove it

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 it is better to keep the check. The op is a cirq object which can have both tags assigned, and then it is unclear what should it be. (The serializer will set the translate_to_two_pulse, but that is only because TwoPulseFSimTag is checked for last)

@BichengYing BichengYing requested a review from pavoljuhas March 24, 2026 22:18
Copy link
Copy Markdown
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.

Let us restore back the test_serialize_fsim_both_translation_tags which you had here before. Those 2 tags can be still added together which is ambiguous for serialization and should be disallowed.

@BichengYing
Copy link
Copy Markdown
Collaborator Author

Let us restore back the test_serialize_fsim_both_translation_tags which you had here before. Those 2 tags can be still added together which is ambiguous for serialization and should be disallowed.

Sure. Done

@BichengYing BichengYing requested a review from pavoljuhas March 24, 2026 23:35
@pavoljuhas pavoljuhas added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit e605fa8 Mar 25, 2026
47 checks passed
@pavoljuhas pavoljuhas deleted the u/ybc/two_pulse_tag_ser branch March 25, 2026 00:12
jkalsi1 pushed a commit to jkalsi1/Cirq that referenced this pull request Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants