@@ -33,6 +33,7 @@ class GuideHandler:
3333 def __init__ (self , producers_and_getters , set_methods ):
3434 self .cur_term = 0
3535 self .current_step = - 1
36+ self .start_point = 0
3637 self .producers_and_getters = producers_and_getters
3738 self .set_methods = set_methods
3839
@@ -131,8 +132,10 @@ def log_get_stale_warning(self, name, next_step):
131132 def try_perform_forward_producer_step (self , zephyr , method , * method_args , ** method_kwargs ):
132133 name = method .__name__
133134 next_step = self .producer_to_step_map [name ]
134- if name in self .set_methods :
135+ if name in self .set_methods : # set method will update start point and start new iteration
135136 self .try_log_skipping_steps_warning (name , next_step )
137+ self .start_point = next_step
138+ self .cur_term += 1
136139 # next_step == 0, set method (already warned), or previous step is up to term
137140 res = self .perform_producer_step (
138141 zephyr , method , * method_args , ** method_kwargs )
@@ -143,12 +146,17 @@ def try_perform_forward_producer_step(self, zephyr, method, *method_args, **meth
143146 def try_perform_backward_producer_step (self , zephyr , method , * method_args , ** method_kwargs ):
144147 name = method .__name__
145148 next_step = self .producer_to_step_map [name ]
146- self . try_log_making_stale_warning ( next_step )
149+ # starting new iteration
147150 self .cur_term += 1
148- # mark everything prior to next step as current term
149- for i in range (0 , next_step ):
150- if self .terms [i ] != - 1 :
151- self .terms [i ] = self .cur_term
151+ if next_step == 0 or name in self .set_methods :
152+ self .start_point = next_step
153+ else : # key method
154+ # mark everything from start point to next step as current term
155+ for i in range (self .start_point , next_step ):
156+ if self .terms [i ] != - 1 :
157+ self .terms [i ] = self .cur_term
158+
159+ self .try_log_making_stale_warning (next_step )
152160 res = self .perform_producer_step (
153161 zephyr , method , * method_args , ** method_kwargs )
154162 return res
@@ -185,33 +193,35 @@ def try_perform_inconsistent_producer_step( # add using stale and overwriting
185193 Otherwise, please perform step { prev_step } \
186194 with { prev_key_method } or { prev_set_method } ." )
187195 # inconsistent backward step: performing set method at nonzero step
188- elif next_step < self .current_step and name in self .set_method :
189- first_set_method = self .producers_and_getters [0 ][0 ][1 ].__name__
190- corr_key_method = self .producers_and_getters [next_step ][0 ][0 ].__name__
191- LOGGER .warning (f"Unable to perform { name } because you are going backwards \
192- and performing step { next_step } with a set method.\
193- You can only perform a backwards step with a set \
194- method at step 0: { first_set_method } .\
195- If you would like to perform step { next_step } , \
196- please use the corresponding key method: { corr_key_method } ." )
196+ # elif next_step < self.current_step and name in self.set_method:
197+ # first_set_method = self.producers_and_getters[0][0][1].__name__
198+ # corr_key_method = self.producers_and_getters[next_step][0][0].__name__
199+ # LOGGER.warning(f"Unable to perform {name} because you are going backwards \
200+ # and performing step {next_step} with a set method.\
201+ # You can only perform a backwards step with a set \
202+ # method at step 0: {first_set_method}.\
203+ # If you would like to perform step {next_step}, \
204+ # please use the corresponding key method: {corr_key_method}.")
197205 # inconsistent backward step: performing key method but previous step is not up to date
198206 elif next_step < self .current_step and self .terms [next_step - 1 ] != self .cur_term :
199207 prev_step = next_step - 1
200208 prev_key_method = self .producers_and_getters [prev_step ][0 ][0 ].__name__
201209 corr_set_method = self .producers_and_getters [next_step ][0 ][1 ].__name__
210+ prev_get_method = self .producers_and_getters [prev_step ][1 ][0 ].__name__
211+ prev_set_method = self .producers_and_getters [prev_step ][0 ][1 ].__name__
202212 LOGGER .warning (f"Unable to perform { name } because you are going \
203213 backwards and starting a new iteration by\
204214 performing a key method at step { next_step } \
205215 but the result of the previous step,\
206- step { prev_step } , is not up to date .\
207- Please perform step { prev_step } with { prev_key_method } first. \
208- If you already have the data for \
209- step { next_step } from the previous iteration, \
210- re-performing { prev_key_method } with the same \
211- arguments should generate the same result .\
212- Otherwise, if the data is unrelated, \
213- please create a new Zephyr instance \
214- and use its { corr_set_method } method. " )
216+ step { prev_step } , is STALE .\
217+ If you want to use the STALE result of the PREVIOUS step, \
218+ you can call { prev_get_method } to get the data, then \
219+ { prev_set_method } to set the data, and then recall this method. \
220+ If you want to regenerate the data of the PREVIOUS step, \
221+ please call { prev_key_method } , and then recall this method .\
222+ If you already have the data for THIS step, you can \
223+ call { corr_set_method } to set the data. \
224+ " )
215225
216226 def try_perform_getter_step (self , zephyr , method , * method_args , ** method_kwargs ):
217227 name = method .__name__
@@ -234,14 +244,11 @@ def guide_step(self, zephyr, method, *method_args, **method_kwargs):
234244 # up-todate
235245 next_step = self .producer_to_step_map [method_name ]
236246 if (next_step == 0 or # 0 step always valid, starting new iteration
247+ # set method always valid, but will update start point and start new iteration
248+ method_name in self .set_methods or
249+ # key method valid if previous step is up to date
250+ self .terms [next_step - 1 ] == self .cur_term ):
237251 # forward step only valid if set method or key method w/ no skips
238- (next_step >= self .current_step and
239- (method_name in self .set_methods or
240- self .terms [next_step - 1 ] == self .cur_term )) or
241- # backward step only valid if key method w/ previous step up to date
242- (next_step < self .current_step and
243- (method_name not in self .set_methods and
244- self .terms [next_step - 1 ] == self .cur_term ))):
245252 res = self .try_perform_producer_step (
246253 zephyr , method , * method_args , ** method_kwargs )
247254 return res
0 commit comments