lime/oqs.py
def coherent(N, alpha):
    """Generates a coherent state with eigenvalue alpha.

    Constructed using displacement operator on vacuum state.

    Modified from Qutip.

    Parameters
    ----------
    N : int
        Number of Fock states in Hilbert space.

    alpha : float/complex
        Eigenvalue of coherent state.

    offset : int (default 0)
        The lowest number state that is included in the finite number state
        representation of the state. Using a non-zero offset will make the
        default method 'analytic'.

    method : string {'operator', 'analytic'}
        Method for generating coherent state.

    Returns
    -------
    state : qobj
        Qobj quantum object for coherent state

    Examples
    --------
    >>> coherent(5,0.25j)
    Quantum object: dims = [[5], [1]], shape = [5, 1], type = ket
    Qobj data =
    [[  9.69233235e-01+0.j        ]
     [  0.00000000e+00+0.24230831j]
     [ -4.28344935e-02+0.j        ]
     [  0.00000000e+00-0.00618204j]
     [  7.80904967e-04+0.j        ]]

    Notes
    -----
    Select method 'operator' (default) or 'analytic'. With the
    'operator' method, the coherent state is generated by displacing
    the vacuum state using the displacement operator defined in the
    truncated Hilbert space of size 'N'. This method guarantees that the
    resulting state is normalized. With 'analytic' method the coherent state
    is generated using the analytical formula for the coherent state
    coefficients in the Fock basis. This method does not guarantee that the
    state is normalized if truncated to a small number of Fock states,
    but would in that case give more accurate coefficients.

    """

    x = basis(N, 0)
    a = destroy(N)
    D = la.expm(alpha * dag(a) - np.conj(alpha) * a)

    return D @ x

    # elif method == "analytic" or offset > 0:

    #     data = np.zeros([N, 1], dtype=complex)
    #     n = arange(N) + offset
    #     data[:, 0] = np.exp(-(abs(alpha) ** 2) / 2.0) * (alpha ** (n)) / \
    #         _sqrt_factorial(n)
    #     return Qobj(data)

    # else:
    #     raise TypeError(
    #         "The method option can only take values 'operator' or 'analytic'")
Generates a coherent state with eigenvalue alpha.

    Constructed using displacement operator on vacuum state.

    Modified from Qutip.

    Parameters
    ----------
    N : int
        Number of Fock states in Hilbert space.

    alpha : float/complex
        Eigenvalue of coherent state.

    offset : int (default 0)
        The lowest number state that is included in the finite number state
        representation of the state. Using a non-zero offset will make the
        default method 'analytic'.

    method : string {'operator', 'analytic'}
        Method for generating coherent state.

    Returns
    -------
    state : qobj
        Qobj quantum object for coherent state

    Examples
    --------
    >>> coherent(5,0.25j)
    Quantum object: dims = [[5], [1]], shape = [5, 1], type = ket
    Qobj data =
    [[  9.69233235e-01+0.j        ]
     [  0.00000000e+00+0.24230831j]
     [ -4.28344935e-02+0.j        ]
     [  0.00000000e+00-0.00618204j]
     [  7.80904967e-04+0.j        ]]

    Notes
    -----
    Select method 'operator' (default) or 'analytic'. With the
    'operator' method, the coherent state is generated by displacing
    the vacuum state using the displacement operator defined in the
    truncated Hilbert space of size 'N'. This method guarantees that the
    resulting state is normalized. With 'analytic' method the coherent state
    is generated using the analytical formula for the coherent state
    coefficients in the Fock basis. This method does not guarantee that the
    state is normalized if truncated to a small number of Fock states,
    but would in that case give more accurate coefficients.

    
Generates a coherent state with eigenvalue alpha.
Constructed using displacement operator on vacuum state.

Modified from Qutip.

Parameters

N : int
Number of Fock states in Hilbert space.

alpha : float/complex
Eigenvalue of coherent state.

offset : int (default 0)
The lowest number state that is included in the finite number state
representation of the state. Using a non-zero offset will make the
default method 'analytic'.

