@@ -731,3 +731,43 @@ def test_dprint(self):
731
731
o1 = op1 (r1 , r2 )
732
732
fg = FunctionGraph ([r1 , r2 ], [o1 ], clone = False )
733
733
assert fg .dprint (file = "str" ) == debugprint (fg , file = "str" )
734
+
735
+ def test_optimizer_verbose (self , capsys ):
736
+ x = MyVariable ("x" )
737
+ y = MyVariable ("y" )
738
+ z = MyVariable ("z" )
739
+
740
+ o1 = op1 (x , y )
741
+ fgraph = FunctionGraph ([x , y , z ], [o1 ], clone = False )
742
+
743
+ with config .change_flags (optimizer_verbose = False ):
744
+ fgraph .replace (y , z , reason = "y->z" )
745
+
746
+ cap_out = capsys .readouterr ().out
747
+ assert cap_out == ""
748
+
749
+ with config .change_flags (optimizer_verbose = True ):
750
+ fgraph .replace (z , y , reason = "z->y" )
751
+
752
+ cap_out = capsys .readouterr ().out
753
+ assert "z->y" in cap_out
754
+
755
+ with config .change_flags (
756
+ optimizer_verbose = True , optimizer_verbose_ignore = "y->z"
757
+ ):
758
+ fgraph .replace (y , z , reason = "y->z" )
759
+ fgraph .replace (z , y , reason = "z->y" )
760
+
761
+ cap_out = capsys .readouterr ().out
762
+ assert "y->z" not in cap_out
763
+ assert "z->y" in cap_out
764
+
765
+ with config .change_flags (
766
+ optimizer_verbose = True , optimizer_verbose_ignore = "y->z,z->y"
767
+ ):
768
+ fgraph .replace (y , z , reason = "y->z" )
769
+ fgraph .replace (z , y , reason = "z->y" )
770
+
771
+ cap_out = capsys .readouterr ().out
772
+ assert "y->z" not in cap_out
773
+ assert "z->y" not in cap_out
0 commit comments