Skip to content

till-m/YaoML.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YaoML

Quantum machine learning in Julia using Yao.jl

This package aims to implement popular QML algorithms such as QSVMs ("Quantum Support Vector Machines") and VQCs ("Variational Quantum Circuit", also known as "Quantum Neural Network").

Usage

QSVM

The QSVM uses a circuit architecture first described in [1]. alt text

using YaoML

# Load the built-in example dataset
X, y = ad_hoc_data(40, 0.5, seed=42)

# Partition into train/test sets 
train, test = partition(eachindex(y), 0.75, seed=42+42, shuffle=true)

# Select the feature map U(x)
feature_map = FeatureMaps.zz_feature_map

# Train the model
model = qsvmtrain(feature_map, X[train, :], y[train])

# Use the trained model to predict on new values
ŷ, decision_values = qsvmpredict(model, X[test,:])

VQC

import Yao
using YaoML

# Generate the example dataset
X, y = ad_hoc_data(40, 0.5, seed=42)

# Partition into train/test sets 
train, test = partition(eachindex(y), 0.75, seed=42+42, shuffle=true)

# Build the circuit
feature_map = FeatureMaps.zz_feature_map
variational_map = FeatureMaps.two_local_demo

# First argument of `circuit` is data, second argument will be optimized over
circuit = (x, theta) -> Yao.chain(feature_map(x), variational_map(theta))

# Initialize the VQC
vqc = VQC(circuit, [0 for i=1:16], 0.01)

# train
vqctrain!(vqc, X[train, :], y[train])

# predict
ŷ = vqcpredict(vqc, X[test,:])

References

[1] Havlíček, V., Córcoles, A.D., Temme, K. et al.; Supervised learning with quantum-enhanced feature spaces; Nature 567, 209–212 (2019). https://doi.org/10.1038/s41586-019-0980-2

About

Quantum machine learning in Julia using Yao.jl

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages