How do I get the amplitude of each qubit, like plot_bloch_multivector()
, but not output the tensor product of all qubits.
In this case I need output [0.707, -0.707], [0, 1], [0.707, 0.707], [0.707, 0.707]
. How can I get this?
You mean something like this?
from qiskit import Aer, execute, QuantumCircuit
from qiskit.quantum_info import Statevector
backend = Aer.get_backend("statevector_simulator")
qc = QuantumCircuit(1, 1)
qc.h(0)
print(qc)
result = execute(qc, backend=backend, shots=1).result()
print('State Vector:', result.get_statevector() )
Update: If you have two qubits or more, then you can also use this function as shown here:
from qiskit import Aer, execute, QuantumCircuit
from qiskit.quantum_info import Statevector
backend = Aer.get_backend("statevector_simulator")
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.h(1)
print(qc)
result = execute(qc, backend=backend, shots=1).result()
print('State Vector:', result.get_statevector() )
Now, if you are working with multi-qubit system then one of the thing you have to remember is that they might be entangled together. So you don't expect any two qubit state $|\psi \rangle \in \mathbb{C}^4$ can be written as $|\psi \rangle = |\phi_1 \rangle \otimes |\phi_2 \rangle $ where $|\phi_1\rangle$ and $|\phi_2\rangle$ belongs to $\mathbb{C}^2$. For example, if you look at this circuit:
You can't write each qubit state individually! That is the state $|\psi \rangle = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 0 \\ 0 \\ 1 \end{pmatrix} \neq \begin{pmatrix} a \\ b \end{pmatrix} \otimes \begin{pmatrix} c \\ d \end{pmatrix} $ with $a,b,c,d \in \mathbb{C}$ and $|a|^2 + |b|^2 =1 $ and $|c|^2 + |d|^2 = 1$.
Now the state is separable and you want to measure on one of them, you can do this:
from qiskit import Aer, execute, QuantumCircuit
from qiskit.quantum_info import Statevector
backend = Aer.get_backend("statevector_simulator")
qc = QuantumCircuit(2, 1)
qc.h(0)
qc.h(1)
qc.measure([1],[0])
print(qc)
result = execute(qc, backend=backend, shots=1).result()
print('State Vector:', result.get_statevector() )
As you can see, the qubit that got measured will collapsed its state to either the state $|0\rangle$ or $|1\rangle$.... Now, if it collapsed to the state $|0\rangle$ then the State Vector now is $|\psi \rangle \otimes |0\rangle$ . Similarly, if it collapsed to the state $|1 \rangle$ then you get $|\psi \rangle \otimes | 1 \rangle$. Either way, this allow you to observe what $|\psi\rangle$ is now... For instance, the State vector above tells you that $|\psi \rangle$ is the the superposition state $\dfrac{|0\rangle + |1 \rangle}{\sqrt{2}}$, which is what you expected as you applied the Hadamard gate $H$ to it.
And I can extend this to higher system as well... Just measured the other states.
Now having said all that, if your circuit only consist of single qubit gates, then you can just decompose that to multiple circuits consisting of single qubit in each. This will make thing easier to consider!