1 Qubit Operations
Next we put some quantum logic gates on the circuit with the chain method after the initialized circuit. the .x 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
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 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 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
Now we get results of 0 and 1 each with 50% probability. The Hadamard gate makes the superposition of the qubits and makes the state which is the neutral position between 0 and 1.
Next let's create the state. Minus state is easily realized by applying the Z gate on the state.
By applying .z after .h 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 is .
Both elements of the state vector are positive. Let's check the 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.
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.