Skip to content

Commit

Permalink
Merge pull request #2234 from pmenczel/nmmcsolve-bandaid
Browse files Browse the repository at this point in the history
Disable improved sampling for nm_mcsolve
  • Loading branch information
nwlambert committed Oct 17, 2023
2 parents 7f28e55 + ec74d98 commit 0c5bf63
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changes/2234.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disabled broken "improved sampling" for `nm_mcsolve`.
4 changes: 2 additions & 2 deletions qutip/solver/mcsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def run(self, state, tlist, ntraj=1, *,
probability is used as a lower-bound for random numbers in future
monte carlo runs
"""
if not self.options["improved_sampling"]:
if not self.options.get("improved_sampling", False):
return super().run(state, tlist, ntraj=ntraj, args=args,
e_ops=e_ops, timeout=timeout,
target_tol=target_tol, seed=seed)
Expand Down Expand Up @@ -526,7 +526,7 @@ def _get_integrator(self):

@property
def resultclass(self):
if self.options["improved_sampling"]:
if self.options.get("improved_sampling", False):
return McResultImprovedSampling
else:
return McResult
Expand Down
84 changes: 84 additions & 0 deletions qutip/solver/nm_mcsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def nm_mcsolve(H, state, tlist, ops_and_rates=(), e_ops=None, ntraj=500, *,
An upper bound on the number of subintervals used in the adaptive
integration of the martingale.
Note that the 'improved_sampling' option is not currently supported.
seeds : int, SeedSequence, list, [optional]
Seed for the random number generator. It can be a single seed used to
spawn seeds for each trajectory or a list of seeds, one for each
Expand Down Expand Up @@ -329,6 +331,7 @@ class NonMarkovianMCSolver(MCSolver):
"completeness_atol": 1e-8,
"martingale_quad_limit": 100,
}
del solver_options["improved_sampling"]

# both classes will be partially initialized in constructor
trajectory_resultclass = NmmcTrajectoryResult
Expand Down Expand Up @@ -516,6 +519,87 @@ def run(self, state, tlist, *args, **kwargs):

return result

@property
def options(self):
"""
Options for non-Markovian Monte Carlo solver:
store_final_state: bool, default=False
Whether or not to store the final state of the evolution in the
result class.
store_states: bool, default=None
Whether or not to store the state vectors or density matrices.
On `None` the states will be saved if no expectation operators are
given.
progress_bar: str {'text', 'enhanced', 'tqdm', ''}, default="text"
How to present the solver progress.
'tqdm' uses the python module of the same name and raise an error
if not installed. Empty string or False will disable the bar.
progress_kwargs: dict, default={"chunk_size":10}
Arguments to pass to the progress_bar. Qutip's bars use
``chunk_size``.
keep_runs_results: bool
Whether to store results from all trajectories or just store the
averages.
method: str, default="adams"
Which ODE integrator methods are supported.
map: str {"serial", "parallel", "loky"}
How to run the trajectories. "parallel" uses concurent module to
run in parallel while "loky" use the module of the same name to do
so.
job_timeout: None, int
Maximum time to compute one trajectory.
num_cpus: None, int
Number of cpus to use when running in parallel. ``None`` detect the
number of available cpus.
bitgenerator: {None, "MT19937", "PCG64", "PCG64DXSM", ...}
Which of numpy.random's bitgenerator to use. With ``None``, your
numpy version's default is used.
mc_corr_eps: float
Small number used to detect non-physical collapse caused by
numerical imprecision.
norm_t_tol: float
Tolerance in time used when finding the collapse.
norm_tol: float
Tolerance in norm used when finding the collapse.
norm_steps: int
Maximum number of tries to find the collapse.
completeness_rtol: float, default=1e-5
Used in determining whether the given Lindblad operators satisfy
a certain completeness relation. If they do not, an additional
Lindblad operator is added automatically (with zero rate).
completeness_atol: float, default=1e-8
Used in determining whether the given Lindblad operators satisfy
a certain completeness relation. If they do not, an additional
Lindblad operator is added automatically (with zero rate).
martingale_quad_limit: float or int, default=100
An upper bound on the number of subintervals used in the adaptive
integration of the martingale.
Note that the 'improved_sampling' option is not currently supported.
"""
return self._options

@options.setter
def options(self, new_options):
MCSolver.options.fset(self, new_options)

start.__doc__ = MultiTrajSolver.start.__doc__
step.__doc__ = MultiTrajSolver.step.__doc__
run.__doc__ = MultiTrajSolver.run.__doc__

0 comments on commit 0c5bf63

Please sign in to comment.