Welcome to the Quantum Calculator, a Python-based project utilizing Qiskit to perform basic arithmetic operations—addition, subtraction, and multiplication—using quantum circuits. This calculator showcases the power of quantum computing for arithmetic computations and serves as an educational tool for those interested in quantum programming.
This project demonstrates how quantum circuits can be used to perform arithmetic operations. By leveraging the capabilities of Qiskit, an open-source quantum computing framework, we implement quantum versions of addition, subtraction, and multiplication.
The calculator provides both a command-line interface and a graphical user interface (GUI) where users can select an operation and input numbers to perform calculations using quantum circuits simulated on a classical computer.
- Quantum Addition: Adds two numbers using a quantum ripple-carry adder circuit.
- Quantum Subtraction: Subtracts one number from another using the inverse of a quantum adder circuit.
- Quantum Multiplication: Multiplies two numbers using controlled addition and quantum gates.
- Graphical User Interface (GUI): A simple and user-friendly GUI built with Tkinter.
- Circuit Visualization: Ability to display the quantum circuit used in the calculation.
- Educational Tool: Helps users understand how quantum circuits can perform arithmetic operations.
- Modular Codebase: Organized code with modular functions for each arithmetic operation.
Follow these instructions to set up the project on your local machine.
- Python 3.8 or higher: Ensure you have Python installed. You can download it from the official website.
- pip: Python package installer, which usually comes with Python.
- Virtual Environment (optional but recommended): To manage dependencies without affecting system-wide packages.
- Tkinter: The standard Python interface to the Tk GUI toolkit (usually included with Python).
- Qiskit: Quantum computing framework for Python.
-
Clone the Repository
git clone https://github.com/your-username/quantum-calculator.git cd quantum-calculator
-
Set Up a Virtual Environment (Optional)
python -m venv venv source venv/bin/activate # On Unix or MacOS venv\Scripts\activate # On Windows
-
Install Dependencies
Use the
requirements.txt
file to install all necessary packages:pip install -r requirements.txt
Contents of
requirements.txt
:qiskit==0.45.0 numpy>=1.21.0
Note: Adjust the versions if necessary based on your environment.
Ensure that Qiskit is correctly installed by running:
python -c "import qiskit; print(qiskit.__qiskit_version__)"
This should display the versions of Qiskit's components without errors.
You can use the calculator in two ways:
- Command-Line Interface (CLI)
- Graphical User Interface (GUI)
To start the calculator using the command-line interface, run the calculator.py
script:
python calculator.py
To launch the graphical user interface, run the quantum_calculator_gui.py
script:
python quantum_calculator_gui.py
- Enter the First Number: Input the first integer in the provided field.
- Enter the Second Number: Input the second integer.
- Select the Operation: Choose from Add, Subtract, or Multiply.
- Calculate: Click the Calculate button to perform the operation.
- View Result: The result will be displayed on the screen.
- Show Circuit: Click the Show Circuit button to view the quantum circuit used in the calculation.
- User-Friendly Interface: Simple layout for easy interaction.
- Error Handling: Validates input and displays error messages for invalid data.
- Circuit Visualization: Displays the quantum circuit in a new window for educational purposes.
-
Addition Example
- Enter
4
as the first number. - Enter
6
as the second number. - Select Add.
- Click Calculate.
- Result displayed:
4 + 6 = 10
. - Click Show Circuit to view the quantum circuit.
- Enter
-
Subtraction Example
- Enter
10
as the first number. - Enter
3
as the second number. - Select Subtract.
- Click Calculate.
- Result displayed:
10 - 3 = 7
. - Click Show Circuit to view the quantum circuit.
- Enter
-
Multiplication Example
- Enter
5
as the first number. - Enter
4
as the second number. - Select Multiply.
- Click Calculate.
- Result displayed:
5 * 4 = 20
. - Click Show Circuit to view the quantum circuit.
- Enter
Select operation.
1.Add
2.Subtract
3.Multiply
Enter choice(1/2/3): 1
Enter first number: 4
Enter second number: 6
4.0 + 6.0 = 10
Let's do next calculation? (yes/no): yes
quantum-calculator/
├── calculator.py # Command-line calculator script
├── quantum_calculator_gui.py # GUI application script
├── adder.py # Contains the Adder function
├── subtractor.py # Contains the Sub function
├── multiplier.py # Contains the Multiply function
├── modifier.py # Contains the Modifier function
├── requirements.txt # Project dependencies
└── README.md # Project documentation
- calculator.py: Main script that provides the command-line user interface.
- quantum_calculator_gui.py: GUI application script using Tkinter.
- adder.py: Implements the quantum addition operation.
- subtractor.py: Implements the quantum subtraction operation.
- multiplier.py: Implements the quantum multiplication operation.
- modifier.py: Utility functions for initializing quantum circuits.
- requirements.txt: Lists all Python packages required.
- README.md: Documentation for the project.
Contributions are welcome! If you'd like to enhance the calculator (e.g., add division or other operations), please follow these steps:
-
Fork the Repository
Click the "Fork" button on the top right to create a copy of the repository on your GitHub account.
-
Clone Your Fork
git clone https://github.com/your-username/quantum-calculator.git cd quantum-calculator
-
Create a Feature Branch
git checkout -b feature/your-feature-name
-
Make Your Changes
- Implement your feature or fix.
- Ensure code follows the existing style.
- Test your changes thoroughly.
-
Commit and Push
git add . git commit -m "Add your commit message here" git push origin feature/your-feature-name
-
Create a Pull Request
Go to the original repository and click on "Pull Requests" to submit your changes for review.
This project is licensed under the MIT License - see the LICENSE file for details.
- Qiskit: Qiskit is an open-source SDK for working with quantum computers at the level of pulses, circuits, and application modules.
- IBM Quantum: For providing access to quantum computing resources and educational materials.
- Contributors: Thanks to everyone who has contributed to this project.
This project is intended for educational purposes to demonstrate quantum computing concepts. The quantum circuits are simulated on classical hardware using Qiskit's simulators.
- Introduced
quantum_calculator_gui.py
script for the graphical user interface. - The GUI allows users to input numbers, select operations, and perform calculations.
- Users can view the quantum circuit used in each calculation by clicking the Show Circuit button.
- Added details about the GUI and circuit visualization features.
- Provided instructions on how to run and use the GUI application.
- Included steps for performing calculations and viewing circuits in the GUI.
- Included
quantum_calculator_gui.py
in the project structure. - Provided descriptions for the GUI script.
- Ensure all dependencies are installed, including
tkinter
andqiskit
. - The GUI uses the same quantum functions (
Adder
,Sub
,Multiply
) as the command-line version.
Feel free to explore the code, experiment with the quantum circuits, and enhance the calculator with additional features. The GUI provides a more interactive way to engage with quantum computing concepts and visualize the underlying circuits.
If you encounter any issues or have suggestions, please open an issue on GitHub or contribute through a pull request.
Happy computing!