1
$\begingroup$

I implemented a simple Neural Net with Pennylane and Qiskit for classifying two half moons: notebook for two half moons (GitHub). It works somehow (not overwhelmingly by any means):

enter image description here

I tried running the program on a public quantum device (IBM) and found very quickly that it would take months, not days, to complete the training. For this reason I built a much simpler net (my hope is that one qubit is enough), which is supposed to solve the classification task: notebook for linear classification (GitHub). It should divide the classes using a straight line:

enter image description here

While the full notebook (a very small one) can be found on the above linked GitHub page, the following snipped is relevant:

# Convert quantum layer to keras
n_layers = 4
weight_shapes = {"weights": (n_layers, n_qubits)}
qlayer = qml.qnn.KerasLayer(qnode, weight_shapes, output_dim=n_qubits)

# Define classical layers
clayer_1 = tf.keras.layers.Dense(1)
clayer_2 = tf.keras.layers.Dense(1, activation="sigmoid")

model = tf.keras.models.Sequential([clayer_1, qlayer, clayer_2])
opt = tf.keras.optimizers.Adam(learning_rate=0.1)
model.compile(optimizer=opt, loss="binary_crossentropy", metrics=["accuracy"])
fitting = model.fit(x, y_hot, epochs=4, batch_size=5, validation_split=0.25, verbose=2)

Possibly it is a very simple error, which causes the net is recognizing all input as one and the same class:

enter image description here

I would be very grateful for any hint that pushes me towards the proper direction.

$\endgroup$
0
$\begingroup$

This is Catalina from Xanadu.

If you run this tutorial does it work for you? It only uses 2 qubits and uses the moons dataset too.

If the tutorial doesn't work then it's probably not a problem in your code but in the connection to the backend. Have you tried different IBM devices? Their errors and waiting times vary a lot so trying different ones can help.

$\endgroup$
1
  • $\begingroup$ Yes - I ran this model multiple times on different quantum computers (IBM devices). Even after several days he was processing epoch 1. I do not have connection problems with the backend, because I could see that the quantum device successfully performed increasingly many of my jobs. The devices have a long queue time, currently of the order of 15 minutes per circuit i.e. per datapoint. Thats why I am really try to simplyfy the classification problem using a much simpler net with less data points. $\endgroup$ Nov 17 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.