Example for function_fitting not working

Hi

I have installed and uninstalled for Python, PennyLane, and StraweberryFields these few days just wish to test two examples i.e., pennylane_quantum_neural_net.py and function_fitting.py. The latter always come ut error “TypeError: backend must be a string or a BaseBackend instance.”

I have tried to search advice or solutions but cannot make it done. This half-day I have corrected the 8 *.py codes according to " [WIP] Upgrades the TensorFlow backend to TF2.0 #323" (https://github.com/XanaduAI/strawberryfields/pull/323) but it still come errors too.

Below is my setting for installing strawberryfields, kindly point out if there is any mistake that causing the function_fitting.py not working.

Thank you very much.
Chien

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

Python version: 3.7.6
Platform info: Windows-10-10.0.16299-SP0
Installation path: C:\Users<user>\AppData\Roaming\Python\Python37\site-packages\strawberryfields
Strawberry Fields version: 0.13.0
Numpy version: 1.18.3
Scipy version: 1.4.1
SymPy version: 1.5
NetworkX version: 2.4
The Walrus version: 0.12.0
Blackbird version: 0.2.4
TensorFlow version: 2.0.0

2020-04-22 15:15:05.654882: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiTraceback (most recent call last):

File “function_fitting.py”, line 121, in
eng, q = sf.Engine(1)
File “C:\Users<user>\AppData\Roaming\Python\Python37\site-packages\strawberryfields\engine.py”, line 328, in init
super().init(backend, backend_options)
File “C:\Users<user>\AppData\Roaming\Python\Python37\site-packages\strawberryfields\engine.py”, line 67, in init
raise TypeError(“backend must be a string or a BaseBackend instance.”)
TypeError: backend must be a string or a BaseBackend instance.

Hi @SuFong_Chien! Can I ask where you are getting the function_fitting.py file from?

Hi

From “https://github.com/XanaduAI/quantum-neural-networks”.

Thanks
Chien

Thanks @SuFong_Chien! That research repository was created last year, and therefore requires an older version of Strawberry Fields.

You can install the old version of Strawberry Fields using pip:

pip install strawberryfields==0.10.0

Let me know if that works!

Dear Josh

Thank you very much for your solution. I will try once I have time. In fact, this problem wasted me for at least two days to search for any possible solutions from the web.

Installing and uninstalling for Python, Anaconda, strawberry and etc really caused me very tired these few days. :slightly_smiling_face:
I am fortunate that I still can make pennylane_quantum_neural_net.py run and let me feel the quantum algorithm.

Honestly, I would prefer using the new version to learn the quantum algorithm. I believe the codes for function_fitting.py needs to do a minor correction, it will work too. If you can give some suggestions about where to do the correction, I shall try then.

Appreciate.

Chien

Hi @SuFong_Chien, sorry to hear that you have had some trouble with getting the scripts working.

As @josh mentioned, we currently require an older version of Strawberry Fields and TensorFlow. You can install the right versions using:

pip install strawberryfields==0.10
pip install tensorflow==1.3

Note that we require Python 3.5 or 3.6 for these scripts to work (which can be checked using python --version).

I also wanted to add that we’re about to release a new version of Strawberry Fields that supports the latest TensorFlow (TF2.0+), based on the PR that you linked: https://github.com/XanaduAI/strawberryfields/pull/323. Once this is out, we’ll be able to update the scripts in https://github.com/XanaduAI/quantum-neural-networks so that getting the right version should be easy!

Hi Tom Bromley

Thanks for your suggestion. Look forward to the new version.

Chien