Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

cirq.X**"text" half works

Open Strilanc opened this issue 4 years ago • 5 comments

To my surprise, if you write cirq.X**"text" instead of cirq.X**sympy.Symbol("text"), thing mostly work. For example, you can run a sweep over the circuit with a dictionary mapping "text" to a value and you'll get samples back. This is because cirq.resolve_parameters treats strings as a shorthand for sympy.Symbol, as a way of removing boilerplate when specifying sweeps.

However, cirq.is_parameterized often does not recognize gates with string parameters as being parameterized. For example it fails on the case I gave above.

I think treating strings as implicitly being symbols is a reasonable idea, and I propose we codify this. Fixing it would involve finding all places with isinstance sympy.Basic checks and replacing them with is_parameterized calls, and then is_parameterized would also handle the string case.

Strilanc avatar Apr 23 '20 20:04 Strilanc

Hey, I would like to work on this issue!

MrSaral avatar Apr 26 '20 03:04 MrSaral

I like the idea, don't see a reason why not. Should be relatively straightforward to implement. @MrSaral did you take a crack at this?

balopat avatar Aug 31 '20 22:08 balopat

Hey @balopat , yes I am working on this! Are you on the discord channel?

MrSaral avatar Sep 01 '20 14:09 MrSaral

@MrSaral, did you mean Gitter? yeah, I tend to hangout there!

balopat avatar Sep 01 '20 17:09 balopat

This is a feature addition and doesn't require changes to the existing API (exponentiating with symbols), so marking as after-1.0.

verult avatar Mar 28 '22 21:03 verult