lynkos / grovers-algorithm

Python script and Jupyter notebook implementations of Grover's Algorithm aka Quantum Search Algorithm for n qubits and m targets.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Grover's Algorithm

Python Jupyter Qiskit Shell IDE
License Last Commit Commit Activity Repo Size

⭐️⭐️⭐️ Please star this repo if you find it helpful, interesting, or useful! ⭐️⭐️⭐️


Requirements

Tip

If you have trouble deciding between Anaconda and Miniconda, please refer to the table below

Anaconda Miniconda
New to conda and/or Python Familiar with conda and/or Python
Like the convenience of having Python and 1,500+ scientific packages automatically installed at once Want fast access to Python and the conda commands and plan to sort out the other programs later
Have the time and space (a few minutes and 3 GB) Don't have the time or space to install 1,500+ packages
Don't want to individually install each package Don't mind individually installing each package

Installation

  1. Verify that conda is installed
    conda --version
    
  2. Ensure conda is up to date
    conda update conda
    
  3. Enter the directory where you want the repository (grovers-algorithm) to be cloned
    • POSIX
      cd ~/path/to/directory
    • Windows
      cd C:\Users\user\path\to\directory
  4. Clone the repository (grovers-algorithm), then enter its directory
    git clone https://github.com/lynkos/grovers-algorithm.git && cd grovers-algorithm
    
  5. Create a conda virtual environment from environment.yml
    conda env create -f environment.yml
    
  6. Activate the virtual environment (grovers_env)
    conda activate grovers_env
    
  7. Confirm that the virtual environment (grovers_env) is active
    • If active, the virtual environment's name should be in parentheses () or brackets [] before your command prompt, e.g.
      (grovers_env) $
      
    • If necessary, see which environments are available and/or currently active (active environment denoted with asterisk (*))
      conda info --envs
      
      OR
      conda env list
      

Conda Shortcuts (Optional)

Instead of manually typing out entire conda commands, you can save time by adding this .sh script to your shell startup file (e.g., .bashrc, etc.) and using it in your terminal.

Warning

These shortcut commands have ONLY been tested on bash v5.2.26(1)-release with aarch64-apple-darwin23.2.0 architecture, so — just to be safe — test and make changes as needed.

E.g., rmenv assumes the path delimeter is forward slash / (POSIX systems); if you use Windows (path delimeter is backslash \), replace forward slashes / in env_path with backslashes \.

Command Description Usage
act Activate conda environment act [env_name]
dac Deactivate conda environment dac
mkenv Create conda environment(s) From .yml / .yaml file(s): mkenv [file1] [file2] ... [fileN]
From CLI: mkenv [env_name] [package1] [package2] ... [packageN]
rmenv Remove conda environment(s) rmenv [env1] [env2] ... [envN]
rnenv Rename conda environment rnenv [curr_name] [new_name]
cpenv Copy conda environment cpenv [env_name] [copy's_name]
exp Export conda environment exp [file]
lsenv List conda environment lsenv

Usage

Visual Studio Code (Recommended)

  1. Open the Command Palette in Visual Studio Code with the relevant keyboard shortcut
    • Mac
      ⌘ + Shift + P
      
    • Windows
      CTRL + Shift + P
      
  2. Search and select Python: Select Interpreter
  3. Select the virtual environment (grovers_env)
  4. Open Grovers-Algorithm.ipynb and/or Grovers-Algorithm.py
  5. Confirm grovers_env is the selected kernel
  6. Run program(s)
    • Grovers-Algorithm.ipynb: Click Run All
    • Grovers-Algorithm.py: Click (i.e. Play button) in the upper-right corner
  7. Deactivate the virtual environment (grovers_env) when you're finished
    conda deactivate
    

Command Line

Python

  1. Run Grovers-Algorithm.py
    • POSIX
      $(which python) Grovers-Algorithm.py
    • Windows
      $(where python) Grovers-Algorithm.py
  2. Deactivate the virtual environment (grovers_env) when you're finished
    conda deactivate
    

Jupyter Notebook

  1. Install ipykernel in the virtual environment (grovers_env)
    conda install -n grovers_env ipykernel
    
  2. Add the virtual environment (grovers_env) as a Jupyter kernel
    python -m ipykernel install --user --name=grovers_env
    
  3. Open Grovers-Algorithm.ipynb in the currently running notebook server, starting one if necessary
    jupyter notebook Grovers-Algorithm.ipynb
    
  4. Select the virtual environment (grovers_env) as the kernel before running Grovers-Algorithm.ipynb
  5. Deactivate the virtual environment (grovers_env) when you're finished
    conda deactivate
    

Resources

Contact

For all questions, bugs, suggestions, etc. relating to this project, please create an issue with a relevant label/tag. For all other queries, feel free to reach out via:

Twitter  Gmail   LinkedIn

Note: Timely response is not guaranteed!

License

Distributed under the MIT License, Copyright © 2023 Kiran Brahmatewari

About

Python script and Jupyter notebook implementations of Grover's Algorithm aka Quantum Search Algorithm for n qubits and m targets.

License:MIT License


Languages

Language:Jupyter Notebook 98.9%Language:Python 0.9%Language:Shell 0.2%