# Learning Blueqat Step 1: Operations

## 1 Qubit Operations

```
import strangeworks.blueqat
```

Circuit()

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.

Circuit().x[0]

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.

Circuit().x[0].m[:].run(shots=1)

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.

Circuit().h[0].run()

The result is the state vector.

## 2 Qubit Operations

```
Circuit().cx[0,1].m[:].run(shots=1)
```

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.

Circuit().x[0].cx[0,1].m[:].run(shots=1)

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.

Circuit().x[0].cx[0,1].m[:].run(shots=1)

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

```
Circuit().h[0].m[:].run(shots=100)
```

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.

Circuit().h[z].z[0].m[:].run(shots=100)

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 $\frac{1}{ \sqrt{2}} [1,1]$.

Circuit().h[0].run()

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

Circuit().h[0].z[0].run()

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.

## Entanglement

```
Circuit().h[0].cx[0,1].m[:].run(shots=100)
```

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.