-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
704e988
commit 498438b
Showing
81 changed files
with
17,373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.ipynb_checkpoints | ||
./nickel/Solutions | ||
.vscode | ||
.venv | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# QNickel | ||
|
||
Welcome to QNickel, a repository dedicated to exploring quantum computing with the Qiskit framework using the Nickel quantum processor. | ||
|
||
## Overview | ||
|
||
QNickel provides a collection of quantum programs and examples that demonstrate various concepts and algorithms in quantum computing. Whether you are a beginner or an experienced quantum programmer, this repository aims to provide you with a hands-on learning experience.Solutions added | ||
|
||
## Getting Started | ||
|
||
To get started with QNickel, follow these steps: | ||
|
||
1. Clone the repository: `git clone https://github.com/qworld/qnickel.git` | ||
2. Install the required dependencies: `pip install -r requirements.txt` | ||
3. Explore the examples and programs in the repository. | ||
4. Run the programs using the Nickel quantum processor. | ||
|
||
## Contents | ||
|
||
The repository is organized into the following directories: | ||
|
||
- `examples`: Contains a collection of example programs showcasing different quantum algorithms and concepts. | ||
- `tutorials`: Provides step-by-step tutorials to help you understand and implement quantum algorithms. | ||
- `resources`: Includes additional resources such as papers, articles, and presentations related to quantum computing. | ||
|
||
## Contributing | ||
|
||
We welcome contributions from the community to enhance QNickel. If you have any ideas, bug fixes, or improvements, feel free to open an issue or submit a pull request. | ||
|
||
## License | ||
|
||
QNickel is licensed under the [MIT License](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<table width=\"100%\"><tr style=\"background-color:white;\">\n", | ||
" <td style=\"text-align:left;padding:0px;width:142px'\">\n", | ||
" <a href=\"https://qworld.net\" target=\"_blank\">\n", | ||
" <img src=\"qworld/images/QWorld.png\"></a></td>\n", | ||
" <td width=\"*\"> </td>\n", | ||
" <!-- ############################################# -->\n", | ||
" <td style=\"padding:0px;width:90px;\">\n", | ||
" <img align=\"right\" src=\"qworld/images/follow_us.png\" height=\"40px\"></td>\n", | ||
" <td style=\"padding:0px;width:40px;\">\n", | ||
" <a href=\"https://twitter.com/QWorld19\" target=\"_blank\">\n", | ||
" <img align=\"right\" src=\"qworld/images/Twitter.png\" width=\"40px\"></a> </td>\n", | ||
" <td style=\"padding:0px;width:5px;\"></td>\n", | ||
" <td style=\"padding:0px;width:40px;\">\n", | ||
" <a href=\"https://www.facebook.com/qworld19/\" target=\"_blank\">\n", | ||
" <img align=\"right\" src=\"qworld/images/Fb.png\"></a></td>\n", | ||
" <td style=\"padding:0px;width:5px;\"></td>\n", | ||
" <td style=\"padding:0px;width:40px;\">\n", | ||
" <a href=\"https://www.linkedin.com/company/qworld19\" target=\"_blank\">\n", | ||
" <img align=\"right\" src=\"qworld/images/LinkedIn.png\"></a></td>\n", | ||
" <td style=\"padding:0px;width:5px;\"></td>\n", | ||
" <td style=\"padding:0px;width:40px;\">\n", | ||
" <a href=\"https://youtube.com/QWorld19?sub_confirmation=1\" target=\"_blank\">\n", | ||
" <img align=\"right\" src=\"qworld/images/YT.png\"></a></td>\n", | ||
" <!-- ############################################# -->\n", | ||
" <td style=\"padding:0px;width:60px;\">\n", | ||
" <img align=\"right\" src=\"qworld/images/join.png\" height=\"40px\"></td>\n", | ||
" <td style=\"padding:0px;width:40px;\">\n", | ||
" <a href=\"https://discord.com/invite/akCvr7U87g\"\n", | ||
" target=\"_blank\">\n", | ||
" <img align=\"right\" src=\"qworld/images/Discord.png\"></a></td>\n", | ||
" <!-- ############################################# -->\n", | ||
" <td style=\"padding:0px;width:72px;\">\n", | ||
" <img align=\"right\" src=\"qworld/images/w3.png\" height=\"40px\"></td>\n", | ||
" <td style=\"padding:0px;width:40px;\">\n", | ||
" <a href=\"https://qworld.net\" target=\"_blank\">\n", | ||
" <img align=\"right\" src=\"qworld/images/www.png\"></a></td>\n", | ||
"</tr></table>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<h1 align=\"center\" style=\"color: #A9A9A9;\"> Welcome to QWorld's Nickel </h1>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<font style=\"color: #A9A9A9;size:+1;\"><b>Nickel</b></font> is the continuation of our introductory material Bronze about the basics of quantum computation and quantum programming. It is a big collection of [Jupyter notebooks](https://jupyter.org).\n", | ||
"\n", | ||
"In Nickel, we focus on oracular quantum algorithms.\n", | ||
"\n", | ||
"*If you are using Jupyter notebooks for the first time, you can check our very short <a href=\"python/R00_Intro_to_Notebooks.ipynb\" target=\"_blank\">Introduction for Notebooks</a>.*\n", | ||
"\n", | ||
"**The open-source toolkits we are using:**\n", | ||
"- Programming language: <a href=\"https://www.python.org\" target=\"_blank\">python</a>\n", | ||
"- Quantum programming libraries:</u> <a href=\"https://qiskit.org\" target=\"_blank\">Qiskit</a>, and <a href=\"https://github.com/quantumlib/Cirq\" target=\"_blank\">Cirq</a>\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Installation and Test\n", | ||
"\n", | ||
"_Python libraries including quantum ones are often updated. Therefore, there might appear some problems due to different versions._\n", | ||
"\n", | ||
"Before starting to use Nickel, please test your system by using the following notebook(s)!\n", | ||
"\n", | ||
"[Qiskit installation and test](test/Qiskit_installation_and_test.ipynb) \n", | ||
"\n", | ||
"[Cirq installation and test](test/Cirq_installation_and_test.ipynb) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Reference notebboks\n", | ||
"\n", | ||
"[Python Reference](nickel/R01_Python_Reference.ipynb) | \n", | ||
"[Python: Drawing](nickel/R02_Python_Drawing.ipynb) \n", | ||
"\n", | ||
"<hr>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Conventional Quantum Algorithms in Qiskit\n", | ||
"[Introduction to Qiskit](nickel/A00_Qiskit_Introduction.ipynb)\n", | ||
"\n", | ||
"[Classical gates](nickel/A01_Classical_Gates.ipynb) | \n", | ||
"[Phase kickback](nickel/A02_Phase_Kickback.ipynb) | \n", | ||
"[Deutsch Algorithm](nickel/A03_Deutsch_Algorithm.ipynb)\n", | ||
"\n", | ||
"[Deutsch-Jozsa Algorithm](nickel/A04_Deutsch_Jozsa_Algorithm.ipynb) | \n", | ||
"[Bernstein-Vazirani Algorithm](nickel/A05_Bernstein_Vazirani_Algorithm.ipynb) | \n", | ||
"[Simon's Algorithm](nickel/A06_Simons_Algorithm.ipynb)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Solving Max-Cut problem using Grover's Search in Cirq\n", | ||
"\n", | ||
"[Introduction to Cirq](nickel/D00_Cirq_Introduction.ipynb) | \n", | ||
"[Grover Algorithm revisited](nickel/B01_Grover_Algorithm_Revisited.ipynb)\n", | ||
"\n", | ||
"[Max-Cut Problem and Bipartite Graphs](nickel/B02_Max_Cut_Problem.ipynb) | \n", | ||
"[Adders and Numbers Checking](nickel/B03_Adders_And_Numbers_Checking.ipynb)\n", | ||
"\n", | ||
"[Grover algorithm for Max-Cut Problem](nickel/B04_Grover_Algorithm_For_Max-Cut_Problem.ipynb)\n", | ||
"<hr>\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"[Credits](nickel/N00_Credits.ipynb)\n", | ||
"[References](nickel/N01_References.ipynb)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import matplotlib.pyplot as plt | ||
|
||
# drawing used for math | ||
|
||
def plot_2D_plane(right=5,up=5,left=-5,down=-5,fsize=(8,8)): | ||
hpoints, vpoints = [],[] | ||
for i in range(left,right+1): | ||
if i!=0: hpoints.append(i) | ||
for i in range(down,up+1): | ||
if i!=0: vpoints.append(i) | ||
|
||
ax = plt.figure(figsize=fsize).gca() | ||
|
||
# Set identical scales for both axes | ||
ax.set(xlim=(left-1,right+1), ylim=(down-1, up+1), aspect='equal') | ||
# Remove top and right spines | ||
ax.spines['top'].set_visible(False) | ||
ax.spines['right'].set_visible(False) | ||
# Set bottom and left spines as x and y axes of coordinate system | ||
ax.spines['bottom'].set_position('zero') | ||
ax.spines['left'].set_position('zero') | ||
# Create minor ticks placed at each integer to enable drawing of minor grid | ||
ax.set_xticks(hpoints) | ||
ax.set_yticks(vpoints) | ||
# Draw major and minor grid lines | ||
ax.grid(which='both', color='grey', linewidth=1, linestyle='-', alpha=0.2) | ||
# Create 'x' and 'y' labels placed at the end of the axes | ||
ax.set_xlabel('x', size=14, labelpad=-24, x=1.03) | ||
ax.set_ylabel('y', size=14, labelpad=-21, y=1.02, rotation=0) | ||
# Draw arrows | ||
arrow_fmt = dict(markersize=4, color='black', clip_on=False) | ||
ax.plot((1), (0), marker='>', transform=ax.get_yaxis_transform(), **arrow_fmt) | ||
ax.plot((0), (0), marker='<', transform=ax.get_yaxis_transform(), **arrow_fmt) | ||
ax.plot((0), (1), marker='^', transform=ax.get_xaxis_transform(), **arrow_fmt) | ||
ax.plot((0), (0), marker='v', transform=ax.get_xaxis_transform(), **arrow_fmt) | ||
|
||
def draw_sides(x=1,y=2,side_color="b",lwidth=1): | ||
plt.arrow(x,0,0,y,color=side_color,linestyle="dotted",width=0.001*lwidth) | ||
plt.arrow(0,y,x,0,color=side_color,linestyle="dotted",width=0.001*lwidth) | ||
|
||
def draw_vector(x=1,y=2,vname="v",show_name=True,vcolor="b",sides=False,side_color="b",lwidth=1): | ||
plt.quiver(0,0,x,y,scale=1,scale_units='xy',angles = 'xy',color=vcolor,width=0.008*lwidth) | ||
dx = x | ||
if y<0: dy=y-0.3 | ||
else: dy = y+0.3 | ||
|
||
if show_name: | ||
vector_name="$"+vname+"=("+str(x)+","+str(y)+")$" | ||
plt.text(dx,dy,vector_name,color=vcolor) | ||
|
||
if sides: | ||
draw_sides(x,y,side_color) | ||
|
||
def place_text(x,y,text,tcolor="blue"): | ||
plt.text(x,y,text,color=tcolor) | ||
|
||
def show_plt(): | ||
plt.show() | ||
|
||
# drawing used for quantum | ||
def draw_axes(): | ||
points = [ [1.2,0], [0,1.2], [-1.2,0], [0,-1.2] ] # dummy points for zooming out | ||
arrows = [ [1.1,0], [0,1.1], [-1.1,0], [0,-1.1] ] # coordinates for the axes | ||
for p in points: | ||
plt.plot(p[0],p[1]+0.1) # drawing dummy points | ||
for a in arrows: | ||
plt.arrow(0,0,a[0],a[1],head_width=0.04, head_length=0.08) # drawing the axes | ||
|
||
|
||
def draw_unit_circle(): | ||
unit_circle= plt.Circle((0,0),1,color='black',fill=False) | ||
plt.gca().add_patch(unit_circle) | ||
|
||
def draw_quantum_state(x,y,name): | ||
# shorten the line length to 0.92 | ||
# line_length + head_length should be 1 | ||
x1 = 0.92 * x | ||
y1 = 0.92 * y | ||
plt.arrow(0,0,x1,y1,head_width=0.04,head_length=0.08,color="blue") | ||
x2 = 1.15 * x | ||
y2 = 1.15 * y | ||
plt.text(x2,y2,name) | ||
|
||
def draw_qubit(): | ||
# draw a figure | ||
plt.figure(figsize=(6,6), dpi=60) | ||
# draw the origin | ||
plt.plot(0,0,'ro') # a point in red color | ||
# drawing the axes by using one of our predefined function | ||
draw_axes() | ||
# drawing the unit circle by using one of our predefined function | ||
draw_unit_circle() | ||
# drawing |0> | ||
plt.plot(1,0,"o") | ||
plt.text(1.05,0.05,"|0>") | ||
# drawing |1> | ||
plt.plot(0,1,"o") | ||
plt.text(0.05,1.05,"|1>") | ||
# drawing -|0> | ||
plt.plot(-1,0,"o") | ||
plt.text(-1.2,-0.1,"-|0>") | ||
# drawing -|1> | ||
plt.plot(0,-1,"o") | ||
plt.text(-0.2,-1.1,"-|1>") | ||
|
||
def draw_qubit_grover(): | ||
# draw a figure | ||
plt.figure(figsize=(7,7), dpi=60) | ||
# draw the origin | ||
plt.plot(0,0,'ro') # a point in red color | ||
# drawing the axes by using one of our predefined function | ||
draw_axes() | ||
# drawing the unit circle by using one of our predefined function | ||
draw_unit_circle() | ||
# drawing |0> | ||
plt.plot(1,0,"o") | ||
plt.text(1.05,0.05,"|unmarked>") | ||
# drawing |1> | ||
plt.plot(0,1,"o") | ||
plt.text(0.05,1.05,"|marked>") | ||
# drawing -|0> | ||
plt.plot(-1,0,"o") | ||
plt.text(-0.98,-0.09,"-|unmarked>") | ||
# drawing -|1> | ||
plt.plot(0,-1,"o") | ||
plt.text(-0.4,-1.1,"-|marked>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
def contFrac(N): | ||
import math | ||
cf=[] | ||
while True: | ||
cf.append(int(N)) | ||
f = N - N//1 | ||
if f < 0.0001: # or whatever precision you consider close enough to 0 | ||
break | ||
N = 1/f | ||
if(math.ceil(N)-N<0.0001): | ||
N=round(N) | ||
return cf | ||
|
||
|
||
def convergents(cf): | ||
from fractions import Fraction | ||
c=[] | ||
cv=[] | ||
|
||
for i in range(len(cf)): | ||
c.append(cf[i]) | ||
for j in range(i-1,-1,-1): | ||
c[i] = 1/c[i]+ cf[j] | ||
cv.append(Fraction(c[i]).limit_denominator(10000)) | ||
return cv |
Oops, something went wrong.