-
Notifications
You must be signed in to change notification settings - Fork 37
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
Enrich logging through context vars #452
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of additional small typing things to consider while decieding what to do with the from __future__ import annotations
line.
Otherwise, looks about ready to go on my end!!
move log filter creation into ContextAwareLogger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks semantics-wise good! Just two requests:
- can you please add/complete the missing docstring parameter lists including
:return:
and:rtype:
fields, at least in the more user-facing files such aslog.py
? - consider running
make style
and thenmake check-style
to make sure the future GH checks will pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small typos, but nothing worth holding this PR up over.
LGTM!! Thanks for all the hard work on this one!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for doing this!
The implementation makes use of python `contextvars.ContextVar` to store experiment-specific state. The state is used to dynamically modify experiment-level logging. For example, this driver: ```py exp1 = smartsim.Experiment('exp-1') rs1 = exp1.create_runsettings(...) model1 = exp1.create_model(..., rs1) exp2 = smartsim.Experiment('other-exp') rs2 = exp2.create_runsettings(...) model2 = exp2.create_model(..., rs2) exp1.start(model1) exp1.start(model2) ``` Results in each experiment dynamically registering `logging.FileHandler` instances that write logs to separate files: - `/exp-1/.telemetry/smartsim/smartsim.out` - `/other-exp/.telemetry/smartsim/smartsim.out` ### Key changes: 1. Decorated experiment API w/contextualizer to enrich log context 2. Create/Use `ContextThread` to ensure threads include current context information 3. Create/Use `ContextAwareLogger` to dynamically add file handlers for experiment logs 4. Updated manifest serialization to include paths to experiment-specific log files 5. Added `LowPassFilter` to enable splitting experiment logs across `xxx.out` and `xxx.err` ### Additional minor changes: 1. Moved `serialize.TELMON_SUBDIR` constant to `Config.telemetry_subdir` to make it more universally available --------- Co-authored-by: Matt Drozt <[email protected]> Co-authored-by: Matt Drozt <[email protected]> [ committed by @ankona ] [ reviewed by @al-rigazzi @MattToast ]
The experiment previously wrote to
sys.stdout
andsys.stderr
. This change makes experiment driver scripts using theExperiment
API write additional logs for experiment tracking. The public "factory API" of theExperiment
has added the behavior of also logging to individual experiment log files.The implementation makes use of python
contextvars.ContextVar
to store experiment-specific state. The state is used to dynamically modify experiment-level logging.For example, this driver:
Results in each experiment dynamically registering
logging.FileHandler
instances that write logs to separate files:/exp-1/.telemetry/smartsim/smartsim.out
/other-exp/.telemetry/smartsim/smartsim.out
Key changes:
ContextThread
to ensure threads include current context informationContextAwareLogger
to dynamically add file handlers for experiment logsLowPassFilter
to enable splitting experiment logs acrossxxx.out
andxxx.err
Additional minor changes:
serialize.TELMON_SUBDIR
constant toConfig.telemetry_subdir
to make it more universally available