1+ using QuantumOptics
2+ using WaveguideQED
3+ using LinearAlgebra
4+ using PyPlot
5+ pygui (false )
6+ pygui (true )
7+ include (" singlecavity_simulations.jl" )
8+ # Parameter structure imported from singlecavity_simulations (bit overkill for now, but can prove usefull)
9+ param = parameters ()
10+
11+ # Set detuning:
12+ param. δ = 0
13+ # Set non linearity:
14+ param. x3 = 0
15+
16+ param. times = 0 : 0.1 : 10
17+
18+ dt = param. times[2 ] - param. times[1 ]
19+
20+ # Create operators for two photons interacting with cavity
21+ bc = FockBasis (1 )
22+ bw = WaveguideBasis (1 ,param. times)
23+ a = destroy (bc)
24+ ad = create (bc);
25+ n = ad* a ⊗ identityoperator (bw)
26+ # $w†a and a†w efficient implementation$
27+ wda = emission (bc,bw)
28+ adw = absorption (bc,bw)
29+ H = param. δ* n + im* sqrt (param. γ/ dt)* (adw- wda) + param. x3/ 4 * (n* n+ n)
30+
31+
32+ # Define input onephoton state shape
33+ ξfun (t,σ,t0) = complex (sqrt (2 / σ)* (log (2 )/ pi )^ (1 / 4 )* exp (- 2 * log (2 )* (t- t0)^ 2 / σ^ 2 ))
34+ ξvec = ξfun .(param. times,param. σ,param. t0)
35+
36+ ψ_cw = onephoton (bw,ξvec)
37+ psi = fockstate (bc,0 ) ⊗ ψ_cw
38+
39+ # Solve
40+ @btime ψ = waveguide_evolution (param. times, psi, H)
41+
42+ # REFERENCE SOLUTION
43+ sol1 = solve_differentialeq (param,ξfun)
44+ ref_sol = ξfun .(sol1. t,param. σ,param. t0)- sqrt (param. γ)* sol1
45+
46+ # Plot single photon waveguide state
47+ ψ_single = OnePhotonView (ψ)/ sqrt (dt)
48+
49+ fig,ax = subplots (1 ,1 ,figsize= (9 ,4.5 ))
50+ ax. plot (param. times,abs .(ξvec).^ 2 ," g-" ,label= " Input pulse" )
51+ ax. plot (param. times,abs .(ψ_single).^ 2 ," ro" ,label= " δ = 0" ,fillstyle= " none" )
52+ ax. plot (sol1. t,abs .(ref_sol).^ 2 ," r-" )
53+ ax. set_xlabel (" time [1/γ]" )
54+ ax. set_ylabel (L " $\x i_{out}^{(1)}$" )
55+ ax. legend ()
56+ plt. tight_layout ()
57+
58+ using DifferentialEquations
59+ using LinearAlgebra
60+ using PyPlot
61+ function dpsi! (dpsi,psi,p,t)
62+ y,d,nsteps,dt = p
63+ timeindex = round (Int,t/ dt,RoundDown) + 1
64+ dpsi .= 0
65+ dpsi[2 + nsteps] = - sqrt (y/ dt)* psi[1 + timeindex]
66+ dpsi[1 + timeindex] = sqrt (y/ dt)* psi[2 + nsteps]
67+ end
68+
69+ # Define parameters
70+ y,d,dt = 1 ,0 ,0.1
71+ times = 0 : dt: 10
72+ N = length (times)
73+ p = (y,d,N,dt)
74+
75+ # Define input gaussian state with width s = 1 and arrivial time t0=5
76+ xi (t,s,t0) = complex (sqrt (2 / s)* (log (2 )/ pi )^ (1 / 4 )* exp (- 2 * log (2 )* (t- t0)^ 2 / s^ 2 ))
77+ psi = zeros (ComplexF64,2 * (N+ 1 ))
78+ psi[2 : N+ 1 ] .= sqrt (dt)* xi .(times,1 ,5 )
79+ prob = ODEProblem (dpsi!, psi, (times[1 ], times[end ]+ dt), p)
80+ sol = solve (prob, OrdinaryDiffEq. DP5 ();reltol = 1.0e-8 ,abstol = 1.0e-10 );
81+ psi_out = sol[end ][2 : N+ 1 ]
82+
83+ # Plot the output
84+ fig,ax = subplots (1 ,1 ,figsize= (9 ,4.5 ))
85+ ax. plot (times,abs .(psi_out).^ 2 ," r-" ,label= " Input pulse" )
0 commit comments