Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
71044ec
update
jhprinz Aug 13, 2016
c85fc53
fix
jhprinz Aug 13, 2016
c4c8724
fix
jhprinz Aug 13, 2016
67534f1
add tests
jhprinz Aug 14, 2016
044aa82
Merge branch 'ala' into enginefail
jhprinz Aug 19, 2016
88cd009
Merge branch 'ala' into enginefail
jhprinz Aug 19, 2016
ee8590f
update
jhprinz Aug 19, 2016
5e0f6e6
add tests
jhprinz Aug 19, 2016
6051a80
udpate
jhprinz Aug 19, 2016
c499aa5
more tests
jhprinz Aug 19, 2016
a0bf940
added correct errors
jhprinz Aug 19, 2016
f81394d
fix
jhprinz Aug 19, 2016
3895254
updates
jhprinz Aug 19, 2016
6e830cf
Merge branch 'ala' into enginefail
jhprinz Aug 19, 2016
d2cdd58
little updates
jhprinz Aug 20, 2016
50aed24
Merge branch 'ala' into enginefail
jhprinz Aug 21, 2016
61411d8
fix a special case in a test
jhprinz Aug 21, 2016
d8d696f
Merge branch 'master' of github.com:choderalab/openpathsampling into …
jhprinz Aug 22, 2016
3daf330
add tests
jhprinz Aug 23, 2016
207546d
fix test using nan template
jhprinz Aug 23, 2016
150f464
update test
jhprinz Aug 23, 2016
3acb843
fix default options
jhprinz Aug 23, 2016
0f81a6e
fix test
jhprinz Aug 23, 2016
f8061b5
fixes
jhprinz Aug 23, 2016
8bf1568
cleanup
jhprinz Aug 23, 2016
f7113aa
add example notebook
jhprinz Aug 23, 2016
5643ecf
little cleanup
jhprinz Aug 23, 2016
9810676
little cleanup
jhprinz Aug 23, 2016
c2eff38
little fix in generate
jhprinz Aug 23, 2016
25cfb40
docstring
jhprinz Aug 23, 2016
454749e
from default `stop` to `fail`
jhprinz Aug 23, 2016
f275912
revert notebook
jhprinz Aug 23, 2016
873a892
revert
jhprinz Aug 23, 2016
76009a1
revert
jhprinz Aug 23, 2016
003758a
revert
jhprinz Aug 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added correct errors
  • Loading branch information
jhprinz committed Aug 19, 2016
commit a0bf940f07411358660cae67ffd4aba7d2e2644d
4 changes: 3 additions & 1 deletion openpathsampling/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

import features

from dynamics_engine import DynamicsEngine, NoEngine
from dynamics_engine import (
DynamicsEngine, NoEngine, EngineError,
EngineNaNError, EngineMaxLengthError)
60 changes: 45 additions & 15 deletions openpathsampling/engines/dynamics_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@


# =============================================================================
# Multi-State Transition Interface Sampling
# Base dynamics engine class
# =============================================================================

class EngineError(Exception):
def __init__(self, message, last_trajectory):
# Call the base class constructor with the parameters it needs
super(EngineError, self).__init__(message)

# Now for your custom code...
self.last_trajectory = last_trajectory

class EngineMaxLengthError(EngineError):
pass


class EngineNaNError(EngineError):
pass


class DynamicsEngine(StorableNamedObject):
"""
Expand Down Expand Up @@ -525,9 +540,10 @@ def iter_generate(self, initial, running=None, direction=+1,
on = self.on_max_length

if on == 'fail':
final_error = RuntimeError(
final_error = EngineMaxLengthError(
'Hit maximal length of %d frames.' %
self.options['n_frames_max']
self.options['n_frames_max'],
trajectory
)
break
elif on == 'ignore':
Expand All @@ -541,27 +557,41 @@ def iter_generate(self, initial, running=None, direction=+1,
attempt_max_length += 1
if attempt_max_length > self.retries_when_max_length:
if self.on_nan == 'fail':
final_error = RuntimeError(
final_error = EngineMaxLengthError(
'Failed to generate trajectory without '
'hitting max length after %d attempts' %
attempt_max_length)
attempt_max_length,
trajectory)
break

if has_nan:
attempt_nan += 1
if attempt_nan > self.retries_when_nan:
if self.on_nan == 'fail':
final_error = RuntimeError(
on = self.on_nan
if on == 'fail':
final_error = EngineNaNError('`nan` in snapshot')
elif on == 'retry':
attempt_nan += 1
if attempt_nan > self.retries_when_nan:
final_error = EngineNaNError(
'Failed to generate trajectory without `nan` '
'after %d attempts' % attempt_nan)
'after %d attempts' % attempt_error,
trajectory)
elif on == 'ignore':
pass

if has_error:
attempt_error += 1
if attempt_error > self.retries_when_nan:
if self.on_error == 'fail':
on = self.on_nan
if on == 'fail':
final_error = errors[-1]
del errors[-1]
elif on == 'retry':
attempt_error += 1
if attempt_error > self.retries_when_error:
final_error = RuntimeError(
'Failed to generate trajectory without error '
'after %d attempts' % attempt_error)
'Failed to generate trajectory without `nan` '
'after %d attempts' % attempt_error,
trajectory)
elif on == 'ignore':
pass

elif stop:
valid = True
Expand Down
45 changes: 42 additions & 3 deletions openpathsampling/pathmover.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,16 @@ def move(self, replica_state):
return ReplicaState(d.items())


class SampleNaNError(Exception):
def __init__(self, message, trial_sample):
super(SampleNaNError, self).__init__(message)
self.trial_sample = trial_sample


class MoveChangeNaNError(Exception):
pass


class PathMover(TreeMixin, StorableNamedObject):
"""
A PathMover is the description of a move in replica space.
Expand Down Expand Up @@ -1104,8 +1114,16 @@ def move(self, sample_set):
# 2. pick samples from these ensembles
samples = [self.select_sample(sample_set, ens) for ens in ensembles]

# 3. pass these samples to the generator
trials = self(*samples)
try:
# 3. pass these samples to the generator
trials = self(*samples)
except SampleNaNError as e:
return paths.RejectedSampleMoveChange(
samples=e.trial_sample,
mover=self,
details=paths.MoveDetails(
error='NaN')
)

# 4. accept/reject
accepted, details = self._accept(trials)
Expand All @@ -1124,6 +1142,7 @@ def move(self, sample_set):
details=details
)


@abc.abstractmethod
def __call__(self, *args):
"""Generate trial samples directly
Expand Down Expand Up @@ -1197,7 +1216,27 @@ def __call__(self, input_sample):

shooting_index = self.selector.pick(initial_trajectory)

trial_trajectory = self._run(initial_trajectory, shooting_index)
try:
trial_trajectory = self._run(initial_trajectory, shooting_index)
except paths.engines.EngineError as e:
trial_trajectory = e.last_trajectory

trial_details = paths.SampleDetails(
initial_trajectory=initial_trajectory,
shooting_snapshot=initial_trajectory[shooting_index],
error='NaN'
)

trial = paths.Sample(
replica=replica,
trajectory=trial_trajectory,
ensemble=self.target_ensemble,
parent=input_sample,
details=trial_details,
mover=self
)

raise SampleNaNError('Sample with NaN', trial)

bias = self.selector.probability_ratio(
initial_trajectory[shooting_index],
Expand Down