I'm attempting to use qiskit's state_fidelity(state1, state2, validate=True)
but keep getting the following error: QiskitError: 'Input quantum state is not a valid'
In order to use this form I had already read the documentation to see that state1 and state2 must be either density matrices or statevectors.
As a result I used the qiskit.quantum_info
module to generate a density matrix for state1.
For state2 I created the array using numpy importing numbers from state tomography. (Shown below)
#Turn this into a the density matrix
state2_matrix = (1/2)*np.array([[1+expectation_vals[0], expectation_vals[1]-1j*expectation_vals[2]], [expectation_vals[1]+1j*expectation_vals[2], 1-expectation_vals[0]]])
state2=DensityMatrix(state2_matrix)
where expectation_vals=[0.004, 1.0, -0.04]
comes from my single qubit tomography.
Edit
This matrix, despite now being created using the Density Matrix class, is still giving me the error that the Input quantum state is not valid. This leads me to believe that there is some property of density matrices that is not being fulfilled by this matrix.
$$\begin{bmatrix}
0.502 & \tfrac{1}{2} + 0.02i \\
\tfrac{1}{2} - 0.02i & 0.498 \\
\end{bmatrix}$$
I can see it has trace=1, and I found the eigenvalues, using numpy, to be (array([ 1.00040384e+00+0.j, -4.03836916e-04+0.j]).
I now assume that this second eigenvalue is the reason this is not working since Density matrices must be positive semidefinite. If this is the reason state_fidelity()
is not working, then how can this be avoided when using tomography on a single qubit?
Edit 2.0
In the end I was able to leave validate = True
, but I had to renormalize my expectation values in order to do so. (Pure State)
Thank you all for your help!