We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
IfAction
1 parent e4fe20e commit 51f7a68Copy full SHA for 51f7a68
1 file changed
test/logging.jl
@@ -78,3 +78,24 @@ end
78
end
79
80
81
+
82
+@testset "IfAction only logs on even iterations" begin
83
+ problem = LogDummyProblem()
84
+ algorithm = LogDummyAlgorithm(StopAfterIteration(4))
85
86
+ # Callback that logs the iteration
87
+ iter_logger = CallbackAction() do problem, algorithm, state
88
+ @info "Even Iter $(state.iteration)"
89
+ end
90
91
+ # Predicate: only log on even iterations
92
+ even_predicate = (problem, algorithm, state; kwargs...) -> state.iteration % 2 == 0
93
+ if_logger = IfAction(even_predicate, iter_logger)
94
95
+ # Expect logs only for iterations 2 and 4
96
+ @test_logs (:info, "Even Iter 2") (:info, "Even Iter 4") begin
97
+ with_algorithmlogger(:PostStep => if_logger) do
98
+ solve(problem, algorithm)
99
100
101
+end
0 commit comments