Extracting final density matrix from mesolve

979 views
Skip to first unread message

Najme*

unread,
Apr 13, 2018, 8:25:50 AM4/13/18
to QuTiP: Quantum Toolbox in Python
Hi every one,
I'm a beginner in python programing and I am trying to solve Lindblad master equation for a system with 4-bosonic mode.
But when I want to extract final density matrix from "qutip.mesolve" function, I'm facing with an error like that:

#system's Dynamics****************************************
rho_0=tensor(coherent_dm(N1,5),thermal_dm(N2,nm),ket2dm(basis(N3,0)),ket2dm(basis(N4,0)));
times=np.linspace(0,T,20);
result=mesolve(H,rho_0,times,c_ops,[])
rho_f=result[-1]
--------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-00ea0a0c3630> in <module>()
      3 times=np.linspace(0,10,20);
      4 result=mesolve(H,rho_0,times,c_ops,[])
----> 5 rho_f=result[-1]

AttributeError: Result instance has no attribute '__getitem__'

and the only code that read the "rho_f=result[-1]" for me without above error is "odesolve".
I'd wonder if any body help me to solve my problem.

Alex Pitchford

unread,
Apr 13, 2018, 8:52:59 AM4/13/18
to qu...@googlegroups.com
Hi,
As you are not specifying any expectation operators, then your result object will contain the states for each t in times.
So I think what you want is:

rho_f = result.states[-1]

I hope that helps.

Alex


--
You received this message because you are subscribed to the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Najme Ettehadi

unread,
Apr 13, 2018, 10:05:41 AM4/13/18
to qu...@googlegroups.com
Thanks a lot Alex, It works well.

harman singh

unread,
Nov 9, 2021, 10:57:12 AM11/9/21
to QuTiP: Quantum Toolbox in Python
Hi Alex, can we extract density matrix if we had specified the  expectation operator in mesolve ?

Regards
Harman

To unsubscribe from this group and stop receiving emails from it, send an email to qutip+un...@googlegroups.com.

Simon Cross

unread,
Nov 15, 2021, 7:40:31 AM11/15/21
to qu...@googlegroups.com
Hi Harman,

> can we extract density matrix if we had specified the expectation operator in mesolve ?

Yes, you can.

As described in the mesolve documentation:

Additional options to mesolve can be set via the `options` argument, which
should be an instance of :class:`qutip.solver.Options`. Many ODE
integration options can be set this way, and the `store_states` and
`store_final_state` options can be used to store states even though
expectation values are requested via the `e_ops` argument.

one needs to set `store_states=True` on the options passed to the solver.

Yours sincerely,
Simon Cross
Reply all
Reply to author
Forward
0 new messages