Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep log-level with stride logs #137

Open
charlesbmi opened this issue Aug 8, 2023 · 0 comments
Open

Keep log-level with stride logs #137

charlesbmi opened this issue Aug 8, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@charlesbmi
Copy link
Contributor

Describe the new feature or enhancement

Please provide a clear and concise description of what you want to add or change.
Print log-levels with the logs that are printed by the stride backend library.

Please describe how you would use this new feature.
Help users configure their PDE parameters properly.

For example, in the following logs:

Default Devito configuration:
         * autotuning=off
         * develop-mode=False
         * mpi=False
         * log-level=DEBUG
         * language=openmp
(ShotID 0) Preparing to run state for shot
(ShotID 0) Estimated bandwidth for the propagated wavelet 0.497-0.502 MHz
(ShotID 0) Spatial grid spacing (0.125 mm | 23.922 PPW) is below dispersion limit (0.598 mm | 5.000 PPW)
(ShotID 0) Time grid spacing (0.083 μs | 186%) is above OT4 limit (0.036 μs)
(ShotID 0) Selected undersampling level 4
(ShotID 0) Selected time stepping scheme OT4
Operator `acoustic_iso_state` instance configuration:
         * subs={h_x: 0.000125, h_y: 0.000125}
         * opt=advanced
         * platform=None

nothing looks wrong at first glance.

Only after looking at the stride code:

            self.logger.warn('(ShotID %d) Time grid spacing (%.3f \u03BCs | %d%%) is '
                             'above OT4 limit (%.3f \u03BCs)'
                             % (problem.shot_id, dt / 1e-6, crossing_factor, dt_max_OT4 / 1e-6))

do we see that this is actually a warning that our PDE could be unstable.

If the corresponding log also said [WARNING], that would be helpful.

Describe your proposed implementation

Describe how you think the feature or improvement should be implemented (e.g., as a new method on an existing class? as new capability added to an existing method?) If you're not sure, please delete this section and the next section.

From bloop.ai

The logger formatting in the stride Python library is managed by the LoggerManager class in
mosaic/utils/logger.py
.

To include the log level in the logger formatting, you need to modify the set_default, set_local, and set_remote methods of the LoggerManager class. These methods define the format of the logger.

For example, in the set_local method, the logger format is set in the following lines:

handler = logging.StreamHandler(self._stdout)
if format == 'interactive':
handler.setFormatter(CustomFormatter('%(runtime_id)-15s %(message)s'))
else:
handler.setFormatter(CustomFormatter('%(asctime)s - %(levelname)-10s %(runtime_id)-15s %(message)s'))
You can see that the format string '%(asctime)s - %(levelname)-10s %(runtime_id)-15s %(message)s' includes the log level (%(levelname)-10s). If you want to include the log level in the 'interactive' format as well, you can modify the format string to something like '%(levelname)-10s %(runtime_id)-15s %(message)s'.

Here is the modified code:

handler = logging.StreamHandler(self._stdout)
if format == 'interactive':
handler.setFormatter(CustomFormatter('%(levelname)-10s %(runtime_id)-15s %(message)s'))
else:
handler.setFormatter(CustomFormatter('%(asctime)s - %(levelname)-10s %(runtime_id)-15s %(message)s'))
You would need to make similar changes in the set_default and set_remote methods.

Please note that modifying the library code directly is not recommended as it can lead to issues when updating the library. It's better to subclass the LoggerManager and override the methods if the library does not provide a way to customize the logger format.

To include the log level in the logger formatting in the stride Python library, you need to modify the set_default, set_local, and set_remote methods of the LoggerManager class in mosaic/utils/logger.py. These methods define the format of the logger. You can add '%(levelname)-10s' to the format string to include the log level. However, modifying the library code directly is not recommended as it can lead to issues when updating the library. It's better to subclass the LoggerManager and override the methods if the library does not provide a way to customize the logger format.

Describe possible alternatives

Configure the log format directly in the stride repository. This would also work.

@charlesbmi charlesbmi added the enhancement New feature or request label Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant