@@ -226,6 +226,25 @@ def _generate_propagator_matrix(self, A) -> sympy.Matrix:
226226
227227 return P
228228
229+ def _merge_conditions (self , solver_dict ):
230+ r"""merge together conditions (a OR b OR c OR...) if the propagators and update_expressions are the same"""
231+
232+ for condition , sub_solver_dict in solver_dict ["conditions" ].items ():
233+ for condition2 , sub_solver_dict2 in solver_dict ["conditions" ].items ():
234+ if condition == condition2 :
235+ # don't check a condition against itself
236+ continue
237+
238+ if sub_solver_dict ["propagators" ] == sub_solver_dict2 ["propagators" ] and sub_solver_dict ["update_expressions" ] == sub_solver_dict2 ["update_expressions" ]:
239+ # ``condition`` and ``condition2`` can be merged
240+ solver_dict ["conditions" ]["(" + condition + ") || (" + condition2 + ")" ] = sub_solver_dict
241+ solver_dict ["conditions" ].pop (condition )
242+ solver_dict ["conditions" ].pop (condition2 )
243+ print ("\n \n \n \n \n \n wqweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeen\n \n \n \n \n " )
244+ return self ._merge_conditions (solver_dict )
245+
246+ return solver_dict
247+
229248 def generate_propagator_solver (self , disable_singularity_detection : bool = False ):
230249 r"""
231250 Generate the propagator matrix and symbolic expressions for propagator-based updates; return as JSON.
@@ -303,7 +322,7 @@ def generate_propagator_solver(self, disable_singularity_detection: bool = False
303322 solver_dict ["conditions" ][condition_str ] = {"propagators" : solver_dict_conditional ["propagators" ],
304323 "update_expressions" : solver_dict_conditional ["update_expressions" ]}
305324
306- # XXX: TODO: merge together conditions (a OR b OR c OR...) if the propagators and update_expressions are the same
325+ solver_dict = self . _merge_conditions ( solver_dict )
307326
308327 return solver_dict
309328
0 commit comments