Skip to content

Create a transformer that cancels the effect of Z-phases#6837

Merged
NoureldinYosri merged 15 commits intoquantumlib:mainfrom
NoureldinYosri:z_transformer
Dec 20, 2024
Merged

Create a transformer that cancels the effect of Z-phases#6837
NoureldinYosri merged 15 commits intoquantumlib:mainfrom
NoureldinYosri:z_transformer

Conversation

@NoureldinYosri
Copy link
Copy Markdown
Collaborator

No description provided.

@CirqBot CirqBot added the size: M 50< lines changed <250 label Dec 11, 2024
@NoureldinYosri NoureldinYosri marked this pull request as ready for review December 11, 2024 22:26
@NoureldinYosri NoureldinYosri requested review from a team, mrwojtek and vtomole as code owners December 11, 2024 22:26
Comment thread cirq-core/cirq/experiments/z_phase_calibration.py Outdated
*,
context: Optional[transformer_api.TransformerContext] = None,
) -> 'cirq.Circuit':
"""Replace every occurance of a calibrated gate with a proper replacement.
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.

Maybe a more descriptive docstring?

Comment on lines +353 to +355
theta=self.target_as_fsim.theta - delta_theta,
gamma=self.target_as_fsim.gamma - delta_gamma,
phi=self.target_as_fsim.phi - delta_phi,
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.

theta and phi are not z-phases. Can we directly insert the z-rotations that take care of cancelling the phases (just the other three angles)?

Copy link
Copy Markdown
Collaborator Author

@NoureldinYosri NoureldinYosri Dec 13, 2024

Choose a reason for hiding this comment

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

theta and phi are not z-phases.

yes, but if they were calibrated then it makes sense to change them as well. if they were not calibrated then the delta would be $=0$ and nothing happens.

Can we directly insert the z-rotations that take care of cancelling the phases (just the other three angles)?

we can, I'm okay either way

Copy link
Copy Markdown
Collaborator

@eliottrosenberg eliottrosenberg Dec 13, 2024

Choose a reason for hiding this comment

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

In order for this to be ready to run on hardware, it would be great if there were at least an option to only cancel the z-phases (not theta and phi) and for this to be implemented as z rotations rather than fSim gates. Thanks, Nour.

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.

ptal

@NoureldinYosri NoureldinYosri changed the title Create a transformer to replace gates with their calibrated versions Create a transformer cancels the effect of Z-phases Dec 14, 2024
Copy link
Copy Markdown
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks, Nour!

Tested in this colab.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.86%. Comparing base (0d9a6ee) to head (1dc99b0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6837      +/-   ##
==========================================
- Coverage   97.86%   97.86%   -0.01%     
==========================================
  Files        1084     1084              
  Lines       94013    94093      +80     
==========================================
+ Hits        92004    92082      +78     
- Misses       2009     2011       +2     

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

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.

LGTM, but please see the comments.

Comment on lines +357 to +358
angles = np.array(_z_angles(self.target_as_fsim, gate)) / np.pi
angles = -angles # Take the negative to cancel the effect.
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.

Nit - consider returning pi-normalized np.array tuple from the _z_angles and perhaps renaming it to _z_powers.

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 prefer to leave it as it's now ... the contructor of PhasedFSimGate does the normalization

Comment thread cirq-core/cirq/experiments/z_phase_calibration_test.py Outdated
Comment thread cirq-core/cirq/ops/fsim_gate.py
Comment thread cirq-core/cirq/experiments/z_phase_calibration_test.py
@NoureldinYosri NoureldinYosri enabled auto-merge (squash) December 20, 2024 19:40
@NoureldinYosri NoureldinYosri merged commit 29d99d3 into quantumlib:main Dec 20, 2024
@mhucka mhucka changed the title Create a transformer cancels the effect of Z-phases Create a transformer that cancels the effect of Z-phases Apr 8, 2025
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants