def make_system(self, H, c_ops, tlist=None, args={}, options=None): if options is None: options = self.options else: self.options = options var = _collapse_args(args) ss = SolverSystem() ss.td_c_ops = [] ss.td_n_ops = [] ss.args = args ss.col_args = var if type(c_ops) is list: for c in c_ops: # Accounts for nested list format of c_ops cevo = QobjEvo(c, args, tlist=tlist) cdc = cevo._cdc() cevo.compile() cdc.compile() ss.td_c_ops.append(cevo) ss.td_n_ops.append(cdc) if isinstance(H, (list, Qobj, QobjEvo)): H_td = QobjEvo(H, args, tlist=tlist) H_td *= -1j for c in ss.td_n_ops: H_td += -0.5 * c if options.rhs_with_state: H_td._check_old_with_state() H_td.compile() ss.H_td = H_td ss.makefunc = _qobjevo_set ss.set_args = _qobjevo_args # <- redundant ss.type = "QobjEvo" elif callable(H): ss.h_func = H ss.Hc_td = -0.5 * sum(ss.td_n_ops) ss.Hc_td.compile() ss.with_state = options.rhs_with_state ss.makefunc = _func_set ss.set_args = _func_args # <- redundant ss.type = "callback" else: raise Exception("Format of c_ops not supported.") solver_safe["mcsolve"] = ss self.ss = ss self.reset()
def _mesolve_QobjEvo(H, c_ops, tlist, args, opt): """ Prepare the system for the solver, H can be an QobjEvo. """ H_td = QobjEvo(H, args, tlist=tlist) if not issuper(H_td.cte): L_td = liouvillian(H_td) else: L_td = H_td for op in c_ops: op_td = QobjEvo(op, args, tlist=tlist) if not issuper(op_td.cte): op_td = lindblad_dissipator(op_td) L_td += op_td if opt.rhs_with_state: L_td._check_old_with_state() nthread = opt.openmp_threads if opt.use_openmp else 0 L_td.compile(omp=nthread) ss = SolverSystem() ss.H = L_td ss.makefunc = _qobjevo_set solver_safe["mesolve"] = ss return ss
def make_system(self, H, c_ops, tlist=None, args={}, options=None): if options is None: options = self.options else: self.options = options var = _collapse_args(args) ss = SolverSystem() ss.td_c_ops = [] ss.td_n_ops = [] ss.args = args ss.col_args = var for c in c_ops: cevo = QobjEvo(c, args, tlist=tlist) cdc = cevo._cdc() cevo.compile() cdc.compile() ss.td_c_ops.append(cevo) ss.td_n_ops.append(cdc) try: H_td = QobjEvo(H, args, tlist=tlist) H_td *= -1j for c in ss.td_n_ops: H_td += -0.5 * c if options.rhs_with_state: H_td._check_old_with_state() H_td.compile() ss.H_td = H_td ss.makefunc = _qobjevo_set ss.set_args = _qobjevo_args ss.type = "QobjEvo" except: ss.h_func = H ss.Hc_td = -0.5 * sum(ss.td_n_ops) ss.Hc_td.compile() ss.with_state = options.rhs_with_state ss.makefunc = _func_set ss.set_args = _func_args ss.type = "callback" solver_safe["mcsolve"] = ss self.ss = ss self.reset()
def _sesolve_func_td(H_func, args, opt): """ Prepare the system for the solver, H is a function. """ ss = SolverSystem() ss.H = H_func ss.makefunc = _Hfunc_set solver_safe["sesolve"] = ss return ss
def _sesolve_QobjEvo(H, tlist, args, opt): """ Prepare the system for the solver, H can be an QobjEvo. """ H_td = -1.0j * QobjEvo(H, args, tlist=tlist) if opt.rhs_with_state: H_td._check_old_with_state() nthread = opt.openmp_threads if opt.use_openmp else 0 H_td.compile(omp=nthread) ss = SolverSystem() ss.H = H_td ss.makefunc = _qobjevo_set solver_safe["sesolve"] = ss return ss
def _mesolve_func_td(L_func, c_op_list, rho0, tlist, args, opt): """ Evolve the density matrix using an ODE solver with time dependent Hamiltonian. """ if type(c_op_list) is list: c_ops = [] for op in c_op_list: op_td = QobjEvo(op, args, tlist=tlist, copy=False) if not issuper(op_td.cte): c_ops += [lindblad_dissipator(op_td)] else: c_ops += [op_td] if c_op_list: c_ops_ = [sum(c_ops)] else: c_ops_ = [] elif callable(c_op_list): c_ops_ = c_op_list if opt.rhs_with_state: state0 = rho0.full().ravel("F") obj = L_func(0., state0, args) if not issuper(obj): L_func = _LiouvillianFromFunc(L_func, c_ops_).H2L_with_state else: L_func = _LiouvillianFromFunc(L_func, c_ops_).L_with_state else: obj = L_func(0., args) if callable(c_ops_): if not issuper(obj): L_func = _LiouvillianFromFunc(L_func, c_ops_).H2L_c else: L_func = _LiouvillianFromFunc(L_func, c_ops_).L_c else: if not issuper(obj): L_func = _LiouvillianFromFunc(L_func, c_ops_).H2L else: L_func = _LiouvillianFromFunc(L_func, c_ops_).L ss = SolverSystem() ss.L = L_func ss.makefunc = _Lfunc_set solver_safe["mesolve"] = ss return ss
def _mesolve_func_td(L_func, c_op_list, rho0, tlist, args, opt): """ Evolve the density matrix using an ODE solver with time dependent Hamiltonian. """ c_ops = [] for op in c_op_list: td = QobjEvo(op, args, tlist=tlist, copy=False) c_ops.append(td if td.cte.issuper else lindblad_dissipator(td)) c_ops_ = [sum(c_ops)] if c_op_list else [] L_api = _LiouvillianFromFunc(L_func, c_ops_, rho0.dims) if opt.rhs_with_state: obj = L_func(0., rho0.full().ravel("F"), args) L_func = L_api.L_with_state if issuper(obj) else L_api.H2L_with_state else: obj = L_func(0., args) L_func = L_api.L if issuper(obj) else L_api.H2L ss = SolverSystem() ss.L = L_func ss.makefunc = _Lfunc_set solver_safe["mesolve"] = ss return ss
def _mesolve_QobjEvo(H, c_ops, tlist, args, opt): """ Prepare the system for the solver, H can be an QobjEvo. """ H_td = QobjEvo(H, args, tlist=tlist) if not issuper(H_td.cte): L_td = liouvillian(H_td) else: L_td = H_td for op in c_ops: # We want to avoid passing tlist where it isn't necessary, to allow a # Hamiltonian/Liouvillian which already _has_ time-dependence not equal # to the mesolve evaluation times to be used in conjunction with # time-independent c_ops. If we _always_ pass it, it may appear to # QobjEvo that there is a tlist mismatch, even though it is not used. if isinstance(op, Qobj): op_td = QobjEvo(op) elif isinstance(op, QobjEvo): op_td = QobjEvo(op, args) else: op_td = QobjEvo(op, args, tlist=tlist) if not issuper(op_td.cte): op_td = lindblad_dissipator(op_td) L_td += op_td if opt.rhs_with_state: L_td._check_old_with_state() nthread = opt.openmp_threads if opt.use_openmp else 0 L_td.compile(omp=nthread) ss = SolverSystem() ss.H = L_td ss.makefunc = _qobjevo_set solver_safe["mesolve"] = ss return ss