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 2 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.86%. Comparing base (ecf9ed7) to head (0a3ece3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6931   +/-   ##
=======================================
  Coverage   97.86%   97.86%           
=======================================
  Files        1084     1084           
  Lines       94315    94327   +12     
=======================================
+ Hits        92301    92316   +15     
+ Misses       2014     2011    -3     

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

@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
Comment on lines -92 to +91
two_qubit_gate=ops.ISWAP,
pre_q0=xy_a,
pre_q1=xy_b,
post_q0=xy_b,
post_q1=xy_a,
support_sweep=True,
two_qubit_gate=ops.ISWAP, pre_q0=xy_a, pre_q1=xy_b, post_q0=xy_b, post_q1=xy_a
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like you committed a lot of files that you didn't intend to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is intended.

There are 2 commits in this,

  • the first commit apply as_sweep for SqrtCZGauge.
  • the second commit cleanup the support_sweep parameter as all the gauges will by default support sweep.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Regarding the second point, do you then need to specify somewhere that the sycamore gauge does not support sweeps yet? (https://github.com/quantumlib/Cirq/blob/main/cirq-google/cirq_google/transformers/sycamore_gauge.py)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, good point! as_sweep is already supported for sycamore gauge. We don't need to add extra code /comments here to support sycamore gauge.

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

def __init__(
self,
# target can be either a specific gate, gatefamily or gateset
# which allows matching parametric gates.
target: Union[ops.Gate, ops.Gateset, ops.GateFamily],
gauge_selector: Callable[[np.random.Generator], Gauge],
symbolize_2_qubit_gate_fn: Optional[
Callable[[ConstantGauge, sympy.Symbol], Tuple[ops.Gate, float]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets allow for some flexibility and make the signature deal with lists

Callable[[ConstantGauge, Sequence[sympy.Symbol]], Sequence[Tuple[ops.Gate, Union[float, int]]]]

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