From 5fd3b729ed41b1321be4d445826e4952a461789c Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Thu, 1 Sep 2016 21:30:53 +0100 Subject: [PATCH] Continue Writing --- Report/appedix/controlledGates.tex | 27 ++++++++ Report/main.tex | 60 +++++++++++++++-- Report/sections/introduction.tex | 6 +- Report/sections/ref.bib | 7 ++ Report/sections/simulation.tex | 104 +++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 Report/appedix/controlledGates.tex create mode 100644 Report/sections/simulation.tex diff --git a/Report/appedix/controlledGates.tex b/Report/appedix/controlledGates.tex new file mode 100644 index 0000000..025c355 --- /dev/null +++ b/Report/appedix/controlledGates.tex @@ -0,0 +1,27 @@ +\documentclass[../main.tex]{subfiles} + +\begin{document} + +One method of creating 'Controlled Unitary-2x2 Gates', +that involves a new number \(c\), or the control value. +When working with this value, it has all of the properties of a real number (\(\mathbb{R}\)), except that the kronecker product of any matrix \(M\), and \(c\) is: +\begin{equation} + c \otimes M = c \cdot Id +\end{equation} +With \(Id\) Being a 2x2 Identity matrix. \\ +Now with a control matrix, \(C = \begin{bmatrix} c & 0 \\ 0 & 1\end{bmatrix}\), You can create any controlled matrix \(CG_{control, target, n}\) (With \(G\) being the 2x2 matrix you want to apply, \(control\) being the number of the qubit controlling the opperation, \(target\) being the number of the qubit you want to apply \(G\) to conditionally, and \(n\) being the total number of qubits in the register) with this equation: +\begin{equation} + CG_{control, target, n} = \underset{i=1}{\overset{n}{\otimes}} + \begin{cases} + G & \text{if} \quad i = target\text{;} \\ + C & \text{if} \quad i = control\text{;} \\ + Id & \text{otherwise.} + \end{cases} +\end{equation} + +(Again: \(\underset{i=1}{\overset{n}{\otimes}}\) is like \(\underset{i=1}{\overset{n}{\sum}}\), but using the kronecker product, instead of the sum.) + +Credit to Craig Gidney \cite{controlslikevalues} + + +\end{document} diff --git a/Report/main.tex b/Report/main.tex index 324e4f0..8432c17 100644 --- a/Report/main.tex +++ b/Report/main.tex @@ -8,17 +8,53 @@ \usepackage{amssymb} \usepackage{graphicx} \usepackage{csquotes} +\usepackage{courier} +\usepackage{pgf,tikz} +\usepackage{mathrsfs} +\usetikzlibrary{arrows} +\usepackage{listings} +\usepackage{fontbook} +\usepackage{color} + +\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666} +\definecolor{zzttqq}{rgb}{0.6,0.2,0.} +\definecolor{qqqqff}{rgb}{0.,0.,1.} +\definecolor{codegreen}{rgb}{0,0.6,0} +\definecolor{codegray}{rgb}{0.5,0.5,0.5} +\definecolor{codepurple}{rgb}{0.58,0,0.82} +\definecolor{backcolour}{rgb}{0.95,0.95,0.92} + +\lstdefinestyle{mystyle}{ + backgroundcolor=\color{backcolour}, + commentstyle=\color{codegreen}, + keywordstyle=\color{magenta}, + numberstyle=\tiny\color{codegray}, + stringstyle=\color{codepurple}, + basicstyle=\footnotesize, + breakatwhitespace=false, + breaklines=true, + captionpos=b, + keepspaces=true, + numbers=left, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + tabsize=2 +} + +\lstset{style=mystyle} \usepackage[ backend=biber, style=numeric ]{biblatex} \addbibresource{sections/ref.bib} - + \title{Designing a High Level Programming Language for Quantum Computing} \subtitle{For the implementation and simulation of Classical and Quantum Algorithms} \author{Adam Kelly} \date{January 2017} - + \begin{document} \begin{titlepage} @@ -28,10 +64,24 @@ \newpage \tableofcontents \newpage - + \section{An Introduction to Quantum Computing} \subfile{sections/introduction} - + +\section{Simulating a Quantum Computer} +\subfile{sections/simulation} + +\newpage +\section{Appendix} +\subsection{Creating Controlled Unitary Gates} +\subfile{appedix/controlledGates} + +\subsection{Source Code} + +\emph{QuSim.py | Main Simulator} +%\lstinputlisting[language=Python]{../Code/Simulator/QuSim.py} + \newpage \printbibliography -\end{document} \ No newline at end of file +\newpage +\end{document} diff --git a/Report/sections/introduction.tex b/Report/sections/introduction.tex index ddd73e7..d4b96f4 100644 --- a/Report/sections/introduction.tex +++ b/Report/sections/introduction.tex @@ -279,9 +279,7 @@ \subsubsection{T or Pi/8 Gate} \end{equation} The \(T\) Gate makes it possible to access all points on a Bloch -Sphere.\\ -This is all of the gates that will be implemented into the simulator. - - +Sphere.\\ \\ \\ +These all of the gates that will be implemented into the simulator. \end{document} \ No newline at end of file diff --git a/Report/sections/ref.bib b/Report/sections/ref.bib index 1db25a7..96e8cba 100644 --- a/Report/sections/ref.bib +++ b/Report/sections/ref.bib @@ -13,4 +13,11 @@ @Article{gottesmanknill pages = {19}, eprinttype = {arxiv}, eprint = {quant-ph/9807006} +} +@online{controlslikevalues, + author = {Craig Gidney}, + title = {Treating Control like Values}, + year = 2015, + url = {http://algorithmicassertions.com/impractical-experiments/2015/05/17/Treating-Controls-like-Values.html}, + urldate = {2016-10-09} } \ No newline at end of file diff --git a/Report/sections/simulation.tex b/Report/sections/simulation.tex new file mode 100644 index 0000000..92ac1fc --- /dev/null +++ b/Report/sections/simulation.tex @@ -0,0 +1,104 @@ +\documentclass[../main.tex]{subfiles} + +\begin{document} +When thinking of simulating a Quantum Computer, there are a number of possible ways to implement it, depending on what you want from your simulator. +Regardless of what method, it will always get exponentially slower as you add more qubits to simulate, as the number of amplitudes you need to store is \(2^n\). +To get the most accurate simulation, you need to also simulate 'Decoherence', which is where the system will loose information by the outside environment, although the simulator detailed here is called an 'Ideal' Simulator, as it doesn't also simulate Decoherence. +In this project, the simulator will be built upon vector-matrix opperations. + +\subsection{Quantum Register} +To first start the simulator, you have to have a new quantum register object. When a new Quantum Register is created, it creates a new \(2^n\) dimensional vector of zero, and then it sets the first 0 to 1. This is the same as representing an n qubit state, and setting all n qubits to the state \(\lvert0\rangle\). Remember: + +$$ +\lvert q_1 q_2...q_n \rangle = \lvert q1 \rangle \otimes \lvert q2 \rangle \otimes ... \otimes \lvert q_n \rangle +$$ + +So therefore, the vector that must be stored for 4 qubits in the state of 0000 is: + +$$ +\lvert0000\rangle = \lvert0\rangle \otimes \lvert0\rangle \otimes \lvert0\rangle \otimes \lvert0\rangle = \left( \begin{matrix} 1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \end{matrix} \right) +$$ + +When a new Quantum Register Is Defined, it stores the vector, so that gates can be applied to it. + +For Source Code see the \emph{QuantumRegister} Class, in the \emph{\_\_init\_\_} function. + +\subsection{Matrix Generation} +If you look at the gates defined in the Previous Section, 'Quantum Logic Gates' (For Example, Equation (3)), they are all either \(2\times2\) or \(4\times4\) Matrices, which means that they can only be applied to either a 2 or 4 dimensional vector. This is a problem for our computational model, as we create a large \(2^n\) Dimensional Vector. + +\subsubsection{Expanding Single Qubit Gates} +Essentially, what we are trying to do it take a 2x2 matrix, and scale it up, so that it a \(2^n\) x \(2^n\) matrix. Whats important, is that the new matrix must only affect the qubit its targeting. For example, if I had a 4 Qubit Register, and I wanted to apply an \(X\) Gate to the 3rd Qubit, The equation for that new matrix is \(X_{3,4} = Id \otimes Id \otimes X \otimes Id \), with \(Id\) Being a 2x2 Identity Matrix. \\ +To generalise this further, to create the gate \(G_{m,n}\) (With \(n\) being the number of qubits in the register, \(m\) being the number of the qubit the gate will act on, and \(G\) Being the 2x2 gate that will be applied to that qubit), +you can use the equation: + +\begin{equation} + G_{m,n} = \underset{i=1}{\overset{n}{\otimes}} + \begin{cases} + G & \text{if} \quad i = m \\ + Id & \text{if} \quad i \neq m + \end{cases} +\end{equation} + +(Note: \(\underset{i=1}{\overset{n}{\otimes}}\) is like \(\underset{i=1}{\overset{n}{\sum}}\), but using the kronecker product, instead of the sum.) + +\subsubsection{Expanding Multi-Qubit Gates} +Focusing on Controlled Gates, there are a number of ways to expand / scale up multi-qubit gates, but most of them are quite long winded (See the appendix for a general expansion method), +but the way that the CNOT / Controlled X Gate is implemented in the simulator, is using a Input-Output like structure to generate a new matrix. \\ +There is no equation for this gate (Again, see the appendices for a full, generalised mathematical solution), but the generation method for this simulator can be shown using the source code. \\ \\ +See the \emph{Gate} class, and the \emph{generateGate} method. + +\subsection{Applying Gates} +Once there is a state vector and a full, unitary matrix to apply to it, +you can then apply the gate by using the dot product of the state or amplitude vector (\(\psi\)), and the matrix of the gate \(G\) \\ +\begin{equation} + \lvert\psi\rangle \cdot G +\end{equation} + +For example, to apply a Pauli-X Gate (Not Gate) to the second qubit of a 2-Qubit Register, it would look as shown (Keep in mind the previous Gate Matrix Generation Equations): + +$$ + Id = \left [\begin{matrix} + 1 && 0 \\ + 0 && 1 + \end{matrix}\right] +$$ + \\ +$$ + X = \left [\begin{matrix} + 0 && 1 \\ + 1 && 0 + \end{matrix}\right] +$$ + \\ +$$ + X_{2,2} = Id \otimes X = \left [\begin{matrix} + 0 && 1 && 0 && 0 \\ + 1 && 0 && 0 && 0 \\ + 0 && 0 && 0 && 1 \\ + 0 && 0 && 1 && 0 + \end{matrix}\right] +$$ + +$$ +\lvert00\rangle \cdot X_{2,2} = \left[\begin{matrix} + 0 && 1 && 0 && 0 \\ + 1 && 0 && 0 && 0 \\ + 0 && 0 && 0 && 1 \\ + 0 && 0 && 1 && 0 +\end{matrix}\right] \cdot \left[\begin{matrix} + 1 \\ + 0 \\ + 0 \\ + 0 \\ +\end{matrix}\right] = \left[\begin{matrix} + 0 \\ + 1 \\ + 0 \\ + 0 \\ +\end{matrix}\right] = \lvert01\rangle +$$ + + +\end{document} + +