top of page

The Building Blocks of Quantum Computing

Everyone remembers playing with Legos. Some of us than began playing with computers, hardware or software, maybe both. The link here should be obvious, given the name of the title, but Lego blocks, hardware components, and lines of code, are all used for the same purpose; to create.


Thus, it makes sense in a blog series to start from the foundations and work our way up the every increasingly difficult mountain that is quantum computing.


Below is the most basic quantum gate we can use as it is the equivalent of a NOT gate in classical computing, more documentation and explanation can be found here. QuantumCircuit initializes 1 qubit and 1classical bit that we will use to measure the output of things done to our qubit.


This puts both bits in |0> and 0 state respectively. Once we apply the Pauli X gate to our qubit, just as the NOT gate does in classical computing, the X gate, likewise, here flips the state vector of the qubit and our result will be |1> being the new state of the qubit.


Gates such as these are critical in quantum circuits as they represent the logic by which we are able to code algorithms like Shor's and Grover's, please be aware that these require pretty extensive math knowledge in order to conceptualize, if unfamiliar. This and this are easier to understand and digest videos exampling both.


Plotting the state vector on the the Bloch sphere gives an easy visualization of what is happening during the manipulation of the qubit. This was a brand new concept to me when starting this journey. I have never taken any physics advanced enough to introduce this concept. However, due to the strange nature of this visual model, Qiskit has put together an interactive application called Grok the Bloch Sphere, which can be found here. I was surprised by how useful that site was at helping me "grok" something that had made me scratch my head for while.


As a brief aside, "grok" or "groking" something is a call to one of my favorite pieces of literature of all time, A Stranger in a Strange Land by Robert Heinlein, published in the early 70's. Long story short, a man comes from Mars to Earth and uses the term "grok", which perplexes the earthlings. No exact definition is given in the novel, as, at least to my linguistic knowledge, alien languages cannot be mapped directly onto English. It is however spoken about in a roundabout manner, leading the reader to have a suspicion of "grok" to mean: to understand, acknowledge, and accept the totality of the existence of the thing being grokked, good and bad, so deeply and intensely, as to envelope oneself in the non-possibility of existence continuing without this knowledge. The Qiskit community aptly named this tool.


Thank you for letting me have my literary indulgence.


Now, secondly, the Hadamard Gate is essential to any type of quantum computing, as this gate puts the qubit it acts upon into a superposition between |0> and |1>. Again, I would like to note that quantum computing relies on the principals of quantum mechanics, one of the most difficult to grok subjects known to man. Click this link to learn more about the Hadamard Gate. Superposition, simply stated, means that the qubit is in all possible positions it can be in, at once. This sounds impossible, but so does everything else in the realm of the quantum.


Code for this is not very different from the above, just calling a different gate to apply to to circuit.


If the rest of the code is unfamiliar take a look at my previous blog posts, as they will explain in more detail what is being done.


Notice that both the state vector and it's representation on the Bloch sphere indicate that the qubit is no longer in the initialized state of |0>, nor is it in the |1> state either, as it was in our previous example with NOT or X Gate.


Having the ability to put qubits into superposition is helpful for all of the calculations and algorithms we will be writing as it is the first step in creating a state of entanglement between two qubits.


As with most of the concepts I have touched on in this post, entanglement is a tricky idea to get your head around if you have never thought about things within the quantum-framework. This video and this article should be enough to get the basics down, however, here is the link for the Wikipedia page.


It is only after understanding the importance of the the Hadamard Gate, Superposition, and Entanglement that we are able to begin to understand the power that quantum computing potentially has to offer. I will go further into the problems that quantum computing is positioned to solve, and the specifics on the advantages it has over classical computing in another blog post in the future, for now, the technical discussion.


Before I discuss what is going on in this last code snippet, I would like, as an exercise, for you to read the code and try to decipher what is happening first.

It may seem like a lot but this is actually quite simple once time is taken to consider it thoroughly. This is how you would code entanglement between two qubits, or what is known as a Bell state. John Stewart Bell, the man whom this state is named, is a titan in the world of quantum mechanics and I high suggest reading up on all of his contributions to science.


A Hadamard Gate was applied to the zeroth qubit in our system, this is technically the "first" qubit, however, this is how coders index objects, so, zero is one in a list of things. A gate we have not talked about yet, a CNOT or CX Gate will be applied to the zeroth qubit (q0) with its target being the first qubit (q1). CX is a conditional gate that performs and X on the target qubit (q1) if that state of the control qubit (q0) is |1>.


In the above example, the measurement of the circuit, which maps [q0,q1] to [c0,c1], collapses the superposition state into either |0> or |1>, with a 50/50 chance of becoming either. However, it is possible to represent the entangled state on the Bloch sphere, simply omit the measurement of the circuit. This will allow the superposition to remain stable and the printed Bloch sphere would have arrows in the 1st dimension, represented as a dot within the middle of the sphere. Creating this entangled state is the first step towards quantum information teleportation.


With these simple tools in the metaphorical bag of tricks it is possible to do things once thought impossible. These three operations are paramount to the whole of quantum computing and are fundamental in progressing our ability to exploit the power of this technology.


Writing this post and giving myself the repeated exposure to these concepts has helped give me the confidence to move forward in this journey. I will be going next into the first simple few algorithms we can use to leverage the advantage the QC comes with, current thoughts are for a post on the teleportation algorithm and the Deutsch-Jozsa algorithm, as they are practical applications of the skills learned during the last few months.




bottom of page