Quantum Machine Learning
Quantum machine learning is the research area where two strands of AI and Quantum Computing act as complements of one another. Every step forward in machine learning is an opportunity of improvement in Quantum Computing. In short, the goal is to build intelligent systems that learn from data and make decisions. Machine learning enables scaling up quantum data processing. Concurrently, the machine learning community is developing faster and more efficient methods and techniques in data science and analysis. Machine intelligence lowers the cost of goods and services that rely on prediction. Prediction analytics is used in many areas such as transportation, agriculture, healthcare, energy manufacturing, and retail. Specifically, quantum machine learning is promising as it is building intelligent systems and quantum computers.
Quantum machine learning is used in many application areas. For example, quantum chemistry is interested in optimizing high-dimensional and difficult cost functions. Quantum computers are used to tackle computationally challenging problems with methods like the variational quantum eigen solvers . New algorithms such as quantum approximate optimization algorithms (QAOA), variational quantum eigen solvers (VQE), quantum classifiers, quantum generative adversarial networks (QGANs), and quantum neural networks (QNN) are evolving.
Variational quantum eigen solver
Finding the eigenvalues of certain operators is a challenging problem. The quantum phase estimation algorithm can be used to find the eigenvalue of a given eigenvector. We optimize a variational circuit in lowering the squared energy expectation of a user-defined Hamiltonian. The Hamiltonian is expressed as a sum of two Pauli operators.
Prerequisites:
You need to set up Python3.5 to run the code samples below. You can download from this link.
Code sample- quantum_eigen_solver.py:
iimport pennylane as qml
from pennylane import numpy as np
from pennylane.optimize import GradientDescentOptimizer
dev = qml.device('default.qubit', wires=2)
def GetAnsatz():
qml.Rot(0.3, 1.8, 5.4, wires=1)
qml.RX(-0.5, wires=0)
qml.RY( 0.5, wires=1)
qml.CNOT(wires=[0, 1])
@qml.qnode(dev)
def getCircuitX():
GetAnsatz()
return qml.expval.PauliX(1)
@qml.qnode(dev)
def getCircuitY():
GetAnsatz()
return qml.expval.PauliY(1)
def getCost(var):
iimport pennylane as qml
from pennylane import numpy as np
from pennylane.optimize import GradientDescentOptimizer
dev = qml.device('default.qubit', wires=2)
def GetAnsatz():
qml.Rot(0.3, 1.8, 5.4, wires=1)
qml.RX(-0.5, wires=0)
qml.RY( 0.5, wires=1)
qml.CNOT(wires=[0, 1])
@qml.qnode(dev)
def getCircuitX():
GetAnsatz()
return qml.expval.PauliX(1)
@qml.qnode(dev)
def getCircuitY():
GetAnsatz()
return qml.expval.PauliY(1)
def getCost(var):
expX = getCircuitX()
expY = getCircuitY()
return (var[0] * expX + var[1] * expY) ** 2
optimizer = GradientDescentOptimizer(0.5)
variables = [0.3, 2.5]
variables_gd = [variables]
for i in range(20):
variables = optimizer.step(getCost, variables)
variables_gd.append(variables)
print('Cost - step {:5d}: {: .7f} | Variable values: [{: .5f},{: .5f}]'
.format(i+1, getCost(variables), variables[0], variables[1]) )
Instructions for Running the Code
pip install pennylane
python quantum_eigen_solver.py
Output
This article is part of the Quantum Machine Learning series. You can check the other articles:
]]>