top of page
Writer's picturemansour ansari

How to run an algorithm on IBM Quantum computer - the steps

Updated: Feb 21, 2022



I have been digging into IBM Quantum Computer documentation and tutorials. There is a lot to learn there. In my second month of studying the IBM portal, there is a lot to learn. Currently working with a free account on IBM Quantum Cloud services.

Working with IBM code is a joy. It is easy to follow, and the tutorials are excellent learning tools.


This post covers the algorithm calls, setup, compile and run process for qiskit coding. The algorithm setup and run is automated and easy to insert different algorithms to perform different tasks ranging from "isin Hamiltonian" on chemistry or run optimization on financial market. Many popular and useful algorithms supported on their platform, make it easy to run algorithms without learning the intricate construct of algorithms. So, these algorithms grouped based on their respective tasks performing. One such algorithm is the "Minimum Eigensolvers." In numerical analysis, one of the most important problems is designing efficient and stable algorithms for finding the eigenvalues of a matrix.


For instance Minimum Eigensolvers to find the smallest eigen value of an operator, for example ground state energy of a chemistry Hamiltonian or a solution to an optimization problem when expressed as an Ising Hamiltonian. Ising hamiltonian in this instance is a mathematical model of ferromagnetism in statistical mechanics. The model consists of discrete variables that represent magnetic dipole moments of atomic "spins" that can be in one of two states (+1 or −1)


There are other Linear Solvers for linear systems of equations problems and Amplitude Estimators for value estimation that can be used say in financial applications. I have to do a post on each at some point as I learn more and dig into these algorithms.


With that said, here is an example to construct a VQE instance on IBM Quantum Simulator and run on the hard device. With VQE, the Variational Quantum Eigensolver, it takes a trial wavefunction (A wave function in quantum physics is a mathematical description of the quantum state of an isolated quantum system,) in the form of a QuantumCircuit and a classical optimizer among other things. The entire source code with links to other resources available on IBM qiskit portal.


Here are the steps:


Setup:

Note: This is just the skeleton of the code.


import some stuff first:

from qiskit.algorithms import VQE

from qiskit.algorithms.optimizers import SLSQP

from qiskit.circuit.library import TwoLocal

// from qiskit import whatever needed for the algorithm


// Setup the number of qubits, optimizer

num_qubits = 2


Setup the optimizer and simulator


ansatz = TwoLocal (num_qubits, 'ry', 'cz')

opt = SLSQP (maxiter=1000)

vqe = VQE(ansatz, optimizer=opt)


// Draw

ansatz.draw()

from qiskit import Aer

Setup the backend

backend = Aer.get_backend('aer_simulator_statevector')


Run after you add your code!. It is pretty simple to setup the environment. I am using the browser-based access, therefore I am not installing anything on my desktop PC although I have all necessary files for local processing with the IBM Code samples. I will try these on local host and post again.


 
  • Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). Numerical analysis finds application in all fields of engineering and the physical sciences, and in the 21st century also the life and social sciences, medicine, business and even the arts. Current growth in computing power has enabled the use of more complex numerical analysis, providing detailed and realistic mathematical models in science and engineering.



See the whole document here.


Ising Model:


See the document here.


34 views

Bình luận


bottom of page