There is now a really easy way to get into Quantum Computing and Quantum Programming. Strangeworks have made a real effort with their new platform in making it easy and simply to use, intuitive with all the functionality that you need. If you want an outline of the new service currently in beta with Strangeworks, look at a previous article on the Strangeworks Community Platform.
Here we will walk through an example with Strangeworks provided from one of the numerous libraries that exist that can help users understand quantum algorithms and developments. The libraries provide some off the peg examples written in one of the quantum programming languages that can be loaded in seconds and run immediately. This means for learners there is not the hassle of trying to download the code, set up access to a QC and then after some time faffing around run it. The process literally takes just seconds as everything can be done from within the platform.
Strangeworks Project Library
When you first login to the platform you’ll see an option to look at the Project library. Let us select the most basic example “Play with one Qubit“, which will give us one qubit that we can explore using the QASM language. After selecting that library we can add it and then work on it after cloning the project. The code below shows how one can set up a qubit and classic register in order to manipulate it with many commands commented out with the
//. For example if we look at the command
x qubit; this will take the state
0 and flip it to
1 and vice versa from
OPENQASM 2.0; // Open Quantum Assembly Language to write basic quantum circiutis // QASM documentation and examples https://arxiv.org/abs/1707.03429 include "qelib1.inc"; // standard header with basic library qreg qubit; // Create a register of just one qubit called qubit creg classicalbit; // Create a register of just one bit called classicalbit // z qubit; // pi rotation about the Z-axis // x qubit; // pi rotation about the X-axis y qubit; // pi rotation about the Y-axis // h qubit; // The combination of two rotations, pi about the Z-axis followed by pi/2 about the Y-axis // s qubit; // S-gate, square root of Z gate // sdg qubit; // conjugate of S-gate // t qubit; // Phase-gate, conjugate of square root of S-gate // tdg qubit; // conjugate of Phase-gate // rx(0) // rotation around X-axis // ry(0) // rotation around Y-axis // rz(0) // rotation around Z axis ry(-pi/7) qubit; barrier qubit; measure qubit -> classicalbit;
There are plenty of other commands such as
rx(0) which performs a rotation around the x axis. The code that is un commented is
y qubit; and
ry(-pi/7) qubit; which performs a rotation around the y-axis. The last-line measures the qubit after we have performed a rotation on the qubit and puts the output in classical register.
measure qubit -> classicalbit;
Lets run the code as it is – we don’t need to change anything. Go to the top right button which says “run code” and hit the button. Choose the number of iterations – lets go for
10. Wait a while and we get the results.
The results show that everything (all
10 of our samples result in an output of
1). Lets now make a simple modification with a Hadamard gate. We can do this by replacing both the y operations with
h qubit; which performs a Hadamard on our only qubit.
What does the Hadamard (H) do? This is a 2×2 matrix that performs the following operation. It takes as input a zero or one and puts that state into an equal superposition of two states. It takes a 0 and makes this into an equal super position of
1with the same constant – meaning that we should see equal numbers of
This means we end up with a state as follows
from our original state of
If we now look at the output from take of our samples we can see what get. Below shows the output results from
10 samples/iterations, which highlight we get 6 in the
0 state and 4 in the
The reason that we do not have 5 in each is due to the statistical and probabilistic nature. Let’s now run
100 samples and see if we get closer to a 50/50 % split. Illustrated below we can see we get 51 to 49. Pretty close. Thus we have seen one of the widely used operators in Quantum Computing and how it can turn a zero into a superposition using Strangeworks Community Platform.