> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qbraid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

<div style={{ display: "flex", justifyContent: "center", alignItems: "center" }}>
  <img src="https://mintcdn.com/qbraidco/rzZT9djB25T3PqZG/qbraid-algorithms/_static/algos_banner.png?fit=max&auto=format&n=rzZT9djB25T3PqZG&q=85&s=acb486624af012b4b4b2b8c19584ceb1" alt="qBraid-ALGOS" style={{ width: "200", height: "auto", margin: "0" }} width="1805" height="340" data-path="qbraid-algorithms/_static/algos_banner.png" />
</div>

<div style={{ textAlign: "center", marginTop: "-8px" }}>
  *Quantum Algorithms Library.*
</div>

Python package for building, simulating, and benchmarking hybrid quantum-classical algorithms.

## Installation

qbraid-algorithms requires Python 3.11 or greater, and can be installed with pip as follows:

```bash theme={null}
pip install qbraid-algorithms
```

### Install from source

You can also install from source by cloning this repository and running a pip install command
in the root directory of the repository:

```bash theme={null}
git clone https://github.com/qBraid/qbraid-algorithms.git
cd qbraid-algorithms
pip3 install .
```

## Check version

You can view the version of qbraid-algorithms you have installed within a Python shell as follows:

```python theme={null}
import qbraid_algorithms

qbraid_algorithms.__version__
```

## Supported Algorithms

<Tabs>
  <Tab title="Bernstein-Vazirani">
    <CodeGroup>
      ```python Usage theme={null}
      from qbraid_algorithms import bernstein_vazirani
      secret_key = '01001'
      algo = bernstein_vazirani.load_program(secret_key)
      print(algo)
      ```

      ```output Output theme={null}
       OPENQASM 3.0;
       include "stdgates.inc";
       def bernvaz(qubit[5] q, qubit[1] ancilla) {
         int[32] s = 18;
         int[16] n = 5;
         for int i in [0:n - 1] {
           h q[i];
         }
         x ancilla[0];
         h ancilla[0];
         for int i in [0:n - 1] {
           if (s >> i & 1) {
             cx q[i], ancilla[0];
           }
         }
         for int i in [0:n - 1] {
           h q[i];
         }
       }
       qubit[5] q;
       qubit[1] ancilla;
       bit[5] b;
       bernvaz(q, ancilla);
       b = measure q;
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Quantum Fourier Transform (QFT)">
    <CodeGroup>
      ```python Usage theme={null}
      from qbraid_algorithms import qft
      algo = qft.load_program(4)
      print(algo)
      ```

      ```output Output theme={null}
       OPENQASM 3.0;
       include "stdgates.inc";
       def qft(qubit[4] q) {
         int n = 4;
         for int[16] i in [0:n - 1] {
           h q[i];
           for int[16] j in [i + 1:n - 1] {
             int[16] k = j - i;
             cp(2 * pi / (1 << k + 1)) q[j], q[i];
           }
         }
         for int[16] i in [0:(n >> 1) - 1] {
           swap q[i], q[n - i - 1];
         }
       }
       qubit[4] q;
       bit[4] b;
       qft(q);
       b = measure q;
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Inverse QFT">
    <CodeGroup>
      ```python Usage theme={null}
      from qbraid_algorithms import iqft
      algo = iqft.load_program(4)
      print(algo)
      ```

      ```output Output theme={null}
       OPENQASM 3.0;
       include "stdgates.inc";
       def iqft(qubit[4] q) {
         int n = 4;
         for int[16] i in [0:n - 1] {
           int[16] target = n - i - 1;
           for int[16] j in [0:n - target - 2] {
             int[16] control = n - j - 1;
             int[16] k = control - target;
             cp(-2 * pi / (1 << k + 1)) q[control], q[target];
           }
           h q[target];
         }
         for int[16] i in [0:(n >> 1) - 1] {
           swap q[i], q[n - i - 1];
         }
       }
       qubit[4] q;
       bit[4] b;
       iqft(q);
       b = measure q;
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Quantum Phase Estimation">
    <CodeGroup>
      ```python Usage theme={null}
      from qbraid_algorithms import qpe

      """
      Path to a qasm file defining the unitary gate U.

      Eg. -
      OPENQASM 3.0;
      include "stdgates.inc";

      gate custom_t q {
          p(pi/4) q;
      }
      """
      unitary_filepath = "gate.qasm"

      """
      Path to a qasm file defining the eigenstate preparation gate.

      Eg. -
      OPENQASM 3.0;
      include "stdgates.inc";

      gate prep q {
          x q;
      }
      """
      eigen_state_filepath = "eigen_state.qasm"

      algo = qpe.load_program(num_qubits = 4, unitary_filepath=unitary_filepath,
                  psi_filepath=eigen_state_filepath)
      print(algo)
      ```

      ```output Output theme={null}
       OPENQASM 3.0;
       include "stdgates.inc";
       def iqft(qubit[4] q) {
         int n = 4;
         for int[16] i in [0:n - 1] {
           int[16] target = n - i - 1;
           for int[16] j in [0:n - target - 2] {
             int[16] control = n - j - 1;
             int[16] k = control - target;
             cp(-2 * pi / (1 << k + 1)) q[control], q[target];
           }
           h q[target];
         }
         for int[16] i in [0:(n >> 1) - 1] {
           swap q[i], q[n - i - 1];
         }
       }
       gate custom_t q {
         p(pi / 4) q;
       }
       gate CU a, b {
         ctrl @ custom_t a, b;
       }
       def qpe(qubit[4] q, qubit[1] psi) {
         int n = 4;
         for int i in [0:n - 1] {
           h q[i];
         }
         for int j in [0:n - 1] {
           int[16] k = 1 << j;
           for int m in [0:k - 1] {
             CU q[j], psi[0];
           }
         }
         iqft(q);
       }
       qubit[4] q;
       qubit[1] psi;
       bit[4] b;
       gate prep_eigenstate q {
         x q;
       }
       qpe(q, psi);
       b = measure q;
      ```
    </CodeGroup>
  </Tab>
</Tabs>

See [API Reference](https://qbraid.github.io/qbraid-algorithms/api/qbraid_algorithms.html) for complete functionality of each algorithm module.
