Hi,
I am currently researching on the topic of image processing in quantum computers. I recently did a project using pennylane (variational classifier) to classify biomedical images. However, I worked only with 2 and 4 qubit circuits and am wanting to try with a larger number of qubits. I am having some trouble understanding how I can go about designing a circuit of this size. Can I please get some help ?
Thank you in advance
hey,
machine learning either classical or quantum depends significantly on your data preparation and how you configure your cost function. because of the gpus and their incredible speed less attention is given to these two points and this is actually what happens here in the quantum realm. by far, the amplitude encoding scheme can encode a single 28*28 image with only 10 qubits and there would be more room for other features and you can you the circuit centric classifier by prof schuld for your problem.
another way is to use the universal qubit classifier but it would be the deepest network ever. Or, you can try out this paper.
if you are more precise i think i can help you more
good luck
I figured it out. Thank you for your reply
Hi @vijpandaturtle! To help create your variational circuit ansatz for a larger number of qubits, you could take a look at the templates provided by PennyLane: Templates — PennyLane 0.27.0 documentation
One that is quite useful is the StronglyEntanglingLayers
. This template creates layers like the following:
For example, for a 10 qubit circuit, with 3 strongly entangling layers:
import pennylane as qml
from pennylane.templates.layers import StronglyEntanglingLayers
dev = qml.device('default.qubit', wires=10)
@qml.qnode(dev)
def circuit(weights):
StronglyEntanglingLayers(weights, wires=list(range(10)))
return qml.expval(qml.PauliZ(0))
init_weights = strong_ent_layers_normal(n_layers=3, n_wires=10)
circuit(init_weights)
Thank you so much @josh !
@josh trying to build this circuit
@qml.qnode(dev)
def circuit(inputs, weights):
AngleEmbedding(inputs, list(range(9)))
RandomLayers(weights=weights, wires=list(range(9)))
return qml.expval(qml.PauliZ(0))
init_pars = random_layers_uniform(n_layers=3, n_wires=num_qubits, seed=2)
however when i run this command to test
print(circuit([1,2,3,4,5,6,7,8,9], init_pars))
i get the following error
“TypeError: RX: Real scalar parameter expected, got <class ‘numpy.ndarray’>.”
what am i doing wrong ?
Hi @vijpandaturtle, the example you posted works for me. I use the following QNode:
import pennylane as qml
num_qubits = 9
dev = qml.device("default.qubit", wires=num_qubits )
@qml.qnode(dev)
def circuit(inputs, weights):
qml.templates.AngleEmbedding(inputs, list(range(9)))
qml.templatesRandomLayers(weights=weights, wires=list(range(9)))
return qml.expval(qml.PauliZ(0))
init_pars = random_layers_uniform(n_layers=3, n_wires=num_qubits, seed=2)
Running this circuit,
>>> print(circuit([1,2,3,4,5,6,7,8,9], init_pars))
0.54030230586814
Can you post the output of qml.about()
?
@josh I ran qml.about() and realized that i have pennylane 0.5.0 installed. simply running an upgrade fixed my issue. thanks for pointing me in the right direction !