Quantum computers aren’t as mysterious as you think.

Does it look like a typical computer? Nope. Does it run on quantum mechanical principles that sound absolutely unreasonable? Most definitely. Do its proponents claim it can perform unimaginable computational feats? Many, many times—although reader discretion is strongly advised.

It’s really not so much a top-secret, super-exclusive secret machine run by Big Tech as it is a really, really good computer. Or at least, it will be someday. It may be a weird-looking one with massive potential for large-scale calculations across scientific fields, yes—but it’s still a computer, just like your laptop or smartphone.

Don’t believe me? Here at Giz, we’re all about trying things out for ourselves, and that’s exactly what I did—I tried coding on a quantum computer. For this hands-on, I took a trip to IBM’s Thomas J. Watson Research Center in Yorktown Heights, New York, where I had the opportunity to use a quantum computer to code a simple magic 8-ball.

As you’ll see, the steps I took in this demo are easily translatable for more complicated pursuits. I also need to disclose that I am tragically bad at coding. I can kind of understand code well enough to retrieve photos from websites, but that’s about it.

But here’s the thing: Even someone like me was able to follow what was going on during the demo. For the purposes of this post, I won’t be listing all the specific codes, but check out the video below for the actual demonstration. You can also find the code for the demo here.

A quick primer

Before we jump in, let’s go over some quantum computation basics. Very simply, quantum computers harness the quirky principles of quantum mechanics to perform feats that are potentially unthinkable for even today’s best supercomputers.

That gives them a wide variety of future applications, like extending the life of EV batteries, advancements in medical and basic research, and whatever extremely complex problem that we humans have yet to grasp the answer for.

We’ve still got ways to go before this becomes a reality, but as my brief attempt at quantum computing shows, some basic tasks are already within reach.

1. Decide on a problem

Like all computing problems, you first need to identify what it is you want to do, then decide on a program that’ll help you do that. For this demonstration, the goal was to create a magic 8-ball that provides one random answer out of eight possible outcomes. During the demonstration—which took place before Thanksgiving—I asked the magic 8-ball whether my flight to see my family in Minnesota would leave on time.

Qiskit Demo 8 Ball ResponseA list of potential answers to be drawn from the quantum 8-ball. © IBM

Sure, I could’ve done the same thing on a classical computer by generating a random integer between 1 and 9, but quantum computers are particularly good at generating truly random distributions, which I tested during the demonstration.

2. Map problem onto a quantum circuit

This step is one of two translation steps for quantum coding, in which you’re mapping a problem onto a quantum circuit. To do this, you first need a software development kit to run quantum circuits or build algorithms on quantum hardware. In this case, we used Qiskit, IBM’s open-source software stack that anyone can use to send code to the company’s quantum computers. Then, you install and load the necessary packages to prepare the workspace, after which you can set up a quantum circuit.

The basic unit of information in quantum computers is the qubit. Unlike classical binary bits (0 or 1), qubits can simultaneously represent numerous combinations of 0 and 1 in a phenomenon called superposition, according to MIT Technology Review. This capacity is what allows quantum computers to outperform classical computers in processing specific types of problems.

Since my magic 8-ball has eight responses, I’ll be setting up a quantum circuit that uses three qubits to encode eight possible outcomes (23 = 8). The next step is to add an operation to these qubits, which in this case means sending them through quantum gates. To be exact, the operation seen below (“qc.h”) places a qubit onto a “Hadamard gate,” which puts the qubits into a state of superposition.

Qiskit Demo 8 Ball Setup© IBM

Since the goal is to make some measurements from the qubit, the next couple of lines of code reflect commands that add measurements to the qubits and another one to help visualize the circuit before sending it to a quantum computer.

Qiskit Demo Q Circuit VisualizationA visualization of a quantum circuit, pre-transpilation. © IBM 3. Optimize for target hardware—and execute!

Believe it or not, that’s about it for how much original thought is required for this mini-project. The final steps are to connect to a real quantum computer, run a few translation commands, and ask it to solve the problem.

Connecting to a quantum computer is very simple and, to be honest, rather anticlimactic. The act itself takes just two lines of code to establish a connection to the backend, which for this demo was IBM’s Kingston, a Heron processor, located at a data center in Poughkeepsie, New York.

Ibm System 2IBM Quantum System Two at IBM’s Thomas J. Watson Research Center. This is a different system than what I used for the demo but contains the same Heron processors. © Adriano Contreras/Gizmodo

Then, the translation process, specifically transpilation, essentially reworks the code into instructions that a quantum computer natively supports. The command for this is somewhat of a mouthful, but this single line allows you to transpile your circuit and specify an optimization level for your task. Remember my quantum circuit from before? After transpilation, it looks like this:

Qiskit Demo Q Circuit Visualization TranspilationA visualization of a quantum circuit, post-transpilation. © IBM

Once that’s done, all that’s left is to specify to Kingston the number of samples I want to draw from my magic 8-ball. Sometimes it takes a bit for the computer to return results, since people worldwide can access the servers, but Qiskit provides a job ID in case you want to check again the next day. These operations are, again, fairly straightforward and are available at the demo page.

4. Make sense of the results

I cannot stress enough the similarities between quantum coding and classical coding. For instance, unpacking a quantum computer’s calculations so that they’re useful to me—that is, so I can represent them in a statistically practical way—mirrors how I’d filter the data in classical coding.

Assuming you have the visualization package for Qiskit, this is what you should get when running a code to ask the computer (back to classical in this case, since I’m now working with a dataset that Kingston ran for me):

Qiskit Demo Result Chart

The number labels of the x-axis represent the different answers from the magic 8-ball in the following order: “Yes” (001), “Not today” (001), “Definitely” (010), “Try again” (011), “Signs point to yes” (100), “Not likely” (101), “Sure thing!” (110), and “Outlook not so good” (111).

The counts on the y-axis represent how many times the quantum computer generated each answer out of the 10,000 draws I asked it to perform. So the answer to my question—the timeliness of my Minnesota flight—appears to be “sure thing.”

And as a matter of fact, my real flight actually left a little early.

Alternatively, I also tried drawing one outcome for a single answer, which was “Try again.” Okay, so the quantum 8-ball does not give the best planning advice.

Optional step: mull over the implications

This demo represents a very simple application of quantum computing, but the results shown in the histogram reflect some scientifically cool features of working with quantum computers. Notice how the different bars are slightly uneven in height. Some of the responses (like 010, “Definitely”) vary more than what you’d expect from the standard deviation of 8 random responses drawn 10,000 times.

That’s the effect of noise, in addition to the relatively small (yes, 10,000 is considered small) number of sampling attempts I had the computer do. Still, the variations aren’t too drastic, which speaks to the efficacy of quantum hardware.

For more complicated tasks, scientists will apply various techniques to correct for errors so that the results appear more consistent. Of course, these people (probably) aren’t coding quantum 8-balls so they can ask them if aliens exist. They have more advanced pursuits, like simulating a dizzying number of complex organic molecules in chemistry or generating truly random numbers for secure financial transactions.

And let me say this for the final time—this is something that you can do at home, right now! It’s a small taste of the stunning potential of quantum computing, which will continue to see great strides this year.