@@ -327,6 +327,16 @@ def _MathAddMul(self, model: Union[MathAdd, MathMul]):
327327class PruneMathExpr (RewriteRule ):
328328 """
329329 This is constant fold operation where scalar addition, multiplication and power are simplified
330+
331+ Args:
332+ model (MathExpr): The rule only acts on [`MathExpr`][oqd_core.interface.math.MathExpr] objects.
333+
334+ Returns:
335+ model (MathExpr):
336+
337+ Assumptions:
338+ None
339+
330340 """
331341
332342 def map_MathAdd (self , model ):
@@ -359,6 +369,20 @@ def map_MathPow(self, model):
359369
360370
361371class SubstituteMathVar (RewriteRule ):
372+ """
373+ This rule substitutes a MathVar with another MathExpr
374+
375+ Args:
376+ model (MathExpr): The rule only acts on [`MathExpr`][oqd_core.interface.math.MathExpr] objects.
377+
378+ Returns:
379+ model (MathExpr):
380+
381+ Assumptions:
382+ None
383+
384+ """
385+
362386 def __init__ (self , variable , substitution ):
363387 super ().__init__ ()
364388
@@ -381,11 +405,22 @@ def map_MathVar(self, model):
381405
382406class EvaluateMathExpr (ConversionRule ):
383407 """
384- This evalaluates MathExpr objects
408+ This evaluates MathExpr objects and raises a type error if a MathVar exist in the AST.
409+
410+ Args:
411+ model (MathExpr): The rule only acts on [`MathExpr`][oqd_core.interface.math.MathExpr] objects.
412+
413+ Returns:
414+ model (MathExpr):
415+
416+ Assumptions:
417+ None
385418 """
386419
387420 def map_MathVar (self , model : MathVar , operands ):
388- raise TypeError
421+ raise TypeError (
422+ "Evaluation requires the substitution of all MathVar to constants"
423+ )
389424
390425 def map_MathNum (self , model : MathNum , operands ):
391426 return model .value
@@ -427,9 +462,27 @@ def map_MathPow(self, model: MathPow, operands):
427462
428463class SimplifyMathExpr (RewriteRule ):
429464 """
430- This simplified MathExpr objects
465+ This simplifies MathExpr objects by evaluating all constants in the AST.
466+
467+ Args:
468+ model (MathExpr): The rule only acts on [`MathExpr`][oqd_core.interface.math.MathExpr] objects.
469+
470+ Returns:
471+ model (MathExpr):
472+
473+ Assumptions:
474+ None
475+
431476 """
432477
478+ def map_MathNum (self , model ):
479+ # This empty function overrides the map_MathExpr definition for child class MathNum
480+ pass
481+
482+ def map_MathImag (self , model ):
483+ # This empty function overrides the map_MathExpr definition for child class MathImag
484+ pass
485+
433486 def map_MathExpr (self , model ):
434487 try :
435488 TypeAdapter (ConstantMathExpr ).validate_python (model )
@@ -449,9 +502,3 @@ def map_MathExpr(self, model):
449502
450503 except ValidationError :
451504 return model
452-
453- def map_MathNum (self , model ):
454- pass
455-
456- def map_MathImag (self , model ):
457- pass
0 commit comments