Make CouplerPulse sweepable
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
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 Should I start a pull request where I delete those checks?
I'd be ok with removing the checks, since they're easily bypassed by using symbols anyway.
@eliottrosenberg can this be closed?
Resolved by https://github.com/quantumlib/Cirq/pull/5919.