本文整理汇总了Python中qutip.solver.Result.ntraj方法的典型用法代码示例。如果您正苦于以下问题:Python Result.ntraj方法的具体用法?Python Result.ntraj怎么用?Python Result.ntraj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qutip.solver.Result
的用法示例。
在下文中一共展示了Result.ntraj方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mcsolve_f90
# 需要导入模块: from qutip.solver import Result [as 别名]
# 或者: from qutip.solver.Result import ntraj [as 别名]
def mcsolve_f90(H, psi0, tlist, c_ops, e_ops, ntraj=None,
options=Options(), sparse_dms=True, serial=False,
ptrace_sel=[], calc_entropy=False):
"""
Monte-Carlo wave function solver with fortran 90 backend.
Usage is identical to qutip.mcsolve, for problems without explicit
time-dependence, and with some optional input:
Parameters
----------
H : qobj
System Hamiltonian.
psi0 : qobj
Initial state vector
tlist : array_like
Times at which results are recorded.
ntraj : int
Number of trajectories to run.
c_ops : array_like
``list`` or ``array`` of collapse operators.
e_ops : array_like
``list`` or ``array`` of operators for calculating expectation values.
options : Options
Instance of solver options.
sparse_dms : boolean
If averaged density matrices are returned, they will be stored as
sparse (Compressed Row Format) matrices during computation if
sparse_dms = True (default), and dense matrices otherwise. Dense
matrices might be preferable for smaller systems.
serial : boolean
If True (default is False) the solver will not make use of the
multiprocessing module, and simply run in serial.
ptrace_sel: list
This optional argument specifies a list of components to keep when
returning a partially traced density matrix. This can be convenient for
large systems where memory becomes a problem, but you are only
interested in parts of the density matrix.
calc_entropy : boolean
If ptrace_sel is specified, calc_entropy=True will have the solver
return the averaged entropy over trajectories in results.entropy. This
can be interpreted as a measure of entanglement. See Phys. Rev. Lett.
93, 120408 (2004), Phys. Rev. A 86, 022310 (2012).
Returns
-------
results : Result
Object storing all results from simulation.
"""
if ntraj is None:
ntraj = options.ntraj
if psi0.type != 'ket':
raise Exception("Initial state must be a state vector.")
config.options = options
# set num_cpus to the value given in qutip.settings
# if none in Options
if not config.options.num_cpus:
config.options.num_cpus = qutip.settings.num_cpus
# set initial value data
if options.tidy:
config.psi0 = psi0.tidyup(options.atol).full()
else:
config.psi0 = psi0.full()
config.psi0_dims = psi0.dims
config.psi0_shape = psi0.shape
# set general items
config.tlist = tlist
if isinstance(ntraj, (list, np.ndarray)):
raise Exception("ntraj as list argument is not supported.")
else:
config.ntraj = ntraj
# ntraj_list = [ntraj]
# set norm finding constants
config.norm_tol = options.norm_tol
config.norm_steps = options.norm_steps
if not options.rhs_reuse:
config.soft_reset()
# no time dependence
config.tflag = 0
# check for collapse operators
if len(c_ops) > 0:
config.cflag = 1
else:
config.cflag = 0
# Configure data
_mc_data_config(H, psi0, [], c_ops, [], [], e_ops, options, config)
# Load Monte Carlo class
mc = _MC_class()
# Set solver type
if (options.method == 'adams'):
mc.mf = 10
elif (options.method == 'bdf'):
mc.mf = 22
else:
if debug:
print('Unrecognized method for ode solver, using "adams".')
mc.mf = 10
#.........这里部分代码省略.........
示例2: mcsolve
# 需要导入模块: from qutip.solver import Result [as 别名]
# 或者: from qutip.solver.Result import ntraj [as 别名]
def mcsolve(H, psi0, tlist, c_ops, e_ops, ntraj=None,
args={}, options=None, progress_bar=True,
map_func=None, map_kwargs=None):
"""Monte Carlo evolution of a state vector :math:`|\psi \\rangle` for a
given Hamiltonian and sets of collapse operators, and possibly, operators
for calculating expectation values. Options for the underlying ODE solver
are given by the Options class.
mcsolve supports time-dependent Hamiltonians and collapse operators using
either Python functions of strings to represent time-dependent
coefficients. Note that, the system Hamiltonian MUST have at least one
constant term.
As an example of a time-dependent problem, consider a Hamiltonian with two
terms ``H0`` and ``H1``, where ``H1`` is time-dependent with coefficient
``sin(w*t)``, and collapse operators ``C0`` and ``C1``, where ``C1`` is
time-dependent with coeffcient ``exp(-a*t)``. Here, w and a are constant
arguments with values ``W`` and ``A``.
Using the Python function time-dependent format requires two Python
functions, one for each collapse coefficient. Therefore, this problem could
be expressed as::
def H1_coeff(t,args):
return sin(args['w']*t)
def C1_coeff(t,args):
return exp(-args['a']*t)
H = [H0, [H1, H1_coeff]]
c_ops = [C0, [C1, C1_coeff]]
args={'a': A, 'w': W}
or in String (Cython) format we could write::
H = [H0, [H1, 'sin(w*t)']]
c_ops = [C0, [C1, 'exp(-a*t)']]
args={'a': A, 'w': W}
Constant terms are preferably placed first in the Hamiltonian and collapse
operator lists.
Parameters
----------
H : :class:`qutip.Qobj`
System Hamiltonian.
psi0 : :class:`qutip.Qobj`
Initial state vector
tlist : array_like
Times at which results are recorded.
ntraj : int
Number of trajectories to run.
c_ops : array_like
single collapse operator or ``list`` or ``array`` of collapse
operators.
e_ops : array_like
single operator or ``list`` or ``array`` of operators for calculating
expectation values.
args : dict
Arguments for time-dependent Hamiltonian and collapse operator terms.
options : Options
Instance of ODE solver options.
progress_bar: BaseProgressBar
Optional instance of BaseProgressBar, or a subclass thereof, for
showing the progress of the simulation. Set to None to disable the
progress bar.
map_func: function
A map function for managing the calls to the single-trajactory solver.
map_kwargs: dictionary
Optional keyword arguments to the map_func function.
Returns
-------
results : :class:`qutip.solver.Result`
Object storing all results from the simulation.
.. note::
It is possible to reuse the random number seeds from a previous run
of the mcsolver by passing the output Result object seeds via the
Options class, i.e. Options(seeds=prev_result.seeds).
"""
if debug:
print(inspect.stack()[0][3])
#.........这里部分代码省略.........
示例3: evolve_serial
# 需要导入模块: from qutip.solver import Result [as 别名]
# 或者: from qutip.solver.Result import ntraj [as 别名]
def evolve_serial(self, args):
if debug:
print(inspect.stack()[0][3] + ":" + str(os.getpid()))
# run ntraj trajectories for one process via fortran
# get args
queue, ntraj, instanceno, rngseed = args
# initialize the problem in fortran
_init_tlist()
_init_psi0()
if (self.ptrace_sel != []):
_init_ptrace_stuff(self.ptrace_sel)
_init_hamilt()
if (config.c_num != 0):
_init_c_ops()
if (config.e_num != 0):
_init_e_ops()
# set options
qtf90.qutraj_run.n_c_ops = config.c_num
qtf90.qutraj_run.n_e_ops = config.e_num
qtf90.qutraj_run.ntraj = ntraj
qtf90.qutraj_run.unravel_type = self.unravel_type
qtf90.qutraj_run.average_states = config.options.average_states
qtf90.qutraj_run.average_expect = config.options.average_expect
qtf90.qutraj_run.init_result(config.psi0_shape[0],
config.options.atol,
config.options.rtol, mf=self.mf,
norm_steps=config.norm_steps,
norm_tol=config.norm_tol)
# set optional arguments
qtf90.qutraj_run.order = config.options.order
qtf90.qutraj_run.nsteps = config.options.nsteps
qtf90.qutraj_run.first_step = config.options.first_step
qtf90.qutraj_run.min_step = config.options.min_step
qtf90.qutraj_run.max_step = config.options.max_step
qtf90.qutraj_run.norm_steps = config.options.norm_steps
qtf90.qutraj_run.norm_tol = config.options.norm_tol
# use sparse density matrices during computation?
qtf90.qutraj_run.rho_return_sparse = self.sparse_dms
# calculate entropy of reduced density matrice?
qtf90.qutraj_run.calc_entropy = self.calc_entropy
# run
show_progress = 1 if debug else 0
qtf90.qutraj_run.evolve(instanceno, rngseed, show_progress)
# construct Result instance
sol = Result()
sol.ntraj = ntraj
# sol.col_times = qtf90.qutraj_run.col_times
# sol.col_which = qtf90.qutraj_run.col_which-1
sol.col_times, sol.col_which = self.get_collapses(ntraj)
if (config.e_num == 0):
sol.states = self.get_states(len(config.tlist), ntraj)
else:
sol.expect = self.get_expect(len(config.tlist), ntraj)
if (self.calc_entropy):
sol.entropy = self.get_entropy(len(config.tlist))
if (not self.serial_run):
# put to queue
queue.put(sol)
queue.join()
# deallocate stuff
# finalize()
return sol
示例4: mcsolve
# 需要导入模块: from qutip.solver import Result [as 别名]
# 或者: from qutip.solver.Result import ntraj [as 别名]
def mcsolve(H, psi0, tlist, c_ops, e_ops, ntraj=None, args={}, options=Options()):
"""Monte-Carlo evolution of a state vector :math:`|\psi \\rangle` for a
given Hamiltonian and sets of collapse operators, and possibly, operators
for calculating expectation values. Options for the underlying ODE solver
are given by the Options class.
mcsolve supports time-dependent Hamiltonians and collapse operators using
either Python functions of strings to represent time-dependent
coefficients. Note that, the system Hamiltonian MUST have at least one
constant term.
As an example of a time-dependent problem, consider a Hamiltonian with two
terms ``H0`` and ``H1``, where ``H1`` is time-dependent with coefficient
``sin(w*t)``, and collapse operators ``C0`` and ``C1``, where ``C1`` is
time-dependent with coeffcient ``exp(-a*t)``. Here, w and a are constant
arguments with values ``W`` and ``A``.
Using the Python function time-dependent format requires two Python
functions, one for each collapse coefficient. Therefore, this problem could
be expressed as::
def H1_coeff(t,args):
return sin(args['w']*t)
def C1_coeff(t,args):
return exp(-args['a']*t)
H=[H0,[H1,H1_coeff]]
c_op_list=[C0,[C1,C1_coeff]]
args={'a':A,'w':W}
or in String (Cython) format we could write::
H=[H0,[H1,'sin(w*t)']]
c_op_list=[C0,[C1,'exp(-a*t)']]
args={'a':A,'w':W}
Constant terms are preferably placed first in the Hamiltonian and collapse
operator lists.
Parameters
----------
H : qobj
System Hamiltonian.
psi0 : qobj
Initial state vector
tlist : array_like
Times at which results are recorded.
ntraj : int
Number of trajectories to run.
c_ops : array_like
single collapse operator or ``list`` or ``array`` of collapse
operators.
e_ops : array_like
single operator or ``list`` or ``array`` of operators for calculating
expectation values.
args : dict
Arguments for time-dependent Hamiltonian and collapse operator terms.
options : Options
Instance of ODE solver options.
Returns
-------
results : Result
Object storing all results from simulation.
"""
if debug:
print(inspect.stack()[0][3])
if ntraj is None:
ntraj = options.ntraj
if not psi0.isket:
raise Exception("Initial state must be a state vector.")
if isinstance(c_ops, Qobj):
c_ops = [c_ops]
if isinstance(e_ops, Qobj):
e_ops = [e_ops]
if isinstance(e_ops, dict):
e_ops_dict = e_ops
e_ops = [e for e in e_ops.values()]
else:
e_ops_dict = None
config.options = options
if isinstance(ntraj, list):
config.progress_bar = TextProgressBar(max(ntraj))
else:
config.progress_bar = TextProgressBar(ntraj)
# set num_cpus to the value given in qutip.settings if none in Options
#.........这里部分代码省略.........