# coherent_state

Graph.coherent_state(alpha, dimension, offset=0, from_displacement=True, *, name=None)

Create a coherent state (or a batch of them).

By default, this function generates the coherent state by applying the displacement operator on the vacuum state in the truncated Fock space. Alternatively, you can also generate the coherent state from its analytical formula in the Fock basis (see the note part for details) by setting the flag from_displacement to False. Note that as the second approach is effectively truncating an infinite series, therefore the returned coherent state is not necessarily normalized.

### Parameters

• alpha (number or np.ndarray) – A number $\alpha$
• dimension (int) – The size of the state representation in the truncated Fock space. By default, the Fock space is truncated at [0, dimension). If non-zero offset is passed, the space is then truncated at [offset, dimension + offset).
• offset (int , optional) – The lowest level of Fock state in the representation. Defaults to 0.
• from_displacement (bool , optional) – Defaults to True, meaning the coherent state is computed from the displacement operation. You can set this flag to False to get the coherent state from its analytical formula in the Fock basis.
• name (str or None , optional) – The name of the node.

### Returns

A tensor representing the coherent state. The shape is 1D if there is no batch in alpha, otherwise 2D where the first axis is the batch dimension.

### Return type

Tensor

Graph.annihilation_operator : Create an annihilation operator in the truncated Fock space.

Graph.creation_operator : Create a creation operator in the truncated Fock space.

Graph.displacement_operator : Create a displacement operator (or a batch of them) in the truncated Fock space.

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

Graph.number_operator : Create a number operator in the truncated Fock space.

## Notes

A coherent state $|\alpha\rangle$ can be generated by applying a displacement operator $D(\alpha)$ on the vacuum state $|0\rangle$

$|\alpha\rangle = D(\alpha)|0\rangle = \exp(\alpha \hat{a}^\dagger - \alpha^\ast \hat{a}) | 0 \rangle$

where $\hat{a}$ and $\hat{a}^\dagger$

The coherent state can also be represented in the basis of Fock states:

$|\alpha\rangle = e^{-\frac{|\alpha|^2}{2}} \sum_{n=0}^{\infty} \frac{\alpha^n}{\sqrt{n!}}|n\rangle .$

For more information about coherent states, see coherent state on Wikipedia.

## Examples

Create a coherent state from displacement.

>>> graph.coherent_state(1j, 2, name="state")
<Tensor: name="state", operation_name="coherent_state", shape=(2,)>
>>> result = bo.execute_graph(graph=graph, output_node_names="state")
>>> result["output"]["state"]["value"]
array([5.40302306e-01+0.j        , 5.55111512e-17+0.84147098j])

Create a batch of coherent states from displacement.

>>> graph.coherent_state([1j, 3], 2, name="batch")
<Tensor: name="batch", operation_name="coherent_state", shape=(2, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="batch")
>>> result["output"]["batch"]["value"]
array([[ 5.40302306e-01+0.j        ,  5.55111512e-17+0.84147098j],
[-9.89992497e-01+0.j        ,  1.41120008e-01+0.j        ]])

Create a batch of coherent states from the analytical formula.

>>> graph.coherent_state([1j, 3], 2, from_displacement=False, name="analytical")
<Tensor: name="analytical", operation_name="coherent_state", shape=(2, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="analytical")
>>> result["output"]["analytical"]["value"]
array([[6.06530660e-01+0.j        , 3.71392916e-17+0.60653066j],
[1.11089965e-02+0.j        , 3.33269896e-02+0.j        ]])