Hello! I am doing some experiments related to Quantum SVMs of 3 types:
I have implemented the first one QK-SVM on my own (with help of some resources). I would greatly appreciate some help for implementation of the other two types (QV-SVM & QVK-SVM)
I am also attaching circuit images for reference.
1)Quantum Kernel SVM
2)Quantum Variational SVM
3)Quantum Variational Kernel SVM
Hereβs the code for the QKSVM
n_qubits= 8
dev = qml.device("lightning.qubit",wires = n_qubits)
@qml.qnode(dev)
def qksvm_kernel_cirq(a,b):
qml.AngleEmbedding(a,wires = range(n_qubits))
qml.adjoint(qml.AngleEmbedding(b,wires = range(n_qubits)))
return qml.probs(wires = range(n_qubits))
def quantum_kernel_pca(A,B):
return np.array([[qksvm_kernel_cirq(a,b)[0] for b in B] for a in A])
svm = SVC(kernel = quantum_kernel_pca).fit(xs_tr, y_tr)
from sklearn.metrics import accuracy_score
print(accuracy_score(svm.predict(xs_test), y_test))
This is the accuracy
0.9615384615384616
And, finally, make sure to include the versions of your packages. Specifically, show us the output of qml.about()
.
Name: PennyLane
Version: 0.36.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /usr/local/lib/python3.10/dist-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane_Lightning
Platform info: Linux-6.1.58+-x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 1.25.2
Scipy version: 1.11.4
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.36.0)
- default.clifford (PennyLane-0.36.0)
- default.gaussian (PennyLane-0.36.0)
- default.mixed (PennyLane-0.36.0)
- default.qubit (PennyLane-0.36.0)
- default.qubit.autograd (PennyLane-0.36.0)
- default.qubit.jax (PennyLane-0.36.0)
- default.qubit.legacy (PennyLane-0.36.0)
- default.qubit.tf (PennyLane-0.36.0)
- default.qubit.torch (PennyLane-0.36.0)
- default.qutrit (PennyLane-0.36.0)
- default.qutrit.mixed (PennyLane-0.36.0)
- null.qubit (PennyLane-0.36.0)