method : string {'operator', 'analytic'}
Method for generating coherent state.

Returns

state : qobj
Qobj quantum object for coherent state

Examples



Notes

Select method 'operator' (default) or 'analytic'. With the
'operator' method, the coherent state is generated by displacing
the vacuum state using the displacement operator defined in the
truncated Hilbert space of size 'N'. This method guarantees that the
resulting state is normalized. With 'analytic' method the coherent state
is generated using the analytical formula for the coherent state
coefficients in the Fock basis. This method does not guarantee that the
state is normalized if truncated to a small number of Fock states,
but would in that case give more accurate coefficients.
Generates a coherent state with eigenvalue alpha . Constructed using displacement operator on vacuum state . Modified from Qutip . Parameters N : int Number of Fock states in Hilbert space . alpha : float / complex Eigenvalue of coherent state . offset : int ( default 0 ) The lowest number state that is included in the finite number state representation of the state . Using a non - zero offset will make the default method ' analytic ' . method : string { ' operator ' ' analytic ' } Method for generating coherent state . Returns state : qobj Qobj quantum object for coherent state Examples Notes Select method ' operator ' ( default ) or ' analytic ' . With the ' operator ' method the coherent state is generated by displacing the vacuum state using the displacement operator defined in the truncated Hilbert space of size ' N ' . This method guarantees that the resulting state is normalized . With ' analytic ' method the coherent state is generated using the analytical formula for the coherent state coefficients in the Fock basis . This method does not guarantee that the state is normalized if truncated to a small number of Fock states but would in that case give more accurate coefficients .
def coherent(N, alpha):
    x = basis(N, 0)
    a = destroy(N)
    D = la.expm(alpha * dag(a) - np.conj(alpha) * a)
    return D @ x
def coherent ( N , alpha ) : x = basis ( N , 0 ) a = destroy ( N ) D = la . expm ( alpha * dag ( a ) - np . conj ( alpha ) * a ) return D @ x
Generates a coherent state with eigenvalue alpha.
Generates a coherent state with eigenvalue alpha .
"""Generates a coherent state with eigenvalue alpha.

    Constructed using displacement operator on vacuum state.

    Modified from Qutip.

    Parameters
    ----------
    N : int
        Number of Fock states in Hilbert space.

    alpha : float/complex
        Eigenvalue of coherent state.

    offset : int (default 0)
        The lowest number state that is included in the finite number state
        representation of the state. Using a non-zero offset will make the
        default method 'analytic'.

    method : string {'operator', 'analytic'}
        Method for generating coherent state.

    Returns
    -------
    state : qobj
        Qobj quantum object for coherent state

    Examples
    --------
    >>> coherent(5,0.25j)
    Quantum object: dims = [[5], [1]], shape = [5, 1], type = ket
    Qobj data =
    [[  9.69233235e-01+0.j        ]
     [  0.00000000e+00+0.24230831j]
     [ -4.28344935e-02+0.j        ]
     [  0.00000000e+00-0.00618204j]
     [  7.80904967e-04+0.j        ]]

    Notes
    -----
    Select method 'operator' (default) or 'analytic'. With the
    'operator' method, the coherent state is generated by displacing
    the vacuum state using the displacement operator defined in the
    truncated Hilbert space of size 'N'. This method guarantees that the
    resulting state is normalized. With 'analytic' method the coherent state
    is generated using the analytical formula for the coherent state
    coefficients in the Fock basis. This method does not guarantee that the
    state is normalized if truncated to a small number of Fock states,
    but would in that case give more accurate coefficients.

    """ # elif method == "analytic" or offset > 0: #     data = np.zeros([N, 1], dtype=complex) #     n = arange(N) + offset #     data[:, 0] = np.exp(-(abs(alpha) ** 2) / 2.0) * (alpha ** (n)) / \ #         _sqrt_factorial(n) #     return Qobj(data) # else: #     raise TypeError( #         "The method option can only take values 'operator' or 'analytic'")
N
alpha