scHopfield.dynamics.simulate_trajectory

scHopfield.dynamics.simulate_trajectory(adata: AnnData, cluster: str, cell_idx: int | List[int], t_span: ndarray, spliced_key: str = 'Ms', degradation_key: str = 'gamma', method: str = 'euler', x_max_percentile: float = 99.0, n_jobs: int = 1, verbose: bool = False) ndarray | List[ndarray][source]

Simulate trajectory from one or more cells’ initial states.

Parameters:
  • adata (AnnData) – Annotated data object with fitted interactions

  • cluster (str) – Cluster name

  • cell_idx (int or list of int) – Index or list of indices of cells to use as initial conditions. Returns a single trajectory array for a scalar, or a list for a list.

  • t_span (np.ndarray) – Time points for simulation

  • spliced_key (str, optional) – Key for expression data

  • degradation_key (str, optional) – Key for degradation rates

  • method (str, optional (default: 'euler')) – Integration method: - ‘euler’: Simple Euler method with clipping (stable, recommended) - ‘odeint’: scipy.integrate.odeint - ‘RK45’, ‘RK23’, etc.: scipy.integrate.solve_ivp methods

  • x_max_percentile (float, optional (default: 99.0)) – Percentile of expression to use as upper bound. Prevents divergence. Set to None to disable upper bound.

  • n_jobs (int, optional (default: 1)) – Number of parallel jobs when cell_idx is a list. 1 = sequential, -1 = all cores. Uses threads; no effect for a single cell.

  • verbose (bool, optional (default: False)) – Print simulation info

Returns:

Trajectory (len(t_span) × n_genes) for a scalar cell_idx, or a list of trajectories for a list input.

Return type:

np.ndarray or list of np.ndarray