예제 #1
0
    def _single_traj(self, nt):
        """
        Monte Carlo algorithm returning state-vector or expectation values
        at times tlist for a single trajectory.
        """
        # SEED AND RNG AND GENERATE
        prng = RandomState(self.seeds[nt])
        opt = self.options

        # set initial conditions
        ss = self.ss
        tlist = self.tlist
        e_ops = self.e_ops.copy()
        opt = self.options
        rhs, ode_args = self.ss.makefunc(ss)
        ODE = self._build_integration_func(rhs, ode_args, opt)
        ODE.set_initial_value(self.initial_vector, tlist[0])
        e_ops.init(tlist)

        cymc = CyMcOde(ss, opt)
        states_out, ss_out, collapses = cymc.run_ode(ODE, tlist, e_ops, prng)

        # Run at end of mc_alg function
        # -----------------------------
        if opt.steady_state_average:
            ss_out /= float(len(tlist))

        return (states_out, ss_out, e_ops, collapses)
예제 #2
0
    def _single_traj(self, nt):
        """
        Monte Carlo algorithm returning state-vector or expectation values
        at times tlist for a single trajectory.
        """
        # SEED AND RNG AND GENERATE
        prng = RandomState(self.seeds[nt])
        opt = self.options

        # set initial conditions
        ss = self.ss
        tlist = self.tlist
        e_ops = self.e_ops.copy()
        opt = self.options
        rhs, ode_args = self.ss.makefunc(ss, args=ss.args)
        
        #try:
        #    ODE = self._build_integration_func(rhs, ode_args, opt)
        #    ODE.set_initial_value(self.initial_vector, tlist[0])
        #    e_ops.init(tlist)

        #    cymc = CyMcOde(ss, opt)
        #    states_out, ss_out, collapses = cymc.run_ode(ODE, tlist, e_ops, prng)
        #    
        #    fd = open('/home/dustyd/Documents/Repositories/qutip/debug_out_%s.txt'%rhs.__name__, 'a')
        #    fd.write(repr(ODE.f_params)+"\n")
        #    fd.write(repr(opt)+"\n\n")
        #    fd.close()
        #    
        #except Exception as exception:
        #    strin = io.StringIO("")
        #    traceback.print_tb(sys.exc_info()[2],file=strin)
        #    
        #    fd = open('/home/dustyd/Documents/Repositories/qutip/debug_out_%s.txt'%rhs.__name__, 'a')
        #    fd.write(repr(ODE.f_params)+"\n")
        #    fd.write(repr(opt)+"\n\n")
        #    fd.close()
        #
        #    return [str(exception), repr(ode_args), strin.getvalue()]
        
        ODE = self._build_integration_func(rhs, ode_args, opt)
        ODE.set_initial_value(self.initial_vector, tlist[0])
        e_ops.init(tlist)

        cymc = CyMcOde(ss, opt)
        states_out, ss_out, collapses = cymc.run_ode(ODE, tlist, e_ops, prng)

        # Run at end of mc_alg function
        # -----------------------------
        if opt.steady_state_average:
            ss_out /= float(len(tlist))

        return (states_out, ss_out, e_ops, collapses)