qml.math.reduce_statevector

reduce_statevector(state, indices, check_state=False, c_dtype='complex128')[source]

Compute the 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 value N.

  • indices (list(int)) – List of indices in the considered subsystem.

  • 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**len(indices), 2**len(indices)) or (batch_dim, 2**len(indices), 2**len(indices))

Return type

tensor_like

Example

>>> x = np.array([1, 0, 0, 0])
>>> reduce_statevector(x, indices=[0])
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]]
>>> y = [1, 0, 1, 0] / np.sqrt(2)
>>> reduce_statevector(y, indices=[0])
[[0.5+0.j 0.5+0.j]
 [0.5+0.j 0.5+0.j]]
>>> reduce_statevector(y, indices=[1])
[[1.+0.j 0.+0.j]
 [0.+0.j 0.+0.j]]
>>> z = tf.Variable([1, 0, 0, 0], dtype=tf.complex128)
>>> reduce_statevector(z, indices=[1])
tf.Tensor(
[[1.+0.j 0.+0.j]
 [0.+0.j 0.+0.j]], shape=(2, 2), dtype=complex128)
>>> x = np.array([[1, 0, 0, 0], [0, 1, 0, 0]])
>>> reduce_statevector(x, indices=[1])
array([[[1.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j]],
       [[0.+0.j, 0.+0.j],
        [0.+0.j, 1.+0.j]]])

Contents

Using PennyLane

Development

API

Internals