density_matrix_expectation_value

Graph.density_matrix_expectation_value(density_matrix, operator, *, name=None)

Calculate the expectation value of an operator with respect to a density matrix.

The last two dimensions of the density matrix must be equal to the last two dimensions of the operator and their batch shapes must be broadcastable.

Parameters

  • density_matrix (np.ndarray or Tensor) – The density matrix. It must be of shape (..., D, D).
  • operator (np.ndarray or Tensor) – The operator. It must be of shape (..., D, D).
  • name (str or None , optional) – The name of the node.

Returns

The expectation value with shape (...).

Return type

Tensor

SEE ALSO

Graph.expectation_value : Expectation value of an operator with respect to a pure state.

Graph.inner_product : Inner product of two vectors.

Graph.outer_product : Outer product of two vectors.

Graph.trace : Trace of an object.

Notes

The expectation value of an operator A\mathbf{A} with respect to a density matrix ρ=ipiψiψi\rho=\sum_i p_i |\psi_i\rangle\langle\psi_i| is defined as

Tr(Aρ)=Tr(Aipiψiψi)=ipiψiAψi. {\mathrm{Tr}}(A\rho) = {\mathrm{Tr}}(A\sum_i p_i |\psi_i\rangle\langle\psi_i|) = \sum_i p_i \langle\psi_i|A|\psi_i\rangle .

For more information about the density matrix expectation value, see density matrix on Wikipedia.

Examples

>>> graph.density_matrix_expectation_value(
...     np.array([[0.9, 0.], [0., 0.1]]), np.array([[1., 0.], [0., -1.]]),
...     name="expectation",
... )
<Tensor: name="expectation", operation_name="density_matrix_expectation_value", shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="expectation")
>>> result["output"]["expectation"]["value"]
0.8
>>> graph.density_matrix_expectation_value(
...     np.array([[0.9, 0.], [0., 0.1]]),
...     np.array([[[0., 1.], [1., 0.]], [[0., -1.j], [1.j, 0.]], [[1., 0.], [0., -1.]]]),
...     name="expectation2"
... )
<Tensor: name="expectation2", operation_name="expectation_value", shape=(3,)>
>>> result = bo.execute_graph(graph=graph, output_node_names="expectation2")
>>> result["output"]["expectation2"]["value"]
array([0. +0.j, 0. +0.j, 0.8+0.j])

Was this useful?