Qiskit#

QLauncher is compatible with qiskit backends and features many qiskit-based algorithms.

Let’s start by defining a problem to be solved, we will use Exact Cover in this tutorial.

from qlauncher.problems import EC

pr = EC.from_preset("default")
pr.visualize()
../_images/ece43bad8d05fe43cfe5b41dfaf5ee4efb5f9cc837d7af16f8088da9feda0516.png

Quantum Approximate Optimization Algorithm#

Algorithm we’re going to use is Quantum Approximate Optimization Algorithm (QAOA), let’s initialize it!

from qlauncher.routines.qiskit import QAOA

alg = QAOA()

Now we need to define the backend our algorithm will run on, you can use a local simulator or a real quantum computer if you have access to one, for now let’s stick to the simulator.

from qlauncher.routines.qiskit import QiskitBackend

backend = QiskitBackend('local_simulator')

Now we can use QLauncher to launch QAOA on the selected backend.

from qlauncher.launcher import QLauncher

launcher = QLauncher(pr, alg, backend)
result = launcher.run(onehot="exact")
result
Result(bitstring=101010, energy=2.1142578125)

Be careful! QAOA returns reversed bitstring!

The results correspond to the following matching:

pr.visualize(result.best_bitstring[::-1])
../_images/4653818f768d6bbb74a420b33a51a8f81d0e8a2948cee2406594bd78c51e8211.png

as you can see QAOA solved this problem with flying colors.

QLauncher allows you to easily test different combinations of problems, algorithms and backend simply by swapping out the arguments, let’s try out the Max Cut Problem:

from qlauncher.problems import MaxCut

pr = MaxCut.from_preset("default")
pr.visualize()
../_images/7b983cf69583327126bb6746df23347f419b0d4b5919d09fe544780583fdb890.png
launcher = QLauncher(pr, alg, backend)
result = launcher.run()
pr.visualize(result.best_bitstring)
../_images/ca6042cf2d621a177021276282c806a40b186b8f058a2b7e5aaee5b03a23ea28.png

AQT Backend#

If you have access to one of the AQT quantum computers you can use it as a backend instead of a qiskit simulator. To do that you need to import AQTBackend and pass ‘device’ as a name together with your access token at object initialization.

Alternatively you can pass a path to the .env file containing you token.

There rest looks identically to using a regular qiskit backend, you can use all the problems and compatible algorithms.