Amazon Braket: Solving the Transverse Ising Model with VQE

Published by strangeworks (02/04/2021)

In this tutorial we show how to solve for the ground state of the Transverse Ising Model, arguably one of the most prominent, canonical quantum spin systems, using the variational quantum eigenvalue solver (VQE). The VQE algorithm belongs to the class of hybrid quantum algorithms (leveraging both classical as well as quantum compute), that are widely believed to be the working horse for the current NISQ (noisy intermediate-scale quantum) era. To validate our approach we benchmark our results with exact results as obtained from a Jordan-Wigner transformation.

We provide a step-by-step walkthrough explaining the VQE quantum algorithm and show how to build the corresponding parametrized quantum circuit ansatz using the Braket SDK, with simple modular building blocks (that can be re-used for other purposes). While we demonstrate our proof-of-concept approach using classical simulators for circuit execution, our code could in principle be run on actual quantum hardware by simply changing the definition of the device object.

Background: The Variational Quantum Eigensolver (VQE)

Quantum computers hold the promise to outperform even the most-powerful classical computers on a range of computational problems in (for example) optimization, chemistry, material science and cryptography. The canonical set of quantum algorithms (such as Shor's or Grover's quantum algorithms), however, comes with hardware requirements (such as a large number of quantum gates) that are currently not available with state-of-the-art technology. Specifically, these algorithms are typically believed to be feasible only with fault-tolerance as provided by quantum error correction. In the current noisy intermediate-sclae (NISQ) era, near-term quantum computers do not have a large enough number of physical qubits for the implementation of error correction protocols, making this canonical set of quantum algorithms unsuitable for near-term devices. Against this background, the near-term focus has widely shifted to the class of hybrid quantum algorithms that do not require quantum error correction. In these hybrid quantum algorithms are the noisy near-term quantum computers are used as co-processors only, within a larger classical optimization loop, as sketched in the schematic figure below. Here, the undesired effects of noise are suppressed by deliberately limiting the quantum circuits on the quantum processing unit (QPU) to short bursts of the calculation, and the need for long coherence times (as required for the standard set of quantum algorithms) is traded for a classical overhead due to (possibly many) measurement repetitions and (essentially error-free) classical processing.

Background: The Transverse Ising Model

While VQE is a very general approach, for concreteness we will focus on applying VQE to the one-dimensional Transverse Ising Model (TIM). The TIM belongs to a the broader class of many-body spin systems that are inherently hard to study on classical computers as the dimension of the Hilbert space grows exponentially with the number of particles in the system. With the help of a quantum computer, however, we can study these many-body systems with less overhead as the number of qubits required only grows polynomially. Even more so, the specific TIM is an integrable system and can be solved exactly. We will use these exact results as a benchmark for our approximate VQE results.

Illustration of the VQE ansatz

VQE tries to find the lowest energy configuration of a given Hamiltonian, such as that of a chemical system or some many-body spin system (as studied here). Being a variational quantum-classical algorithm, VQE uses the QPU for state preparation and measurement subroutines, and the classical computer to post-process the measurement results and update the parametrized VQE ansatz according to an update rule such as gradient descent. VQE, however, does not come without limitations. Akin to what happens in deep learning, the quality of our results will depend very much on the trial architecture of our circuit (i.e., the trial wave function) and its the expressive power. In other words, to approximate the ground state we are looking for, VQE can only operate within the bounds of the general ansatz we are using (the so-called ansatz space), by having a quantum computer prepare this very ansatz state with a parameterized gate sequence, and then have a classical optimizer iteratively update the optimal parameters. Here, we will be guided by physical intuition and symmetry arguments to make an educated guess for our variational ansatz.
In general, VQE makes use of the variational principle, by preparing a parametrized trial wavefunction Ψ(θ)\lvert \Psi ( \vec{\theta}) \rangle, and trying to find the optimal set of parameters \vec{\theta}, according to the following objective \min \langle \Psi(\vec{\theta})|H|\Psi(\vec{\theta})\rangle \geq E_0.

Here, E0E_0denotes the (true) lowest energy eigenvalue of the Hamiltonian H. Since (for sufficiently large systems with more than ∼50 qubits) classical computers are unable to efficiently prepare, store and measure the wavefunction, we use the quantum computer for this subroutine. We then use the classical computer to iteratively update the parameters using some optimization algorithm.

VQE Simulation on a Local Simulator

We are now ready to run some VQE simulation experiments. First of all, you can play and experiment yourself with the number of qubits 𝑁. Secondly, you may also experiment with the classical optimizer. Since we are using an off-the-shelf scipy minimizer, you can simply swap between different optimizers by setting the method parameter accordingly, as done above in the line result = minimize(..., method='SLSQP'). Some popular options readily available within this library include Nelder-Mead, BFGS and COBYLA. As a precautionary warning, note that the classical optimization step may get stuck in a local optimum, rather than finding the global minimum for our parametrized VQE ansatz wavefunction. To address this issue, we run several optimization loops, starting from different random parameter seeds. You can set the number of these optimization loops using the n_initial parameter, as shown below. While this brute-force approach does not provide any guarantee to find the global optimum, from a pragmatic point of view at least it does increase the odds of finding an acceptable solution, at the expense of potentially having to run many more circuits on the QPU. For a more detailed and sophisticated discussion of classical optimization of VQE we refer to this.
# set up the problem SHOTS = 1000 N = 10 # number of qubits n_initial = 30 # number of random seeds to explore optimization landscape verbose = False # control amount of print output # set counters CYCLE = 0 # set up Ising matrix with nearest neighbour interactions and PBC J = get_ising_interactions(N) # set options for classical optimization if verbose: options = {'disp': True} else: options = {} # kick off training start = time.time() # parameter scan stepsize = 0.5 xvalues = np.arange(0, 2+stepsize, stepsize) results = [] results_site = [] for bb in xvalues: b_field = bb print('Strength of magnetic field:', b_field) energy_min = train(b_field, options=options, n_qubits=N, n_shots=SHOTS, n_initial=n_initial, s3_folder=s3_folder, verbose=verbose) results.append(energy_min) results_site.append(energy_min/N) # reset counters CYCLE = 0 end = time.time() # print execution time print('Code execution time [sec]:', end - start) # print optimized results print('Optimal energies:', results) print('Optimal energies (per site):', results_site)

Benchmarking our VQE Ansatz with Exact Results

As detailed in the seminal paper, the paradigmatic TIM can be solved with the help of a (highly non-local) Jordan-Wigner transformation that expresses the spin (qubit) variables as fermionic variables, and leading to a sum of local quadratic terms containing fermionic creation and annihilation operators. The resulting Hamiltonian is mathematically identical to that of a superconductor in the mean field Bogoliubov deGennes formalism and can be completely understood in the same standard way. Specifically, the exact excitation spectrum and eigenvalues can be determined by Fourier transforming into momentum space and diagonalizing the Hamiltonian. Here, we just use the known results to recover the exact ground-state energy with the helper function defined below, and refer the interested reader to the broad set of literature on the TIM for further details. The original paper is available online here.