File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -37,18 +37,21 @@ def ket2dm(ket: cupy.ndarray) -> cupy.ndarray:
3737
3838# Helper to create a 'coherent' state as a state vector.
3939def coherent_state (N : int , alpha : float ):
40- sqrtn = cupy .sqrt (cupy .arange (0 , N , dtype = cupy .complex128 ))
41- sqrtn [0 ] = 1
42- data = alpha / sqrtn
43- data [0 ] = cupy .exp (- cupy .abs (alpha )** 2 / 2.0 )
44- cupy .cumprod (data , out = sqrtn )
45- return sqrtn
40+ # Computes coherent state amplitudes in the Fock basis
41+ # Ref: https://en.wikipedia.org/wiki/Coherent_state
42+ fock_amplitudes = cupy .zeros (N , dtype = cupy .complex128 )
43+ amplitude = numpy .exp (- numpy .abs (alpha )** 2 / 2.0 )
44+ for n in range (N ):
45+ fock_amplitudes [n ] = amplitude
46+ amplitude *= (alpha / numpy .sqrt (n + 1 ))
47+ return fock_amplitudes
4648
4749
4850# Helper to create a coherent state as a density matrix.
4951def coherent_dm (N : int , alpha : float ):
5052 return ket2dm (coherent_state (N , alpha ))
5153
54+
5255# A Python wrapper of `CuDensityMatState` state.
5356class CuDensityMatState (object ):
5457 __ctx = None
You can’t perform that action at this time.
0 commit comments