# Julia SoC '19 : Quantum Algorithms for Differential Equations

"$VERSION"

Hi. I am Divyanshu Gupta. I am one of the participants in Julia's Season of Contribution, 2019.

## An Introduction

Over the next couple of months, my focus will be on implementing quantum algorithms for solving differential equations. These include algorithms for first-order linear and non-linear (of quadratic nature) differential equations, and partial differential equations such as the wave equation and heat equation.

I am using Yao.jl, a quantum computer simulator that allows you to design quantum algorithms in Julia.

QuDiffEq.jl will serve as the the repository for the aforementioned algorithms.

## A Quantum Algorithm for Linear Differential Equation

### Background

A Quantum algorithm can heavily cut down on the time is takes to solve a specific problem, in comparison to its classical counterpart. Though it may seem appealing in theory, a physically feasible algorithm is difficult to come by. There are many caveats to keep in mind - there is no easy way to input data or read the output, and there are questions about how effectively evolution of states can be brought about (Hamiltonian evolution).

An earlier attempt at solving linear differential equations has been presented in Berry's paper

The algorithm

*Note: The output from these algorithms is a superposition of computational basis with resultant vector's component as the probability amplitude.So we can't just read out whatever values the registers have for the final answer. In addition, inputing data requires what is called a QRAM. I shall be looking past all of this during my development.*

### Mathematical details

The algorithm solves problems of the form

This can be Taylor expanded up to the

We need to prescribe a way to express the vectors

The task at hand is to simulate an operation on the encoded vector states to collectively obtain the above. We have to consider two cases:

**1.is unitary**. In addition to the vector state register, there are two ancillary registers of 1 qubit and

The input to the circuit is an all zero ancilla and work register

Essentially, the first (size 1) register controls the multiplication of

**2.is non-unitary. **

The quantum circuit consists of three ancillary register:

The second register and the third register together control the multiplication of

### Usage and Example

Constructing an arbitrary linear differential equation problem:

using QuDiffEq using OrdinaryDiffEq, Test N = 1 #size of the work register k = 3 #order of approximation siz = 1<<N b = (rand(ComplexF64, siz)) u0 = (rand(ComplexF64, siz)) #initial condition M = rand(ComplexF64,siz,siz) tspan = (0.0, 0.4) qprob = QuLDEProblem(M, b, u0, tspan) #problem is defined as a QuLDEProblem

The algorithm is named `QuLDE()`

. It takes the argument

to build a circuit of the

For linear differential equations:

solve(::QuLDEProblem,::QuLDE)

For non-linear differential equations through linearisation (covered below):

solve(::ODEProblem,::QuLDE)

out = solve(qprob, QuLDE(k))

To compare the result, the problem is solved using `Tsit5()`

from *OrdinaryDiffEq.jl*

f(u,p,t) = M*u + b; prob = ODEProblem(f, u0, tspan) sol = solve(prob, Tsit5()) s = sol.u[end] isapprox.(s,out, atol = 0.05) |> all

We shall use this algorithm to solve a system of non-linear equation.

We proceed by linearising the equations about the point

The differential equation to be solved will be of the form

where

using QuDiffEq using OrdinaryDiffEq, Test """ Linearizing non linear ODE and solving it using QuLDE du/dt = f u0 -> inital condition for the ode Δu -> difference for fixed point h -> time step k -> order of Taylor Expansion in QuLDE circuit Equation input to QuLDE circuit : d(Δu)/dt = J * Δu + b """ # Arbitary non-linear equation function fo(du,u,p,t) du[1] = -2*u[2]^2*u[1] du[2] = 3*u[1]^(1.5) - 0.1*u[2] end u0 = [0.2,0.1] h = 0.1 k = 3 tspan = (0.0,0.8) prob = ODEProblem(fo,u0,tspan) qsol = solve(prob,QuLDE(k),dt = h) sol = solve(prob,Tsit5(),dt = h,adaptive = false) v = transpose(hcat(sol.u...)) isapprox.(v,qsol, atol = 1e-3) |> all

## References

- High-order quantum algorithm for solving linear differential equations: https://arxiv.org/abs/1010.2745v2
- Quantum algorithm for solving linear systems of equations: https://arxiv.org/abs/0811.3171
- A Quantum Algorithm for Solving Linear Differential Equations: Theory and Experiment: arxiv.org/abs/1807.04553
- Simulating Hamiltonian dynamics with a truncated Taylor series: https://arxiv.org/abs/1412.4687