👋 Welcome to Qiboml, the quantum machine learning package of the Qibo ecosystem!
🎯 Our goal is to integrate Qibo within the most commonly used machine learning frameworks, allowing the definition and usage of quantum or hybrid classical-quantum models keeping the same high-level language proposed by the most used libraries (Pytorch, Tensorflow).
📖 The Qiboml documentation can be found in our organization webpage.
You can quickly build a QML model using one of the currently supported interfaces. For instance,
to train a VQE to find the ground state of an Hamiltonian
from qiboml.models.ansatze import hardware_efficient
from qiboml.models.decoding import Expectation
nqubits = 2
circuit = hardware_efficient(nqubits)
# By default Expectation sets Z_0 + Z_1 + ... + Z_n as observable,
# any Hamiltonian can be used though
decoding = Expectation(nqubits)
# using pytorch
import torch
import qiboml.interfaces.pytorch as pt
pt_model = pt.QuantumModel(circuit_structure=[circuit,], decoding=decoding)
optimizer = torch.optim.Adam(pt_model.parameters(), lr=0.05)
for iteration in range(100):
optimizer.zero_grad()
cost = pt_model()
cost.backward()
optimizer.step()
# using keras
import keras
import tensorflow as tf
import qiboml.interfaces.keras as ks
tf.keras.backend.set_floatx('float64') # set the dtype to float64, which is qibo's default
ks_model = ks.QuantumModel(circuit_structure=[circuit,], decoding=decoding)
optimizer = keras.optimizers.Adam(learning_rate=0.05)
for iteration in range(100):
with tf.GradientTape() as tape:
cost = ks_model()
gradients = tape.gradient(
cost, ks_model.trainable_variables
)
optimizer.apply_gradients(zip(gradients, ks_model.trainable_variables))If you use the package please refer to the documentation for citation instructions.
To get in touch with the community and the developers, consider joining the Qibo workspace on Matrix:
If you have a question about the project, please contact us with 📫.
