@@ -55,6 +55,10 @@ def _set_universe(self, u: mda.Universe):
5555 """Internal: Set the universe"""
5656 self .u = u
5757
58+ def _reset_frame_latest (self ):
59+ """Internal: Reset frame to latest timestep"""
60+ _ = self .u .trajectory [- 1 ]
61+
5862 def _get_inputs (self ):
5963 """Internal: Get the current instance inputs"""
6064 inputs = getattr (self , "_inputs" )
@@ -172,33 +176,24 @@ def run_every_frame(self) -> None:
172176
173177 """
174178
175- def run_batch (self , batch_size : int ) -> None :
179+ def run_batch (self ) -> None :
176180 """run_batch handler
177181
178182 This handler is called every time a new batch of timesteps is full
179183 and ready to be run if the run frequency is set to `batch`
180184 (`_run_frequency='batch'`).
181185
182- Parameters
183- ----------
184- batch_size: int
185- The batch size, which indicates the number of buffered timesteps
186- available in the buffer is passed
186+ `self.u.trajectory.buffer_size` is the size of the buffer / batch
187+ that can be used by the widget class.
187188
188189 """
189190
190- def get_parallel_job (self , batch_size : int ) -> Any :
191+ def get_parallel_job (self ) -> Any :
191192 """get_parallel_job handler
192193
193194 This handler is called if the run mode is set to `parallel`
194195 (`_run_mode='parallel'`) to get the parallel job to run.
195196
196- Parameters
197- ----------
198- batch_size: int
199- The configured batch size to use in the parallel jobs
200- if their run frequency is `batch`
201-
202197 Returns
203198 -------
204199 job: Any
@@ -272,7 +267,7 @@ def _validate_widget_class(cls, widget_class: WidgetBase) -> None:
272267 # check for one of the run methods to exist with correct params
273268 run_methods = {
274269 "run_every_frame" : 1 ,
275- "run_batch" : 2 ,
270+ "run_batch" : 1 ,
276271 }
277272 has_valid_run_method = False
278273 for run_method , n_params in run_methods .items ():
@@ -546,11 +541,11 @@ def custom_setstate(self, state):
546541 IMDReader .__setstate__ = custom_setstate
547542 IMDReader .__getstate__ = custom_getstate
548543
549- def _run_parallel_jobs (self , parallel_widgets , batch_size , parallel_results ):
544+ def _run_parallel_jobs (self , parallel_widgets , parallel_results ):
550545 """Internal: Run parallel jobs using joblib.Parallel"""
551546 parallel_jobs = []
552547 for widget in parallel_widgets :
553- parallel_jobs .append (widget .get_parallel_job (batch_size ))
548+ parallel_jobs .append (widget .get_parallel_job ())
554549 try :
555550 results = Parallel (
556551 n_jobs = self .n_jobs , initializer = WidgetManager ._patch_IMDReader
@@ -560,7 +555,7 @@ def _run_parallel_jobs(self, parallel_widgets, batch_size, parallel_results):
560555 except Exception : # pragma: no cover
561556 logger .exception ("Parallel run failed for jobs %s" , parallel_jobs )
562557
563- def run_widgets (self , uid : int , batch_ready : bool , batch_size : int ) -> None :
558+ def run_widgets (self , uid : int , batch_ready : bool ) -> None :
564559 """Run widget instances
565560
566561 Parameters
@@ -571,9 +566,6 @@ def run_widgets(self, uid: int, batch_ready: bool, batch_size: int) -> None:
571566 batch_ready: bool
572567 Flag indicating if a batch of timesteps is full
573568
574- batch_size: int
575- Size of the batch
576-
577569 """
578570 # collect widgets that need to be run
579571 parallel_widgets = []
@@ -594,19 +586,19 @@ def run_widgets(self, uid: int, batch_ready: bool, batch_size: int) -> None:
594586 target = self ._run_parallel_jobs ,
595587 args = (
596588 parallel_widgets ,
597- batch_size ,
598589 parallel_results ,
599590 ),
600591 )
601592 parallel_thread .start ()
602593 # run serial widgets
603594 for widget in serial_widgets :
595+ widget ._reset_frame_latest ()
604596 with _widget_uuid_in_metadata (widget .uuid ):
605597 try :
606598 if widget ._run_frequency == "every-frame" :
607599 widget .run_every_frame ()
608600 elif batch_ready :
609- widget .run_batch (batch_size )
601+ widget .run_batch ()
610602 # pylint: disable=broad-exception-caught
611603 except Exception : # pragma: no cover
612604 logger .exception ("Serial run failed for widget %s" , widget .uuid )
0 commit comments