You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/interface.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,7 +107,7 @@ end
107
107
```
108
108
109
109
Note that we are only focussing on the actual algorithm, and *not* incrementing the iteration counter.
110
-
These kinds of bookkeeping should be handled by the [`increment!(state)`](@ref) function, which will by default already increment the iteration counter.
110
+
These kinds of bookkeeping should be handled by the [`AlgorithmsInterface.increment!`](@ref) function, which will by default already increment the iteration counter.
111
111
The following generic functionality is therefore enough for our purposes, and does *not* need to be defined.
112
112
Nevertheless, if additional bookkeeping would be desired, this can be achieved by overloading that function:
Copy file name to clipboardExpand all lines: docs/src/logging.md
+19-14Lines changed: 19 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,14 +24,14 @@ The logging system aims to achieve these goals by separating the logging logic i
24
24
These parts can be roughly described as *events* and *actions*, where the logging system is responsible for mapping between them.
25
25
Concretely, we have:
26
26
27
-
***When do we log?** → an [`AlgorithmLogger`](@ref)mapping events to actions.
28
-
***What happens when we log?** → a [`LoggingAction`](@ref).
27
+
***When do we log?** → an [`with_algorithmlogger`](@ref)to control how to map events to actions.
28
+
***What happens when we log?** → a [`LoggingAction`](@ref) to determine what to do when an event happens.
29
29
30
30
This separation allows users to compose rich behaviors (printing, collecting statistics, plotting) without modifying algorithm code, and lets algorithm authors emit domain‑specific events.
31
31
32
32
## Using the default logging actions
33
33
34
-
Continuing from the [Stopping Criteria](@ref) page, we have our Heron's method implementation ready:
34
+
Continuing from the [Stopping Criteria](@ref sec_stopping) page, we have our Heron's method implementation ready:
35
35
36
36
```@example Heron
37
37
using AlgorithmsInterface
@@ -97,7 +97,7 @@ nothing # hide
97
97
```
98
98
99
99
To activate this logger, we wrap the section of code that we want to enable logging for, and map the `:PostStep` context to our action.
100
-
This is achieved through the [`with_algorithmlogger`](@ref) function, and uses Julia's `with` function to set the [`ALGORITHM_LOGGER`](@ref)scoped value:
100
+
This is achieved through the [`with_algorithmlogger`](@ref) function, which under the hood uses Julia's `with` function to manipulate a scoped value.
101
101
102
102
```@example Heron
103
103
with_algorithmlogger(:PostStep => iter_printer) do
@@ -246,7 +246,7 @@ Let's implement a more sophisticated example: tracking iteration statistics.
246
246
To implement a custom [`LoggingAction`](@ref), you need:
247
247
248
248
1. A concrete subtype of `LoggingAction`.
249
-
2. An implementation of [`handle_message!`](@ref) that defines the behavior.
249
+
2. An implementation of [`AlgorithmsInterface.handle_message!`](@ref) that defines the behavior.
250
250
251
251
The signature of `handle_message!` is:
252
252
@@ -306,7 +306,7 @@ This pattern of collecting data during iteration and post-processing afterward i
306
306
307
307
## [The AlgorithmLogger](@id sec_algorithmlogger)
308
308
309
-
The [`AlgorithmLogger`](@ref) is the dispatcher that routes logging events to actions.
309
+
The [`AlgorithmsInterface.AlgorithmLogger`](@ref) is the dispatcher that routes logging events to actions.
310
310
Understanding its design helps when adding custom logging contexts.
311
311
312
312
### How logging events are emitted
@@ -315,21 +315,19 @@ Inside the `solve!` function, logging events are emitted at key points:
When logging is disabled globally, [`algorithm_logger`](@ref) returns `nothing`, and `emit_message` becomes a no-op with minimal overhead.
365
+
This works since the default implementation of [`emit_message`](@ref) first retrieves the current logger through [`AlgorithmsInterface.algorithm_logger`](@ref):
When logging is disabled globally, [`algorithm_logger`](@ref AlgorithmsInterface.algorithm_logger) returns `nothing`, and `emit_message` becomes a no-op with minimal overhead.
368
373
369
374
### Error isolation
370
375
@@ -493,7 +498,7 @@ Private = true
493
498
You have now seen the three pillars of the AlgorithmsInterface:
494
499
495
500
*[**Interface**](@ref sec_interface): Defining algorithms with `Problem`, `Algorithm`, and `State`.
496
-
*[**Stopping criteria**](@ref): Controlling when iteration halts with composable conditions.
501
+
*[**Stopping criteria**](@ref sec_stopping): Controlling when iteration halts with composable conditions.
497
502
*[**Logging**](@ref sec_logging): Instrumenting execution with flexible, composable actions.
498
503
499
504
Together, these patterns encourage modular, testable, and maintainable iterative algorithm design.
Use the current or the provided algorithm logger to handle the logging event of the given `context`.
156
-
The [`AlgorithmLogger`](@ref) is responsible for dispatching the correct events to the correct [`LoggingAction`](@ref)s.
169
+
The first signature should be favored as it correctly handles accessing the `logger` and respecting global toggles for enabling and disabling the logging system.
170
+
171
+
The second signature should be used exclusively in (very) hot loops, where the overhead of [`AlgorithmsInterface.algorithm_logger()`](@ref) is too large.
172
+
In this case, you can manually extract the `algorithm_logger()` once outside of the hot loop.
0 commit comments