Programming Quantum Algorithms on a Quantum Computer
IBM accepted my request to use their quantum computer to develop my own experiments, and even run them in, on the world's first fullycontrollable quantum processor through the IBM Cloud located in Yorktown Heights, New York, I'm going to write about my experience and share documentation.
I love quantum mechanics since I was a kid, I read all the books aviable in the little library near my home, and magazines too, I can't forget this image:
In November 11, 1989, Don Eigler and colleagues drew the IBM logo in atoms. He and his team were able to literally move 35 xenon atoms on a background of copper atoms to spell out IBM, when I see this image, I thought: "Some day, I'm going to have a Company, and I'm going to manipulate atoms to draw my logo", when I was 15, a cranioencephalic trauma changed my life, I forget a lot of information, and I never studied physics, anyway, I did something better than draw my logo in atoms, this is a dream come true, I manipulated quantum states to obtain this:
Execution results
7NY.US experiment. Quantum algorithm by Miguel Angel Vargas Cruz
Executed on: May 5, 2016 1:49:49 AM
Results date: May 5, 2016 1:50:10 AM
Number of shots: 1
Q_{0} 0⟩  M  
Q_{1} 0⟩  M  
Q_{2} 0⟩  X  M 
Q_{3} 0⟩  X  M 
Q_{4} 0⟩  X  M 
Distribution
1  
0.875  
0.75  
0.625  
0.5  
0.375  
0.25  
0.125  
0  
00111 
Device Calibration: 20160504 15:52
Q_{0} T_{1}: 54.8μs T_{2}: 60.9μs ε_{g}: 3.2×10^{3} ε_{r}: 4.1×10^{2} ε^{02}_{g}: 6.43×10^{2}  Q_{1} T_{1}: 78.5μs T_{2}: 109.2μs ε_{g}: 1.8×10^{3} ε_{r}: 1.8×10^{2} ε^{12}_{g}: 3.97×10^{2} 
Q_{2} T_{1}: 66.7μs T_{2}: 61.9μs ε_{g}: 2.6×10^{3} ε_{r}: 2.1×10^{2}  Q_{3} T_{1}: 59.7μs T_{2}: 51.6μs ε_{g}: 4.8×10^{3} ε_{r}: 4.1×10^{2} ε^{32}_{g}: 6.07×10^{2} 
Q_{4} T_{1}: 79.4μs T_{2}: 80.2μs ε_{g}: 1.8×10^{3} ε_{r}: 3.7×10^{2} ε^{42}_{g}: 3.48×10^{2} 
Bloch measurement
Q_{0} 0⟩  BM  
Q_{1} 0⟩  BM  
Q_{2} 0⟩  X  BM 
Q_{3} 0⟩  X  BM 
Q_{4} 0⟩  X  BM 
Thanks IBM!!!, is so simple to understand if you are a developer, the quantum composer I use, contains four classes of gates, each denoted by a letter, in this case I only used Pauli X gate is known as an X_{π}rotation and it takes 0⟩→X0⟩=1⟩ in other words, it flips the zero to a one, or vice versa, this is why it is also commonly referred to as a bitflip. The first class of gates (ID) represents an idle operation on the qubit for a time equal to the singlequbit gate duration. The second class of gates X, Y, Z represents a group known as Pauli operators, which represent bitflips (X, which is a classical NOT), phaseflips (Z), and a combined bitflip and phaseflip (Y). The third class H, S, S† represents Clifford gates, for generating quantum superpositions, along with the all important CNOT twoqubit gate which is necessary for entanglement. The final class T, T†, represents gates that are required for universal control.
A quantum algorithm (circuit) begins by preparing the qubits in welldefined states (here the ground state, 0⟩), then executing a series of onequbit and twoqubit gates in time, followed by a measurement of the qubits. There are two options for measurement: a standard measurement which is a simple Z projection (M), or a Bloch measurement (BM) which is a Bloch sphere projection to indicate the final qubit state having been projected along the X, Y and Z axes. After measurement, the qubit state becomes classical (either 0⟩ or 1⟩ but never a quantum superposition); this is represented by the double line that appears after a measurement operation. This is the reference for the next experiments in this article.
Bloch Sphere
Probabilities in the standard basis are not enough to specify a quantum state because it cannot capture the phase of the superposition. A convenient representation for a qubit is the Bloch sphere.
If we define a qubit state by ψ⟩=cos(θ/2)0⟩+e^{iφ}sin(θ/2)1⟩ where θ and φ are defined in the picture, we see that there is a onetoone correspondence between pure qubit states (ℂ^{2}) and the points on the surface of a unit sphere (ℝ^{3}). This is significant because now we can simply visualize qubit states and gates. We can reconstruct an arbitrary unknown qubit state ψ⟩ by measuring the Bloch vector, whose vector components are the expectation values of the three Pauli operators, given by ⟨X⟩=tr(ψ⟩⟨ψX), ⟨Y⟩=tr(ψ⟩⟨ψY), and ⟨Z⟩=tr(ψ⟩⟨ψZ). The state is given by ψ⟩⟨ψ=(I+⟨X⟩X+⟨Y⟩Y+⟨Z⟩Z)/2.
Each expectation value ⟨Q⟩ can be obtained experimentally by first preparing the state, rotating the standard basis frame to lie along the corresponding axis, and making a measurement in the standard basis. The probabilities of obtaining the two possible outcomes 0 and 1 are used to evaluate the desired expectation value via ⟨Q⟩=P(0)P(1). As an example, let's look at measuring the expectation value of X, ⟨X⟩=tr(ψ⟩⟨ψX), depicted in the circuit below. Once ψ⟩ is prepared we implement the gate H that exchanges Z to X, then we make a measurement in the standard basis. The desired expectation value is given by ⟨X⟩=P(0)P(1). Similarly, we can use the S†H gate to measure ⟨Y⟩.
Looks so simple but have been an epic experience for me, now, it's time to share you information about the quantum computer and quantum mechanics basics, to finish with experiments.
About quantum computers
Today's computers perform calculations and process information using the classical model of computation, in this model, all information is reducible to bits, which can take the values of either 0 or 1, and all processing can be performed via simple logic gates (AND, OR, NOT, NAND) acting on one or two bits at a time. At any point in its computation, a classical computer's state is entirely determined by the states of all its bits, so that a computer with n bits can exist in one of 2^{n} possible states, ranging from 00...0 to 11...1, a quantum computer also has bits, just like any computer, but instead of 0 and 1, its quantum bits, or qubits, can represent a 0, 1, or both at once, a property known as superposition. This by itself is not much help, since a computer whose bits can be intermediate between 0 and 1 is just an analog computer, scarcely more powerful than an ordinary digital computer. A quantum computer takes advantage of a special kind of superposition that allows for exponentially many logical states at once, all the states from 00...0⟩ and 11...1⟩.
The vast majority of these quantum superpositions, and the ones most useful for quantum computation, are entangled they are states of the whole computer that do not correspond to any assignment of digital or analog states of the individual qubits. The quantum mechanics have some counterintuitive ideas, for example a physical system in a perfectly definite state can still behave randomly, or two systems that are too far apart to influence each other can nevertheless behave in ways that, though individually random, are somehow strongly correlated, anyway, this is great.
The Quantum Bit (Qubit)
A qubit is a quantum system consisting of two levels, labeled 0⟩ and 1⟩ (here we are using Dirac's braket notation) and is represented by a twodimensional vector space over the complex numbers ℂ^{2}. This means that a qubit takes two complex numbers to fully describe it. The computational (or standard) basis corresponds to the two levels 0⟩ and 1⟩, and corresponds to the following vectors:
The qubit does not always have to be in just 0⟩ or 1⟩ but can be in any quantum state, denoted ψ⟩, which can be any superposition ψ⟩=α0⟩+β1⟩, of the basis vectors. The superposition quantities α and β are complex numbers; together they obey α2+β2=1.
Interesting things happen when quantum systems are measured, or observed. Quantum measurement is described by the Born rule. In particular, if a qubit that is in some state ψ⟩ is measured in the standard basis, the result 0 is obtained with probability α2 and the result 1 is obtained with the complementary probability β2. A point of fascination is that a quantum measurement takes any superposition state of the qubit, and projects it to either the state 0⟩ or the state 1⟩ with a probability determined from the parameters of the superposition.
In IBM Quantum Lab are able the temperature cold enough (15 milliKelvin in a dilution refrigerator) that there is no ambient noise or heat to excite the superconducting qubit; after the system has gotten cold enough (for a few days), the superconducting qubit reaches equilibrium down to the ground state 0⟩, the IBM quantum computer uses a type of qubit called a superconducting transmon qubit, which is made from superconducting materials such as niobium and aluminum, patterned on a silicon substrate.
Let's talk about laws
Quantum is a system like everything else. To each physical system there corresponds a Hilbert space that is a linear vector space with complex coefficients and inner products ⟨φψ⟩=Σ_{i}φ_{i}^{*}ψ_{i} of dimensionality equal to the system's maximum number of reliably distinguishable states:
A quantum state is a configuration of the system. Each direction (ray) in the Hilbert space corresponds to a possible state of the system, other qubit states include:
with two states being reliably distinguishable if and only if their directions are orthogonal (inner product is zero).
A quantum state changes; it naturally wants to evolve, but it can always be undone. Evolution of a closed system is a unitary (unitary means linear and inner product preserving) transformation on its Hilbert space.
Scaling  how parts make a whole. The Hilbert space of a composite system is the tensor product of the Hilbert space of the parts, a twoqubit system can exist in a product state such as 00⟩ or 0+⟩ but also in an entangled state (00⟩+11⟩)/√2, in which neither qubit has a definite state, even though the pair together does.
Quantum measurements are probabilistic. Each possible measurement (measurement causes the system to behave probabilistically and forget its premeasurement state, unless that state happens to lie entirely with one of the subspaces Π_{j}) on a system corresponds to a resolution of it's Hilbert space into orthogonal subspaces {Π_{j}} where Σ_{j}Π_{j}=1, on state ψ⟩ the result j occurs with probability P(j)=⟩ψπ_{j}ψ⟩ and the state after the measurement is ψ_{j}⟩=π_{j}ψ⟩/√P_{j}.
Excited State and Pauli Operators
Quantum gates, or operations, are typically represented as matrices. A gate that acts on one qubit is represented by a 2×2 unitary matrix. Since quantum operations need to be reversible and preserve probability amplitudes, the matrices must be unitary. The result of the quantum gate is found by multiplying the matrix representing the gate with the vector representing the quantum state.
ψ'⟩=Uψ⟩ where U†U=1 (A† represents the complex conjugation and transpose of any matrix A).
A common group of gates, known as the Pauli Operators, are represented by the matrices:
Executing Pauli Operators
Pauli X
Distribution
Bloch measurement

Pauli Y
Distribution
Bloch measurement

Pauli Z
Distribution
Bloch measurement

Superposition
Superposition is the concept that adding quantum states together (similar to overlaying two waves) results in a new quantum state. To make superpositions we need to expand our set of gates to include {H,S,S†}, and are represented by the matrices:
H known as the Hadamard gate, on one of the qubits that has been prepared in the 0⟩ state and then followed by the standard measurement. The qubit should spend half it's time in the 0⟩ state and the other half in the 1⟩ state. Before the measurement forced it to choose, the qubit was in both states at once. This is part of the reason for the oftenmisused analogy that a quantum computer does everything at once.
Applying the H gate to 0⟩ does a size2 discrete Fourier transform, making the state +⟩=(1/√2)(0⟩+1⟩), this is the standard representation of a superposition state. We can define the state ⟩=(1/√2)(0⟩1⟩), which with +⟩ forms a new basis called the diagonal (or conjugate) basis. The H makes the above superposition and then the Z flips the phase (1⟩ to 1⟩).
Trying Superposition (+) X Measurement and Superposition () X Measurement, we should find that nearly 100% of the time the outcome is 0 and 1 respectively. That is, if we make a measurement in the standard basis, the outcome is completely uniform, but in the diagonal basis, it has deterministic outcome. No measurement can distinguish all four kinds of states 0⟩, 1⟩, +⟩, ⟩. This is not a limitation of the measurement, but a fundamental consequence of the uncertainty principle.
The circular or Y basis: ⟳⟩=(1/√2)(0⟩+i1⟩), ↺⟩=(1/√2)(0⟩i1⟩). To make the ⟳⟩ state we need to use the additional gate S, the phase gate. This gate applies a complex phase to 1⟩, via the application of an H followed by an S gate.
Like the above example, measurement in the standard basis will not give you different statistics. Even measurement in the diagonal basis will be random. To measure in this basis we must rotate the standard basis Z to the circular basis Y. To do this, use an S† followed by H before your measurement.
Superpositions algorithms
Superposition (+)
Distribution
Bloch measurement

Superposition ()
Distribution
Bloch measurement

Superposition (+)
Distribution
Bloch measurement

Superposition ()
Distribution
Bloch measurement

Superposition (+i)
Distribution
Bloch measurement

Superposition (i)
Distribution
Bloch measurement

Decoherence
Real quantum computers must deal with decoherence, or the loss of information due to environmental disturbances (noise). The Bloch vector formalism is sufficient to describe the state of the system under decoherence processes. The pure states so far have ρ=ψ⟩⟨ψ and a Bloch vector of length 1, touching the surface of the Bloch sphere. Decoherence causes our quantum states to become mixed states, which have a density matrix ρ that can be written as a sum over pure states ρ=σ_{k}p_{k}ψ_{k}⟩⟨ψ_{k} and a Bloch vector that sits inside the Bloch sphere ⟨X⟩2+⟨Y⟩2+⟨Z⟩2<1.
Energy relaxation and T_{1}. One important decoherence process is called energy relaxation, where the excited 1⟩ state decays toward the ground state 0⟩. The time constant of this process, T_{1}, is an extremely important figureofmerit for any implementation of quantum computing.
Dephasing and T_{2}. Dephasing is another decoherence process, and unlike energy relaxation, it affects only superposition states. It can be understood solely in a quantum setting as it has no classical analog. The time constant T_{2} includes the effect of dephasing as well as energy relaxation, and is another crucial figureofmerit.
Follow us on Facebook, comment about the post and don't forget to share.