I am trying to implement and run the variational circuit from the paper “Quantum Machine Learning in Feature Hilbert spaces” and apply to Iris dataset. After following the tutorial on the strawberryfields demos on variational I am getting the error:
SympifyError: SympifyError: <tf.Tensor: shape=(3,), dtype=float32, numpy=array([1.0025, 1.0025, 1.0025], dtype=float32)>
when I run with engine.run() whilst testing before applying on the dataset. Here is my code:
import strawberryfields as sf
from strawberryfields.ops import *
import tensorflow as tf
import numpy as np
from sklearn.datasets import load_iris
# hyper-parameters
batch_size = 3
eng = sf.Engine(backend="tf", backend_options={"cutoff_dim": 5, "batch_size": batch_size})
circuit = sf.Program(2)
# defining variables
theta1 = tf.Variable([0.1] * batch_size)
theta2 = tf.Variable([0.1] * batch_size)
theta3 = tf.Variable([0.1] * batch_size)
theta4 = tf.Variable([0.1] * batch_size)
theta5 = tf.Variable([0.1] * batch_size)
theta6 = tf.Variable([0.1] * batch_size)
theta7 = tf.Variable([0.1] * batch_size)
theta8 = tf.Variable([0.1] * batch_size)
x1,x2 = circuit.params("x1", "x2")
_x1 = tf.zeros([batch_size], dtype=tf.float32)
_x2 = tf.zeros([batch_size], dtype=tf.float32)
# construct the circuit
with circuit.context as q:
Squeezed(sq, x1) | q[0]
Squeezed(sq, x2) | q[1]
BSgate(theta1, theta2) | (q[0], q[1])
Dgate(theta3) | q[0]
Dgate(theta4) | q[1]
Pgate(theta5) | q[0]
Pgate(theta6) | q[1]
Vgate(theta7) | q[0]
Vgate(theta8) | q[1]
if eng.run_progs:
eng.reset()
# results = eng.run(circuit,run_options={"eval": False})
results = eng.run(circuit, args={"x1": _x1, "x2": _x2})