Thanks for confirming @EmmanSSSS
I can actually replicate the issue by using default.qubit
together with diff_method='parameter-shift'
. This means that the issue isn’t really due to the IBM device, but instead to the differentiation method. Note that for quantum hardware devices we need to use hardware-compatible differentiation methods such as ‘parameter-shift’.
The good news is that it’s easy to test a solution. You can see a solution for a similar problem in this post.
The solution consists in identifying whether you have a batch dimension and adjusting your embedding accordingly. Below I copy the changes I made to test the solution for your problem. The rest of the code stays the same.
dev = qml.device('default.qubit', wires=n_qubits)
n_inputs = 6
#define circuit
@qml.qnode(dev, diff_method='parameter-shift')
def circuit(inputs, weights):
# These print statements help me check that the size for the inputs matches my embedding template
print('inputs.shape: ',inputs.shape)
print('inputs[0].shape: ',inputs[0].shape)
# Encode your inputs
if len(inputs.shape) > 1: # use this if you have a batch dimension
for i in range(n_inputs):
qml.AngleEmbedding(features=inputs[0], wires=range(n_qubits), rotation='Y') # the key is in this line
else: # use this if you don't have a batch dimension
for i in range(n_inputs):
qml.AngleEmbedding(features=inputs, wires=range(n_qubits), rotation='Y')
Let me know if this solution works for you when using the IBM device.
Note:
If you get an error like the one below, you’ll need to change tf.keras.backend.set_floatx('float32')
to tf.keras.backend.set_floatx('float64')
InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a float tensor but is a double tensor [Op:Mul] name:
Let me know if this helps!