You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the dynamical simulation of a chain, I tried 2 solvers mesolve and mcsolve. I want to calculate the number of spins in state 1 (basis(dimensions=2, n=1)) in the chain. For mesolve, I just take the formula from the publication (n(t)=(1/L) * sum_k Tr(rho(t)n^(k))), where n^(k) is the number operator for site k. I find my implementation is inefficient due to the nested loops. I know it's also possible with e_ops option in the solver but I'm not sure how to define them for the 2 solvers (possibly working with v5.0.0a2).
This snippet works for v4.7.3
def n_t(time: np.array,
states_t,
solver: str,
L: int,
ntraj: int = 250) -> np.ndarray: # TODO: Is there a more efficient way? with e_ops?
n_t = np.zeros(len(time), dtype=float)
if solver == "mesolve":
for t in range(len(time)):
no_of_particles = 0
for i in range(L):
no_of_particles += np.trace(states_t[t].ptrace(i) * num(2)).real
n_t[t] += 1 / L * no_of_particles
if solver == "mcsolve":
num_list = []
for i in range(L):
op_list = [qeye(2)] * L
op_list[i] = num(2)
num_list.append(tensor(op_list))
for t in range(len(time)):
particle_numbers_trajs = np.zeros(L)
for traj in range(ntraj):
particle_numbers = states_t[traj][t].dag() * num_list * states_t[traj][t]
particle_numbers_trajs += np.array(
[np.real(diagonal_element.full()[0, 0]) for diagonal_element in particle_numbers])
n_t[t] += np.sum(particle_numbers_trajs) / ntraj / L
return n_t
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
For the dynamical simulation of a chain, I tried 2 solvers
mesolve
andmcsolve
. I want to calculate the number of spins in state 1 (basis(dimensions=2, n=1)
) in the chain. Formesolve
, I just take the formula from the publication (n(t)=(1/L) * sum_k Tr(rho(t)n^(k))), where n^(k) is the number operator for site k. I find my implementation is inefficient due to the nested loops. I know it's also possible withe_ops
option in the solver but I'm not sure how to define them for the 2 solvers (possibly working with v5.0.0a2).This snippet works for v4.7.3
Beta Was this translation helpful? Give feedback.
All reactions