The arguments of Coherent(r, phi) cannot be complex

Hello,

I tried to prepare a coherent state with Coherent(complex(1,1))

However I get the error: The arguments of Coherent(r, phi) cannot be complex.
According to the documentation, it should have been possible "The gate is parameterized so that a user can specify a single complex number "
https://strawberryfields.readthedocs.io/en/stable/code/api/strawberryfields.ops.Coherent.html#strawberryfields.ops.Coherent

Am I missing something ?

Hi @EternalStudent, welcome to the forum!

I’m writing the following code and I don’t get an error. Please check that you’re using the latest version of StrawberryFields. If updating the version of Strawberry Fields doesn’t solve your problem then please post the output of sf.about().

import strawberryfields as sf
sf.ops.Coherent(complex(1,1)) 

Please let me know if this helps!

Unfortunately I still have the same problem even after updating every package (I’m using Anaconda). It’s not a big deal however since the two arguments versions of Coherent is working, so I have to convert my complex to polar form then use Coherent(r, phi).
Here is the output of sf.about()

sf.about()

Strawberry Fields: a Python library for continuous-variable quantum circuits.
Copyright 2018-2020 Xanadu Quantum Technologies Inc.

Python version: 3.9.13
Platform info: Windows-10-10.0.19042-SP0
Installation path: C:\Users\usuari\anaconda3\lib\site-packages\strawberryfields
Strawberry Fields version: 0.23.0
Numpy version: 1.21.5
Scipy version: 1.7.3
SymPy version: 1.10.1
NetworkX version: 2.8.4
The Walrus version: 0.19.0
Blackbird version: 0.4.0
XCC version: 0.2.1
TensorFlow version: None

Hi @EternalStudent, I think you may be facing some installation issues because you’re not using a virtual environment and some of your libraries are outdated.

I suggest that you create a virtual environment and install Strawberry Fields there. This cheat sheet can help you with the commands to create and activate your environment.

If you don’t want to do this then you can also create your programs on Xanadu Cloud. Here you will find examples, you can create new notebooks, and everything comes pre-installed.

Please let me know if this solves your problem!