Graph.wigner_transform(density_matrix, position, momentum, offset=0, *, name=None)

Transform a density matrix into a Wigner function (or a batch of them).


  • density_matrix (Tensor or np.ndarray) – The density matrix ρ\rho(..., D, D).
  • position (np.ndarray) – The dimensionless position vector qq(L,).
  • momentum (np.ndarray) – The dimensionless momentum vector pp(K,).
  • offset (int , optional) – The lowest Fock state. Defaults to 0.
  • name (str or None , optional) – The name of the node.


The Wigner function with shape (..., L, K).

Return type



This function currently does not support calculating a gradient with respect to its inputs. Therefore, it cannot be used in a graph for a run_optimization or run_stochastic_optimization call, which will raise a RuntimeError. Please use gradient-free optimization if you want to perform an optimization task with this function. You can learn more about it in the How to optimize controls using gradient-free optimization user guide.


Graph.coherent_state : Create a coherent state (or a batch of them).

Graph.fock_state : Create a Fock state (or a batch of them).


The Wigner transform is defined as:

W(q,p)=12πeispqs/2ρq+s/2ds. W(q,p) = \frac{1}{2\pi} \int_{-\infty}^{\infty} \mathrm{e}^{\mathrm{i}sp} \langle q - s/2| \rho | q + s/2 \rangle \mathrm{d}s .

For more information about the Wigner transform, see Wigner function on Wikipedia.


Create a Wigner function.

>>> graph.wigner_transform(np.array([[1]]), [-1, 0, 1], np.zeros(1), name="wigner")
<Tensor: name="wigner", operation_name="wigner_transform", shape=(3, 1)>
>>> result = bo.execute_graph(graph=graph, output_node_names="wigner")
>>> result["output"]["wigner"]["value"]
array([[ 0.11709966+0.j],
    [ 0.31830989+0.j],
    [ 0.11709966+0.j]])

Create a batch of Wigner function.

>>> graph.wigner_transform(
        np.array([[[1, 0], [0, 0]], [[0, 0], [0, 1]]]),
        np.array([-1, 0, 1]),
<Tensor: name="wigner_batch", operation_name="wigner_transform", shape=(2, 3, 1)>
>>> result = bo.execute_graph(graph=graph, output_node_names="wigner_batch")
>>> result["output"]["wigner_batch"]["value"]
array([[[ 0.11709966+0.j],
        [ 0.31830989+0.j],
        [ 0.11709966+0.j]],
    [[ 0.11709966+0.j],
        [ 0.11709966+0.j]]])

Was this useful?