Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Make CouplerPulse sweepable

Open eliottrosenberg opened this issue 3 years ago • 3 comments

I am building fSim gates using CouplerPulse (located in cirq_google/experimental/ops/coupler_pulse.py). To calibrate them, I need to sweep over hold_time and coupling_mhz. I wrote a sweep to do this, but it throws the following error because cirq.Duration is not sweepable:

File [...]/cirq_google/experimental/ops/coupler_pulse.py:73, in CouplerPulse.__init__(self, hold_time, coupling_mhz, rise_time, padding_time)
     55 def __init__(
     56     self,
     57     hold_time: cirq.Duration,
   (...)
     60     padding_time: Optional[cirq.Duration] = cirq.Duration(nanos=2.5),
     61 ):
     62     """Inits CouplerPulse.
     63 
     64     Args:
   (...)
     71         ValueError: If any time is negative or if the total pulse is too long.
     72     """
---> 73     if hold_time < _MIN_DURATION:
     74         raise ValueError(f'hold_time must be greater than {_MIN_DURATION}')
     75     if padding_time < _MIN_DURATION:

File [...]/sympy/core/relational.py:398, in Relational.__bool__(self)
    397 def __bool__(self):
--> 398     raise TypeError("cannot determine truth value of Relational")

TypeError: cannot determine truth value of Relational

If I comment out the offending lines (the ones checking the values of hold_time, rise_time, and total_time, then everything works. I get nice-looking results, and it is much faster than running this without the sweep.

If a more permanent solution could be found, that would be very helpful.

Thank you!

@95-martin-orion @tanujkhattar

eliottrosenberg avatar Oct 12 '22 18:10 eliottrosenberg

I have a PR up to allow symbols for coupling_mhz: https://github.com/quantumlib/Cirq/pull/5908. Note that cirq.Duration is sweepable if you construct it with a symbol, e.g. cirq.Duration(nanos=sympy.Symbol('delay_ns')) but we need to modify the CouplerPulse constructor to not check the durations if they are symbolic (or to remove the checks altogether since these should be handled internally after parameter resolution).

maffoo avatar Oct 12 '22 21:10 maffoo

@maffoo Should I start a pull request where I delete those checks?

eliottrosenberg avatar Oct 12 '22 21:10 eliottrosenberg

I'd be ok with removing the checks, since they're easily bypassed by using symbols anyway.

maffoo avatar Oct 12 '22 21:10 maffoo

@eliottrosenberg can this be closed?

senecameeks avatar May 17 '23 17:05 senecameeks

Resolved by https://github.com/quantumlib/Cirq/pull/5919.

eliottrosenberg avatar May 18 '23 06:05 eliottrosenberg