Learning About Quantum Computers at a Hackathon

Here at Visiba Care we had a two day Hackathon with the overall goal of learning and trying new things we otherwise would not have explored. To get away from the office we in the tech department rented a house and divided ourselves into groups with different project and started coding. Despite some distractions along the way like table tennis, Mario Kart, an indoor swimming pool and board games many of us produced some impressive projects. At the end we held a presentation of the result.

I personally decided to learn about quantum algorithms and quantum computers. My goal was to learn about fundamental concepts such as quantum gates and qubits and to run a simple quantum algorithm on a real quantum computer. I did indeed learn a lot, but I barely scratched the surface. This post is about how and what I learned during my project.

Resources and Development Environment

Learning resources

I started by signing up to a website called Brilliant.org which offers a course in Quantum Computing using interactive examples and quizzes. This seemed like a suitable place to start since the target audience of the course are people with degrees in computer science who have previously never explored quantum computers. It was here I learned about the qubit, quantum gates and the Bloch sphere, all of which I have written more about below.

I then moved on to Microsoft’s documentation for their Quantum Development Kit. Here you can find beginner level and advanced tutorials on how to implement quantum algorithms that do everything from generating random numbers to implement Grover Search. I mostly used this site to look up references and documentation for the Q# programming language. I found several of the tutorials a bit overwhelming without more in-depth knowledge about the math and core concept of Quantum computing.

Finally, of course I learned by coding stuff myself. Experimenting with several types of gates, discovered what happens when you entangle qubits and writing simple console applications gave me some much-needed firsthand experience.

Q# and Quantum Development Kit

Microsoft offers something called Quantum Development Kit (QDK) and with it comes the open-source programming language Q# (Q-sharp). Q# reminded me a bit of a cross over between Kotlin and C# with a robust standard library and a functional approach to programming. You can run Q# applications on quantum simulators locally or you can run quantum jobs on Azure Quantum in the cloud.

Using the QDK in Visual Studio was my primary IDE during the project. I chose this over for example Python due to my previous experience with the Microsoft ecosystem and programming languages such as C#.

IBM and Qiskit

At the very end of the Hackathon, I briefly evaluated IBM Quantum Lab. IBM Quantum Lab offers you to work with Jupyter notebooks writing quantum algorithms with Qiskit. Qiskit is an open-source framework for working with quantum computing using Python as the programming language. Jupyter is a web-based interactive development environment which you can use to run and write your code directly in your browser.

I ended up writing a Qiskit script for generating a truly randomized Secret Santa chain. This generated chain will be used for this year’s Secret Santa event where people at the office give and receive gifts to and from one random person. I ran the script on one of IBM’s actual quantum computers which felt really cool.

Screenshot from IBM Quantum Lab where I generated the secret Santa chain

Quantum computing fundamentals

Why quantum computers?

It turns out that quantum computers can solve certain search problems exponentially faster than classical computers. This is due to qubits being able to represent multiple states at the same time because they can simultaneously be both 1 and 0. Also, any classical algorithm that can be quantized to take advantage of a quantum processor will see a huge performance boost when run in a quantum computer. Search optimizations can be taken advantage of in areas such as:

  • AI — Processing massive quantities of data faster and more efficiently
  • Stock market — Monte Carlo simulations
  • Data security — Prime factorization
  • Biology — Simulating multiple molecular structures simultaneously

Why aren’t quantum computers mainstream yet?

Currently, quantum computers are only accessible to certain universities and larger research institutes. This is due to qubits being extremely sensitive to outside interference and the quantum processors requiring being cooled down to absolute zero. Years or even decades of research into the quantum computer field will still be required to find viable solutions to these obstacles.

Qubits

A Qubit can do everything a normal bit can and any algorithm which runs on a classical computer can also run on a quantum computer. When you measure a qubit in a superposition it will permanently collapse into a computational state of 1 or 0. All other information about the qubit’s previous state is lost.

Operations made on qubits before measurement are reversible. This means that a qubit that has been put in a superposition can be reset back to its initial state again, but as mentioned previously, only if no measurements have been made.

Qubits can also be entangled with one another so that the measurement of one directly affects the outcome of measuring the other. This is one of the most powerful tools in quantum computing arsenal and is a fundamental law in quantum physics. Further down in the code examples, I show one type of entanglement called the Bell state. Bell state is when you entangle two qubits so that after measuring one the other will also always return the same measurement.

Quantum gates and the Bloch sphere

Something that I found particularly useful for visualizing how quantum gates affect qubits was the so-called Bloch sphere. The Bloch sphere is a geometrical representation of a qubit’s current 3D state. I found it immensely helpful for visualizing how all the different quantum gates ended up affecting the qubit’s current state.

Credit: https://en.wikipedia.org/wiki/Bloch_sphere

I used and experimented with the following quantum gates:

H = Hadamard gate. Puts a qubit into a super position.

X, Y, Z = Pauli gates. Inverts the qubit’s current state.

CNOT = Controlled note gate. Entangles two qubits so they will always measure the same value.

M = Measures the qubit’s current value and collapses the super position.

Quantum oracles

Quantum oracles are useful for doing direct comparisons between classical and quantum algorithms since they abstract away parts of the circuit that are pure implementation details. This makes it clearer which parts of the circuit is the algorithm itself and which parts may differ depending on the implementation you choose.

Results

At the end of the hackathon I presented my project to my colleagues via a PowerPoint presentation covering all the topics I’ve written about in this post. I also showed the Q# functions I wrote and what they produced as output.

Q# code for putting two qubits into a super position:

Output after running the SuperPosition operation
operation SuperPosition() : Unit {
//Allocate two qubits with value 0
use qs = Qubit[2];
//Put both qubits into a superposition with the Hadamard gate
for qubit in qs {
H(qubit);
}
//Measure the two qubits. They have a 50% chance of being either 1 or 0
let res = M(qs[0]);
let res2 = M(qs[1]);
Message($"SuperPosition: {res}, {res2}");
}

Q# code for random number generator:

Output after running the RandomNumberGenerator operation
operation RandomNumberGenerator() : Unit {
//We want the random number to be 3 bits in size (between 0 and 7). Here true = 1 and false = 0 for the Bool array.
mutable output = new Bool[3];
//We reuse the same qubit for every loop iteration
use q = Qubit() {
for i in 0 .. 2 {
H(q);
let m = M(q);
let bit = m == One ? true | false;
set output w/= i <- bit;
}
}
//Convert the Bool array into a regular Integer
let result = BoolArrayAsInt(output);
Message($"RandomNumberGenerator: {result}");
}

Q# code for putting two qubits into a bell state:

Output after running the BellState operation
operation BellState() : Unit {
use (q0, q1) = (Qubit(), Qubit());
H(q0);
//The Controlled NOT-gate entangles the two qubits so that after measuring one the other will also always return the same measurement
CNOT(q0, q1);
let res = M(q0);
let res2 = M(q1);
Message($"BellState: q0 = {res} q1 = {res2}");
}

Final Thoughts

This was by far the most interesting and difficult hackathon project I’ve tackled so far in my career. Trying to understand the quantum world really demanded me to think a bit outside the box and it took countless hours of reading and experimenting to even grasp basic concepts. Overall, I think the project was a huge success since I accomplished my established goal and received positive feedback for my presentation.

It is going to be exciting to follow the technological progress in the field of quantum computing and the many possibilities it will open for us in the future.

Philip Sandegren
App Developer at Visiba Care

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store