Skip to content

Commit

Permalink
handle case where integration may fail in on attractor sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
jbial committed Oct 1, 2024
1 parent ed5e62e commit d9b24db
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions dysts/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,26 @@ class OnAttractorInitCondSampler(BaseSampler):
events: Optional[List[Callable]] = None # solve_ivp events

def __call__(self, ic: Array, system: BaseDyn) -> Array:
if system.name is None:
raise ValueError("System must have a name")

# make reference trajectory if not already cached
if system.name not in self.trajectory_cache:
if self.verbose:
print(f"Adding {system.name} to trajectory cache...")

# Integrate the system with default parameters
reference_traj = system.make_trajectory(
self.reference_traj_length,
events=self.events,
)[self.reference_traj_transient :]
)

if (
reference_traj is None
): # if integrate fails, resulting in an incomplete trajectory
# if integrate fails, resulting in an incomplete trajectory
if reference_traj is None:
raise ValueError(
f"Failed to integrate the system {system.name} with ic {system.ic} and params {system.params}"
)

self.trajectory_cache[system.name] = reference_traj
else:
self.trajectory_cache[system.name] = reference_traj[
self.reference_traj_transient :
]

trajectory = self.trajectory_cache[system.name]

Expand Down

0 comments on commit d9b24db

Please sign in to comment.