This repository contains the code accompanying the master's thesis titled 'Shor's Algorithm for IBM Qiskit' defended in 2021. It serves as a scientific resource for students taking a course on quantum computing.
- Python version >= 3.8
- IBMQ account with saved credentials (for better performance of simulation)
- Basic knowledge about Shor's algorithm ;)
- Clone (or fork) repository and enter project directory.
git clone https://github.com/bartek-bartlomiej/master-thesis.git
cd master-thesis
- Create and activate virtual environment.
python3.8 -m venv venv
source venv/bin/activate
- Install requirements.
pip install -r requirements.txt
- For running tests, install development requirements.
pip install -r requirements-dev.txt
Run Jupyter
jupyter notebook
and open laboratories_notebook.ipynb
.
Import class from one of package in implementations
and create instance:
from implementations.mix import MixShor as Shor
from qiskit import Aer
from qiskit.utils import QuantumInstance
shor = Shor(quantum_instance=QuantumInstance(backend=Aer.get_backend('qasm_simulator')))
For constructing quantum part of the algorithm:
circuit = shor.construct_circuit(a=4, N=15, semi_classical=False, measurement=True)
circuit.draw(output='mpl')
For acquiring the order r
of an element a
in the multiplicative group (mod N)
:
result = shor.get_order(a=4, N=15, semi_classical=True)
print(result.order)
For perform factorization of N
:
factors = shor.factor(a=4, N=15, semi_classical=True)
print(factors)
Run:
python -m unittest tests/test_implementations.py
Copyright (c) 2023 Bartłomiej Stępień
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Master thesis addressed the subject of variants and implementations of the Shor [1] algorithm - one of the famous examples of Quantum Computing. Methods of optimising the number of qubits in the quantum part of the Shor algorithm was presented as well as the design of a circuit implementing the modular exponentiation operation present in the papers by Beauregard [2], Takahashi [3], Häner [4] and the author's combination of variants in question:
Beauregard | Takahashi | Häner | Author's combination | |
---|---|---|---|---|
Width (w/o SCQT opt.) | ||||
Width (with SCQT opt.) | ||||
Size | ||||
Depth |
An evaluation has been carried out to compare the developed implementations - the author's combination of variants performed best in terms of simulation time and circuit size. The regression line confirms the exponential growth of simulation time with an increase in the number of simulated qubits.
Each solution from the literature has its strengths:
- Takahashi's variant - describes a circuit with the smallest size (among the three works).
- Beauregard's variant - circuit with the smallest depth.
- Häner's variant - circuit with the best asymptotic complexity of size.
On the other hand, the authors' combination proved to be better than Takahashi's variant in terms of size and simulation time of the system.
[1] Peter W. Shor, "Polynomial-Time Algorithms for Prime Factorization and Di- screte Logarithms on a Quantum Computer", 1997
[2] Stephane Beaureagard, "Circuit for Shor’s algorithm using 2n+3 qubits", 2003
[3] Yasuhiro Takahashi, "Efficient Quantum Circuits For Arithmetic Operations And Their Applications", 2008
[4] Thomas Häner, "Factoring using 2n+2 qubits with Toffoli based modular multiplication", 2017