Skip to content
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

Apply as_sweep for SqrtCZGauge #6931

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

Conversation

babacry
Copy link
Collaborator

@babacry babacry commented Jan 9, 2025

Example usage:

exec parameterized_circuit, sweeps = self.gauge_transformer.as_sweep(input_circuit, N=5)

with input_circuit:

0: ───H───@───────────────H───M───
          │
1: ───────@^0.5───@───────H───M───
                  │
2: ───────────────@^0.5───H───M───

output parameterized circuit is:

0: ───H───PhXZ(a=a0,x=x0,z=z0)───@──────PhXZ(a=a2,x=x2,z=z2)────────────────────────────────────────────────────────H───M───
                                 │
1: ───────PhXZ(a=a1,x=x1,z=z1)───@^s0───PhXZ(a=a3,x=x3,z=z3)───PhXZ(a=a4,x=x4,z=z4)───@──────PhXZ(a=a6,x=x6,z=z6)───H───M───
                                                                                      │
2: ────────────────────────────────────────────────────────────PhXZ(a=a5,x=x5,z=z5)───@^s1───PhXZ(a=a7,x=x7,z=z7)───H───M───

randomly generalized sweeps

cirq.Points('x0', [0.0, 0.0, 0.0, 0.0, 0.0]) + cirq.Points('z0', [0.0, 0.0, 0.0, 0.0, 0.0]) + cirq.Points('a0', [0.0, 0.0, 0.0, 0.0, 0.0]) + 
cirq.Points('x1', [1, 0.0, 0.0, 1, 0.0]) + cirq.Points('z1', [0, 0.0, 0.0, 0, 0.0]) + cirq.Points('a1', [-1.0, 0.0, 0.0, -1.0, 0.0]) + 
cirq.Points('x2', [0.0, 0.0, 0.0, 0.0, 0.0]) + cirq.Points('z2', [0.5, 0.0, 0.0, 0.5, 0.0]) + cirq.Points('a2', [0.0, 0.0, 0.0, 0.0, 0.0]) + 
cirq.Points('x3', [1, 0.0, 0.0, 1, 0.0]) + cirq.Points('z3', [0, 0.0, 0.0, 0, 0.0]) + cirq.Points('a3', [-1.0, 0.0, 0.0, -1.0, 0.0]) + 
cirq.Points('x4', [1, 1, 0.0, 0.0, 0.0]) + cirq.Points('z4', [0, 0, 0.0, 0.0, 0.0]) + cirq.Points('a4', [-1.0, -1.0, 0.0, 0.0, 0.0]) + 
cirq.Points('x5', [0.0, 0.0, 0.0, 0.0, 1]) + cirq.Points('z5', [0.0, 0.0, 0.0, 0.0, 0]) + cirq.Points('a5', [0.0, 0.0, 0.0, 0.0, -1.0]) + 
cirq.Points('x6', [1, 1, 0.0, 0.0, 0.0]) + cirq.Points('z6', [0, 0, 0.0, 0.0, 0.5]) + cirq.Points('a6', [-1.0, -1.0, 0.0, 0.0, 0.0]) + 
cirq.Points('x7', [0.0, 0.0, 0.0, 0.0, 1]) + cirq.Points('z7', [0.5, 0.5, 0.0, 0.0, 0]) + cirq.Points('a7', [0.0, 0.0, 0.0, 0.0, -1.0]) + 
cirq.Points('s0', [-0.5, 0.5, 0.5, -0.5, 0.5]) + cirq.Points('s1', [-0.5, -0.5, 0.5, 0.5, -0.5])

@CirqBot CirqBot added the size: M 50< lines changed <250 label Jan 9, 2025
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.87%. Comparing base (5cc14ba) to head (b2fbfb5).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6931    +/-   ##
========================================
  Coverage   97.87%   97.87%            
========================================
  Files        1084     1084            
  Lines       94579    94814   +235     
========================================
+ Hits        92568    92799   +231     
- Misses       2011     2015     +4     

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

@babacry babacry force-pushed the sqrtcz branch 2 times, most recently from 033d607 to 785dd6b Compare January 9, 2025 05:29
@babacry babacry marked this pull request as ready for review January 9, 2025 06:12
@babacry babacry requested review from vtomole and a team as code owners January 9, 2025 06:12
@babacry babacry requested a review from fdmalone January 9, 2025 06:12
Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

this is great but lets allow some flexiblity when parameterizing two qubit gates

@babacry babacry force-pushed the sqrtcz branch 3 times, most recently from 9d66a84 to 77ae6b4 Compare January 15, 2025 04:12
@babacry babacry requested review from NoureldinYosri and eliottrosenberg and removed request for fdmalone January 15, 2025 04:28
@babacry babacry linked an issue Jan 15, 2025 that may be closed by this pull request
Copy link
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, Renyi!!

"""

symbolizer_fn: Callable[
[ops.Gate, Sequence[sympy.Symbol]], Tuple[ops.Gate, Dict[str, Union[float, int]]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit - here and at other instances of Union[float, int]

Suggested change
[ops.Gate, Sequence[sympy.Symbol]], Tuple[ops.Gate, Dict[str, Union[float, int]]]
[ops.Gate, Sequence[sympy.Symbol]], Tuple[ops.Gate, Dict[str, numbers.Real]]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! Done.

In switching to Real, extra code type hinting using isinstance(..., Real) is necessary as Types from "numbers" aren't supported for static type checking. So I wonder what is the typical way to determine whether to use float (should be good enough in most cases as int can naturally be converted to float?), Real (better generic real number support, easy to switch to Complex?), Union[float, int] (type checking friendly) in cirq?

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.

@babacry - LGTM with a couple of minor suggestions.

@babacry
Copy link
Collaborator Author

babacry commented Jan 18, 2025

Thank you so much for the valuable suggestions, Pavol! @pavoljuhas

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.

Support as_sweep for gauge_compiling.
5 participants