qml.math.dm_from_state_vector¶
- dm_from_state_vector(state, check_state=False, c_dtype='complex128')[source]¶
Convenience function to compute a (full) density matrix from a state vector.
- Parameters
state (tensor_like) – 1D or 2D tensor state vector. This tensor should of size
(2**N,)
or(batch_dim, 2**N)
, for some integer valueN
.check_state (bool) – If True, the function will check the state validity (shape and norm).
c_dtype (str) – Complex floating point precision type.
- Returns
Density matrix of size
(2**N, 2**N)
or(batch_dim, 2**N, 2**N)
- Return type
tensor_like
Example
>>> x = np.array([1, 0, 1j, 0]) / np.sqrt(2) >>> dm_from_state_vector(x) array([[0.5+0.j , 0. +0.j , 0. -0.5j, 0. +0.j ], [0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j ], [0. +0.5j, 0. +0.j , 0.5+0.j , 0. +0.j ], [0. +0.j , 0. +0.j , 0. +0.j , 0. +0.j ]])
code/api/pennylane.math.dm_from_state_vector
Download Python script
Download Notebook
View on GitHub