Sorry, my description may not be very clear to you. Here, I will explain my question in detail. (I also slightly changed the parameter values to make the different in the figure more obvious.)
My first code is
using QuantumOptics
using PyPlot
# elapsed_time_1 = @elapsed begin
dim = 3; # Dimension of the single atom Hilbert space
Natom = 2; # Number of atoms
# baisis
b = NLevelBasis(dim) # Basis for a single atom
s00 = nlevelstate(b,1) # 0> state
sD = nlevelstate(b,2) # 1> state
srr = nlevelstate(b,3) # r> state
# Identity4 = identityoperator(b) # Identity operator one or identityoperator
# parameters
Omega = 1;
Ud = 10;
delta = 0;
tf = pi/Omega;
Hami = sqrt(2)*Omega*sD ⊗ dagger(s00) + sqrt(2)*Omega*srr ⊗ dagger(sD) + dagger(sqrt(2)*Omega*sD ⊗ dagger(s00) + sqrt(2)*Omega*srr ⊗ dagger(sD)) + Ud*srr ⊗ dagger(srr)  delta*sD ⊗ dagger(sD);
# initial and final state
psi_0 = s00;
psi_f = s00;
dm0 = psi_0⊗dagger(psi_0);
rho_final = psi_f⊗dagger(psi_f);
# evolution
tlist_pump = range(0, stop=tf, length=1000);
ffidelity = [];
tout, psi_XZ = timeevolution.schroedinger(tlist_pump, psi_0, Hami);
ffidelity = real(expect(rho_final, psi_XZ))
# plt.close()
figure(figsize=(9,3))
subplot(1,2,1)
plot(ffidelity)
xlabel(L"T")
ylabel(L"Fidelity")
tight_layout()
gcf()
Here I write tout, rho_XZ = timeevolution.schroedinger(tlist_pump, psi_0, Hami)
and use psi_0 (ket)
as intial state. The fidelity is defined as exp_psi0 = real(expect(rho_final, rho_XZ))
. I can plot
Here because I cannot find the source code of expect
, i guess it can be used as \langle \psi_{XZ}\rho_{final}\psi_{XZ}\rangle (here \rho_{final}=\psi_{final}\rangle\langle \psi_{final}). And the image is same as that in Matlab (which does use the definition abs(psi_final'*rho_xz*psi_final)
) of fidelity. I want to know is the definition of expect
\langle \psi_{XZ}\rho_{final}\psi_{XZ}\rangle?
My second code is
using QuantumOptics
using PyPlot
# elapsed_time_1 = @elapsed begin
dim = 3; # Dimension of the single atom Hilbert space
Natom = 2; # Number of atoms
# baisis
b = NLevelBasis(dim) # Basis for a single atom
s00 = nlevelstate(b,1) # 0> state
sD = nlevelstate(b,2) # 1> state
srr = nlevelstate(b,3) # r> state
# Identity4 = identityoperator(b) # Identity operator one or identityoperator
# parameters
Omega = 1;
Ud = 10;
delta = 0;
tf = pi/Omega;
Hami = sqrt(2)*Omega*sD ⊗ dagger(s00) + sqrt(2)*Omega*srr ⊗ dagger(sD) + dagger(sqrt(2)*Omega*sD ⊗ dagger(s00) + sqrt(2)*Omega*srr ⊗ dagger(sD)) + Ud*srr ⊗ dagger(srr)  delta*sD ⊗ dagger(sD);
# initial and final state
psi_0 = s00;
psi_f = s00;
dm0 = psi_0⊗dagger(psi_0);
rho_final = psi_f⊗dagger(psi_f);
# evolution
tlist_pump = range(0, stop=tf, length=1000);
ffidelity = [];
tout, rho_XZ = timeevolution.schroedinger(tlist_pump, dm0, Hami);
ffidelity = real(expect(rho_final, rho_XZ))
# plt.close()
figure(figsize=(9,3))
subplot(1,2,1)
plot(ffidelity)
xlabel(L"T")
ylabel(L"Fidelity")
tight_layout()
gcf()
Here tout, rho_XZ = timeevolution.schroedinger(tlist_pump, dm0, Hami)
I use initial state dm0 (density operator)
and write real(expect(rho_final, rho_XZ))
to compute fidelity. And I plot
I hope here expect
acts as trace(\rho_{final}\rho_{XZ}) = \langle \psi_{final}\rho_{XZ}\psi_{final}\rangle . However, it must not. Because it is different as that from my first code.
My third code is
using QuantumOptics
using PyPlot
# elapsed_time_1 = @elapsed begin
dim = 3; # Dimension of the single atom Hilbert space
Natom = 2; # Number of atoms
# baisis
b = NLevelBasis(dim) # Basis for a single atom
s00 = nlevelstate(b,1) # 0> state
sD = nlevelstate(b,2) # 1> state
srr = nlevelstate(b,3) # r> state
# Identity4 = identityoperator(b) # Identity operator one or identityoperator
# parameters
Omega = 1;
Ud = 10;
delta = 0;
tf = pi/Omega;
Hami = sqrt(2)*Omega*sD ⊗ dagger(s00) + sqrt(2)*Omega*srr ⊗ dagger(sD) + dagger(sqrt(2)*Omega*sD ⊗ dagger(s00) + sqrt(2)*Omega*srr ⊗ dagger(sD)) + Ud*srr ⊗ dagger(srr)  delta*sD ⊗ dagger(sD);
# initial and final state
psi_0 = s00;
psi_f = s00;
dm0 = psi_0⊗dagger(psi_0);
rho_final = psi_f⊗dagger(psi_f);
# evolution
tlist_pump = range(0, stop=tf, length=1000);
ffidelity = [];
tout, rho_XZ = timeevolution.schroedinger(tlist_pump, dm0, Hami);
ffidelity = [fidelity(rhoXZ, rho_final) for rhoXZ in rho_XZ]
# plt.close()
figure(figsize=(9,3))
subplot(1,2,1)
plot(ffidelity)
xlabel(L"T")
ylabel(L"Fidelity")
tight_layout()
gcf()
Here I use tout, rho_XZ = timeevolution.schroedinger(tlist_pump, dm0, Hami)
and ffidelity = [fidelity(rhoXZ, rho_final) for rhoXZ in rho_XZ]
with initial state dm0 (density operator)
. And I get
I believe it is the definition of fidelity
, however, I do not want to use trace(\sqrt{\rho*\sigma}). Instead, I want to use trace(\rho*\sigma). I cannot find a direct way to define fidelity like this.
conclusion

I do not know the knowledge and source code of code expect
.
My ideal guess is when I use initial state with ket
, it is \langle \psi_{target}\rho(t)\psi_{target}\rangle, and when I use initial state with density operator
, it is trace(\rho(t)*\rho_{target}).

Compared to fidelity(rho,sigma)
with definition trace(\sqrt{\sqrt{\rho}\sigma\sqrt{\rho}}), I want to use trace(\rho(t)*\rho_{target}) and \langle \psi_{target}\rho(t)\psi_{target}\rangle. It is precisely because there is no such two definitions and I cannot directly write it myself, so I used expect
. But I find when I use initial state with density operator
, i cannot get the correct image (using expect
) same as Matlab.

Do you have any way to write directly the fidelity in the way trace(\rho(t)*\rho_{target}) and \langle \psi_{target}\rho(t)\psi_{target}\rangle?