salfaris / zxfibonacci

Fibonacci numbers on quantum computers with Clifford+T hardware

Home Page:https://salfaris.github.io/posts/2024-08-04-quantum-fibonacci/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fibonacci in the ZX calculus

ZXFibo: A simple quantum algorithm to compute Fibonacci numbers based on Clifford+T hardware.

For correctness proof of ZXFibo using ZX-calculus, read my August 2024 blog post here: A benchmark for testing quantum computers with Clifford+T hardware.

Usage

  1. Clone this repo.
git clone https://github.com/salfaris/zxfibonacci
  1. Install dependencies from requirements: PyZX, Qiskit and matplotlib.
  2. Run the hello world script below which compares the result of classical and quantum Fibonacci algorithms:
from zxfibo import zxfibo

def fibo(n):
    """Classical Fibonacci algorithm."""
    if n == 1: return 1
    if n == 2: return 2
    return fibo(n-1) + fibo(n-2)

N = 9
print("Quantum:", end=" ")
for i in range(2, N):
    print(zxfibo(i), end=" ")
print()
print("Classical:", end=" ")
for i in range(2, N):
    print(fibo(i), end=" ")

>>> Quantum: 3 5 8 13 21 34 55 
>>> Classical: 3 5 8 13 21 34 55 

About

Fibonacci numbers on quantum computers with Clifford+T hardware

https://salfaris.github.io/posts/2024-08-04-quantum-fibonacci/


Languages

Language:Python 100.0%