Let’s dive right into coding after making sure you are working in your preferred directory. Let’s first start by creating a quantum circuit made out of a quantum register and a classical register. to do so, you will need to import qiskit, and define some variables. If you are familiar with Python, you will find ease at doing this, since, under the hood, we are just coding in Python.

python code

At this point, I want to introduce a mobile application called Hello Quantum. It is made by IBM and it looks very similar to a puzzle game. However, it explains how the quantum gates work and their behavior very well. I suggest playing with it for a little bit if you are interested in learning more about the circuit composition. The app’s icon looks like this:Qubit

Back to the code, now we can add operations to our circuit. We previously defined two registers (one quantum and one classical) and made a circuit out of them. Next, let’s apply a Hadamard gate on the quantum register and a cnot (controlled not) gate on the classical register.



Let’s add the measurements to the circuit we just created. Since we want to do the measurements with and without a Hadamard gate beforehand, it will be easier to create separate circuits for the measurements and combine them with our entangling circuit.

The measure_Z circuit will just do our measurement on the standard basis. Afterward, we use a qiskit function to store the result in the classical register

We’ll call our second measure measure_X and we’ll apply a Hadamard gate to it before the measurement.

Now that we have defined our measurement circuits, we can append them to our entangling circuit, creating two new circuits that we will label test_Z and test_X.

These are all the previous commands executed successfully to help make sure you nail them.python code

Now we get to the more exciting stuff! Real Quantum Computer connection!

Navigate to https://quantumexperience.ng.bluemix.net/qx and make an account and login. Once you are logged in, click on the avatar picture on the top right corner and go to account, then to advanced. You will be able to see a similar screen to this.imq

Copy your API Token, we will use it shortly.

Next, import IBMQ and get ready to connect to a quantum computer!

Make sure you pass in your API token as a string. Now if you run IBMQ.backend() you should be able to see all the backends available to you by IBM. If you look closely, they are under IBM Q Backend Acces on your IBM Q account. Now let’s define a variable for our backend and start executing some code on the QC.

backend = IBMQ.get_backend('ibmqx4')

I chose ibmqx4 for this example, but this is purely up to you what to use. Sometimes some backends go on maintenance, so I always check what backends are available before I choose one. Here is a quick summary of the backend connecting.

Now, remember the test jobs that we were preparing out of the circuits earlier? Now we are going to use them! let’s create a job this way:

Next, let’s execute the job.status() a few times, to monitor the status of the job. It should be queued if there are a lot of use for the quantum machines (or if you picked a busy one, a quick fix is to go back and redefine the variable for the backend with a different provider!), and after a bit, it should succeed. This is what I got from following that.job.status

At this point, the next step is to get the result for the execution of the job.


Those were the results of my execution. Yours may vary. The interpretation of that is that because of the execution on a quantum computer, we have shown the existence of the “Bell State”, which is when a Qubit is in the right middle between a 0 and 1 and, and only happens in a quantum system. That is given to us by the middle values on the x-axis (01 and 10), which represents the “Bell state”, otherwise known as the entangled state.

Don’t believe me? See for yourself! let’s wrap this up by executing the same job on a local simulator (not quantum). These are the commands you will need to connect to Aer and use their local simulator, and re-execute the past job:

Here are the results:See.result

As you see from the graphs, there is no entangled state. All boring regular 0 and 1 bits. However, this was just your proof that you were using a quantum computer!

Congratulations if you made it this far and were able to connect to the IBM Q backend and execute your first job!

I want to thank Mr. McClure for being my biggest resource for this article. I utilized a lot of his Youtube video, I suggest you check it out!

Source link

Write A Comment