Learning Blueqat Step 1: Operations

Published by strangeworks (04/09/2021)

1 Qubit Operations

Here we start from the basic learning about quantum computing. To calculate on the quantum computer, we just make a circuit. Let's import blueqat and initialize the circuit first.
​import strangeworks.blueqat


Next we put some quantum logic gates on the circuit with the chain method after the initialized circuit. the .x[0] applies the X gate to the 0th qubit.


To get the result fo this circuit, we have to measure the result of the circuit. Let's but the measurement gates as .m[:]. ":" applies the measurement gate to all of the qubits. Add .run() with the number of shots to get the final result.


We get the result of "1" once. This is the result. Initially the circuit starts from 0 and applying the X gate flips the bit of the qubit from 0 to 1.

For more advanced use of the circuit, we can get the state amplitude (probability distribution from the state veector. We can get the state vector directly from the simulator with just .run() the circuit without measurement.


The result is the state vector.

2 Qubit Operations

The basic preparation is the same as the 1 qubit operation. Let's start! First we import the blueqat basic module and put the CX gate.

Now we get the result of '00' once. 00 means that the two qubits are both 0.

CX quantum logic gate is also called the CNOT gate. This time we have two qubits to use. One is called the control qubit and the other is the target qubit. Only when the controlled qubit is '1' does the target qubit flip. If the controlled quibt is '0', nothing happens.

This time we have both qubits initialized to 0 so nothing happens after the CX gate is applied.

Let's see if the control is 1. Applying x[0] to the 0th qubit and then applying cx to the 0th and 1st qubit.


Now we have a result of '11' . First the circuit flips the 0th qubit with .x[0] and then the .cx[0,1] gate flips the 1st qubit to 1 because the control qubit on the 0th qubit is 1. Thus both qubits are measured to be 1.

Usually the circuit automatically specifies the number of qubits used in the circuit, we can also specify the number of qubits first and then make the circuit.


Just put the number of qubits in the circuit(). This time 3 qubits are prepared and just two of them are used.

Superposition of Qubits

Here we learn about quantum superposition. Superposition is akind of combination of quantum logic gates.
The superposition is quite easy to implement. Just apply the Hadamard gate (H) to the circuit. To see the result now we have to measure the circuit 100 times.

Now we get results of 0 and 1 each with 50% probability. The Hadamard gate makes the superposition of the qubits and makes the +|+\rangle state which is the neutral position between 0 and 1.

Next let's create the |-\rangle state. Minus state is easily realized by applying the Z gate on the +|+\rangle state.


By applying .z[0] after .h[0] we can get the minus state. The minus state also has half 0 and half 1 measurements. We cannot distinguish these states just by the measurement. The quantum state is behind the equation and we can just guess it.

The state vector of +|+\rangle is 12[1,1]\frac{1}{ \sqrt{2}} [1,1].


Both elements of the state vector are positive. Let's check the |-\rangle state.


Now we can see the second element of the vector is a minus sign. This state can be acquired by simulator only. We cannot get this state vector directly from the actual quantum computer.


If you just use the basic superposition of qubits you cannot efficiently get the result of the calculation. Superposition is just a combination of bits and too many patters exist. To filter the data and reduce the number of combinations of resutls we can use entanglement.
You can syncronize more than two qubits with each other and filter the data you want after the measurement.
The circuit is very simple. Just apply the CX gate after the H gate.

Now you get almost half of the time '00' and '11'. Usually without engatglement and with just superposition you will get the result of 00, 01, 10, 11. By using combination of H gate and CX gate you can filter the data you want efficiently.