Skip to content

Commit 6d62cdd

Browse files
authored
Add files via upload
This is the moved repository of the content on QML projects done for QuantumAI.
1 parent fe31c8f commit 6d62cdd

19 files changed

+89094
-0
lines changed

QuantumAI/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Sai Ganesh Manda
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

QuantumAI/Project_QML/1-Fundamentals_of_Quantum_Computing/Fundamentals_of_Quantum_Computing.ipynb

Lines changed: 86687 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from quiz_model import Question
2+
from quiz_brain import QuizBrain
3+
from quiz_ui import QuizInterface
4+
from quiz_data import question_data
5+
from random import shuffle
6+
7+
def main():
8+
question_bank = []
9+
for question in question_data:
10+
choices = []
11+
question_text = question['question']
12+
correct_answer = question['correct_answer']
13+
incorrect_answers = question['incorrect_answers']
14+
for ans in incorrect_answers:
15+
choices.append(ans)
16+
choices.append(correct_answer)
17+
shuffle(choices)
18+
new_question = Question(question=question_text, correct_answer=correct_answer, options=choices)
19+
question_bank.append(new_question)
20+
21+
quiz = QuizBrain(questions=question_bank)
22+
quiz_ui = QuizInterface(quiz_brain=quiz)
23+
24+
print("You have completed the Quantum Quiz!! Congratulations!")
25+
print(f"You final score is: {quiz.score}/{quiz.question_no}")
26+
27+
# if __name__ == "__main__":
28+
# main()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Instructions for Making Use of the Quiz Graphical User Interface (GUI)
2+
3+
4+
To be able to use the Python library functions for making an API for a quiz box with a GUI, install the library _tkinter_ using the following command:
5+
6+
`pip install tkintertable`
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class QuizBrain:
2+
3+
def __init__(self, questions):
4+
self.question_no = 0
5+
self.score = 0
6+
self.questions = questions
7+
self.current_question = None
8+
9+
def has_more_questions(self):
10+
return self.question_no < len(self.questions)
11+
12+
def next_question(self):
13+
self.current_question = self.questions[self.question_no]
14+
self.question_no += 1
15+
ques_text = self.current_question.question_text
16+
return f"Q{self.question_no}. {ques_text}"
17+
18+
def check_answer(self, user_answer):
19+
correct_answer = self.current_question.correct_answer
20+
if user_answer.lower() == correct_answer.lower():
21+
self.score += 1 # Increasing the score by one point for every correct answer
22+
return True
23+
else:
24+
# self.score -= 1 # Deducting a point for every wrong answer
25+
return False
26+
27+
def get_score(self):
28+
wrong = self.question_no - self.score
29+
score_percent = int((self.score / self.question_no) * 100)
30+
return (self.score, wrong, score_percent)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
question_data = [{"question":"What makes a qubit different to a classical bit?", "correct_answer":"superposition",
2+
"incorrect_answers":["energy","hardware","computational speed"]},
3+
{"question":"Which pair of gates are applied to entangle two qubits?", "correct_answer":"H & CX",
4+
"incorrect_answers":["X & CX", "CX & H", "H & CZ"]},
5+
{"question":"What speed-up does Grover's Algorithm promise over classical unstructured search?", "correct_answer":"quadratic",
6+
"incorrect_answers":["cubic", "exponential", "depends on the problem"]},
7+
{"question":"How many classical and quantum mechanical queries respectively does the Deutsch-Josza Algorithm take to determine the constancy (or otherwise) of a function?", "correct_answer":"2^(n-1)+1 and 1",
8+
"incorrect_answers":["2^n and n", "n^2 and logn", "n and 1"]},
9+
{"question":"What does the Shor's Algorithm incoporate in its circuit construction?", "correct_answer":"Quantum Fourier Transform",
10+
"incorrect_answers":["Quantum Teleportation", "Entanglement Swapping", "Quantum Tunneling"]}]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Question:
2+
def __init__(self, question : str, correct_answer : str, options : list):
3+
self.question_text = question
4+
self.correct_answer = correct_answer
5+
self.choices = options
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
from quiz_brain import QuizBrain
2+
from tkinter import *
3+
from tkinter import messagebox
4+
5+
THEME_COLOR = 'blue'
6+
7+
class QuizInterface:
8+
9+
def __init__(self, quiz_brain : QuizBrain) -> None:
10+
self.quiz = quiz_brain
11+
self.window = Tk()
12+
self.window.title("QUANTUM QUIZ")
13+
self.window.geometry("850x530")
14+
15+
# Display title
16+
self.display_title()
17+
18+
# A canvas for question text and displaying the question
19+
self.canvas = Canvas(width=800, height=250)
20+
self.question_text = self.canvas.create_text(400, 125, text="Question here", width=680, fill=THEME_COLOR, font=('Ariel', 15, 'italic'))
21+
self.canvas.grid(row=2, column=0, columnspan=2, pady=50)
22+
self.display_question()
23+
24+
# Store user's answer
25+
self.user_answer = StringVar()
26+
27+
# Disply four options (radio_buttons)
28+
self.opts = self.radio_buttons()
29+
self.display_options()
30+
31+
# To show whether the answer is correct or wrong
32+
self.feedback = Label(self.window, pady=10, font=('ariel', 15, 'bold'))
33+
self.feedback.place(x=290, y=50)
34+
35+
# Next and Quit buttons
36+
self.buttons()
37+
self.window.mainloop(0)
38+
39+
# DISPLAY THE TITLE
40+
def display_title(self):
41+
title = Label(self.window, text="QUANTUM QUIZ APPLICATION", width=50, bg='green', fg='crimson', font=('ariel', 20, 'bold'))
42+
title.place(x=0, y=2)
43+
44+
# DISPLAY THE QUESTIONS
45+
def display_question(self):
46+
quest_text = self.quiz.next_question()
47+
self.canvas.itemconfig(self.question_text, text=quest_text)
48+
49+
# CREATE THE RADIO BUTTONS
50+
def radio_buttons(self):
51+
choices = [] # empty options initialized
52+
y_position = 220 # position of the first option
53+
54+
# Add the options to the list
55+
while len(choices) < 4:
56+
radio_button = Radiobutton(self.window, text="", variable=self.user_answer, value="", font=('ariel', 14))
57+
choices.append(radio_button)
58+
radio_button.place(x=200, y=y_position) # place the button(s)
59+
y_position += 41 # incrementing the position of the first question every time a new choice is added in
60+
return choices
61+
62+
# DISPLAY THE OPTIONS
63+
def display_options(self):
64+
val = 0
65+
# deselecting the options
66+
self.user_answer.set(None)
67+
68+
for option in self.quiz.current_question.choices:
69+
self.opts[val]['text'] = option
70+
self.opts[val]['value'] = option
71+
val += 1
72+
73+
# NEXT BUTTON FUNCTIONALITY
74+
def next_button(self):
75+
# check if the answer given by the user is correct
76+
if (self.quiz.check_answer(self.user_answer.get())):
77+
self.feedback['fg'] = 'green'
78+
self.feedback['text'] = 'Correct! \U0001F44D'
79+
80+
else:
81+
self.feedback['fg'] = 'red'
82+
self.feedback['text'] = ('\u274E Oops! \n'
83+
f'The right answer is: {self.quiz.current_question.correct_answer}')
84+
85+
if self.quiz.has_more_questions():
86+
# Move on the next one to display the next question, if there are any more
87+
self.display_question()
88+
self.display_options()
89+
else:
90+
# if no more questions, then display the result
91+
self.display_result()
92+
self.window.destroy()
93+
94+
def buttons(self):
95+
"""To show next button and quit button"""
96+
97+
# The first button is the Next button to move to the next Question
98+
next_button = Button(self.window, text="Next", command=self.next_button,
99+
width=10, bg="green", fg="white", font=("ariel", 16, "bold"))
100+
101+
# palcing the button on the screen
102+
next_button.place(x=350, y=460)
103+
104+
# This is the second button which is used to Quit the self.window
105+
quit_button = Button(self.window, text="Quit", command=self.window.destroy,
106+
width=5, bg="red", fg="white", font=("ariel", 16, " bold"))
107+
108+
# placing the Quit button on the screen
109+
quit_button.place(x=700, y=50)
110+
111+
# DISPLAY THE RESULT
112+
def display_result(self):
113+
correct, wrong, score_percent = self.quiz.get_score()
114+
115+
correct = f"Correct : {correct}"
116+
wrong = f"Wrong : {wrong}"
117+
correct_percent = f"Percentage : {score_percent}"
118+
119+
# Show a message box to display the result
120+
messagebox.showinfo(title="RESULT", message=f"\n{correct_percent}\n{correct}\n{wrong}")

0 commit comments

Comments
 (0)