← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe

Technology Innovation Institute (TII) and the Qibo community

Grover search with Qibo

SoftwareQuantum SDKLicence: Apache-2.0Version: 0.3.59.2 KB

Official source: qiboteam/qibo

Download ZIP (free)

A three-qubit Grover search with the open-source Qibo led by TII in Abu Dhabi, finding the target among 8 possibilities with about 95% probability. A tested example with a guide.

What is Qibo?

Qibo is an open-source quantum computing framework developed under the lead of the Technology Innovation Institute (TII) in Abu Dhabi. It aims to run the same Python code on a simulator (numpy and GPU-accelerated backends) or on laboratory hardware (Qibolab).

When to use it

The example in this package

grover_arama.py searches for the state 101 among 8 possibilities with Grover's algorithm on 3 qubits. After two iterations (oracle + reflection) about 950 out of 1000 measurements give the target; random guessing would give 12.5%.

Windows note

Qibo imports compiled packages such as osqp and qdldl through cvxpy. If Python exits without any error message or with an "access violation", the cause is usually an old Microsoft Visual C++ runtime on the computer (msvcp140.dll). First install Microsoft's current "Visual C++ Redistributable" package: https://aka.ms/vs/17/release/vc_redist.x64.exe

If you cannot update, older versions of these two packages also fixed the problem on our test machine:

pip install "osqp<1" "qdldl<0.1.9"

These steps are not needed on Linux and macOS.

Next steps

  1. Change the HEDEF (target) variable to search for another state.
  2. Increase the number of qubits to 4; the best number of iterations becomes round(pi/4 * sqrt(16)) = 3.

Installation and running

pip install qibo
python grover_arama.py

Tested with: qibo 0.3.5, Python 3.12 (Windows and Linux; for Windows see the note in the guide).

Official source

Links

Package contents

Licence

The example code and the guide in this package were written by the Quantum Store editors and are MIT licensed. The project it uses is subject to its own licence (Apache-2.0).


Quantum Store — https://hakanerdogan.com/en

Example code

The example shipped in the package, run and checked. Comments and printed messages are in Turkish; the code is the same in any language. Everything is in the ZIP.

grover_arama.py

"""Qibo ile 3 kübitlik Grover araması: 8 olasılık içinden |101> durumunu bul.

Çalıştırma:
    pip install qibo
    python grover_arama.py
"""

import numpy as np
from qibo import Circuit, gates, set_backend

set_backend("numpy")
np.random.seed(7)

N = 3
HEDEF = "101"


def oracle(c: Circuit) -> None:
    # Hedef durumun fazını -1 yapar: 0 olan bitleri X ile çevir, CCZ uygula, geri çevir.
    for i, bit in enumerate(HEDEF):
        if bit == "0":
            c.add(gates.X(i))
    c.add(gates.Z(N - 1).controlled_by(*range(N - 1)))
    for i, bit in enumerate(HEDEF):
        if bit == "0":
            c.add(gates.X(i))


def diffuser(c: Circuit) -> None:
    # Ortalamaya göre yansıtma: H, X, CCZ, X, H.
    c.add(gates.H(i) for i in range(N))
    c.add(gates.X(i) for i in range(N))
    c.add(gates.Z(N - 1).controlled_by(*range(N - 1)))
    c.add(gates.X(i) for i in range(N))
    c.add(gates.H(i) for i in range(N))


c = Circuit(N)
c.add(gates.H(i) for i in range(N))
# 8 eleman için en iyi tekrar sayısı: round(pi/4 * sqrt(8)) = 2
for _ in range(2):
    oracle(c)
    diffuser(c)
c.add(gates.M(*range(N)))

c.draw()
sonuc = c(nshots=1000)
frekans = dict(sorted(sonuc.frequencies().items()))
print("Ölçüm sonuçları:", frekans)

oran = frekans.get(HEDEF, 0) / 1000
print(f"|{HEDEF}> bulunma oranı: {oran:.1%} (rastgele tahmin: 12.5%)")
assert oran > 0.85, oran
print("Tamam: Grover hedefi yüksek olasılıkla buldu.")

← All packages

Share: X · LinkedIn