This repository contains Qiskit code to simulate an ALU using QSim
- Register on the QSim Portalhttps://qctoolkit.in)
- Log in to QSim along with your given Username and Password.
- Paste the Code in the QSim editor.
- Click on the run circuit button:
- Run Blender by clicking on the following LINK.
- Open a New Notebook.
- Upload the .ipynb file at following LINK.
- Click on Restart Kernal and All Cells button.
- Now all the cells will be run!
from qiskit import QuantumRegister, ClassicalRegister
from qiskit import QuantumCircuit, execute, BasicAer
import numpy as np
q = QuantumRegister(10, 'q')
c = ClassicalRegister(10, 'c') # Output registers
qc = QuantumCircuit(q, c)
input_1 = 5
input_2 = 3
operation = 'Multiplication'
This step is needed since the inputs will be in the binary string format.
bin_input_1 = format(input_1, '03b')
bin_input_2 = format(input_2, '03b')
for i, bit in enumerate(bin_input_1):
if bit == '1':
qc.x(q[i + 2]) # Apply X gate to q[2] and q[3]
for i, bit in enumerate(bin_input_2):
if bit == '1':
qc.x(q[i + 4]) # Apply X gate to q[4] and q[5]
- Addition
- Substraction
- Multiplication
- Division
- XOR
- AND
- OR
- NOT
Example of Addition:
qc.cx(q[3], q[0]) # Swap q[3] and q[0]
qc.cx(q[4], q[0]) # XOR
qc.ccx(q[3], q[4], q[0]) # AND
qc.measure(q[0], c[0])
qc.measure(q[1], c[1])
qc.measure(q[4], c[2])
qc.measure(q[2], c[3])
backend = BasicAer.get_backend('dm_simulator')
job = execute(qc, backend=backend, **options)
job_result = job.result()
density_matrix = job_result.results[0].data.densitymatrix
print(density_matrix)
- CDAC Team
- IIT Roorkee
- IISc Bangalore
- All other organizers
Sumanto Kar
Student and Project Staff, IIT Bombay
Contact: jeetsumanto123@gmail.com