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

Adding a logger widget for logging in run_tardis #2700

Closed
wants to merge 10 commits into from

Conversation

DeekshaMohanty
Copy link

@DeekshaMohanty DeekshaMohanty commented Jul 12, 2024

📝 Description

Fixes #2701

Type: 🚀 feature

  • Added an output ipyidget with tabs to logger.py
  • Removed colored_logger.py

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

@tardis-bot
Copy link
Contributor

tardis-bot commented Jul 12, 2024

*beep* *bop*

Hi, human.

The docs workflow has failed

Click here to see the build log.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

4 similar comments
@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

@tardis-bot
Copy link
Contributor

*beep* *bop*

Hi, human.

I'm the @tardis-bot and couldn't find your records in my database. I think we don't know each other, or you changed your credentials recently.

Please add your name and email to .mailmap in your current branch and push the changes to this pull request.

In case you need to map an existing alias, follow this example.

@wkerzendorf
Copy link
Member

@DeekshaMohanty can you please fix the .mailmap problem.

@tardis-bot
Copy link
Contributor

tardis-bot commented Jul 28, 2024

*beep* *bop*
Hi human,
I ran ruff on the latest commit (a95096c).
Here are the outputs produced.
Results can also be downloaded as artifacts here.
Summarised output:

7	G004  	[ ] Logging statement uses f-string
2	I001  	[*] Import block is un-sorted or un-formatted
2	W291  	[*] Trailing whitespace
2	W605  	[*] Invalid escape sequence: `\A`
1	RET505	[ ] Unnecessary `else` after `return` statement
1	RET506	[ ] Unnecessary `else` after `raise` statement
1	E902  	[ ] No such file or directory (os error 2)
1	E999  	[ ] SyntaxError: Expected an expression
1	F401  	[*] `IPython.display.display` imported but unused
1	UP004 	[*] Class `FilterLog` inherits from `object`
1	UP008 	[*] Use `super()` instead of `super(__class__, self)`
1	TRY300	[ ] Consider moving this statement to an `else` block

Complete output(might be large):

.mailmap:1:38: E999 SyntaxError: Expected an expression
docs/quickstart.ipynb:cell 12:1:39: W291 [*] Trailing whitespace
docs/quickstart.ipynb:cell 12:5:35: W291 [*] Trailing whitespace
docs/quickstart.ipynb:cell 16:10:26: W605 [*] Invalid escape sequence: `\A`
docs/quickstart.ipynb:cell 16:11:40: W605 [*] Invalid escape sequence: `\A`
tardis/io/logger/colored_logger.py:1:1: E902 No such file or directory (os error 2)
tardis/io/logger/logger.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/io/logger/logger.py:257:17: UP004 [*] Class `FilterLog` inherits from `object`
tardis/simulation/base.py:1:1: I001 [*] Import block is un-sorted or un-formatted
tardis/simulation/base.py:8:29: F401 [*] `IPython.display.display` imported but unused
tardis/simulation/base.py:155:14: UP008 Use `super()` instead of `super(__class__, self)`
tardis/simulation/base.py:199:13: RET506 Unnecessary `else` after `raise` statement
tardis/simulation/base.py:263:17: G004 Logging statement uses f-string
tardis/simulation/base.py:270:9: RET505 Unnecessary `else` after `return` statement
tardis/simulation/base.py:451:13: G004 Logging statement uses f-string
tardis/simulation/base.py:549:13: G004 Logging statement uses f-string
tardis/simulation/base.py:638:21: G004 Logging statement uses f-string
tardis/simulation/base.py:641:13: G004 Logging statement uses f-string
tardis/simulation/base.py:646:13: G004 Logging statement uses f-string
tardis/simulation/base.py:697:13: TRY300 Consider moving this statement to an `else` block
tardis/simulation/base.py:699:26: G004 Logging statement uses f-string
Found 21 errors.
[*] 8 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

@DeekshaMohanty DeekshaMohanty marked this pull request as ready for review July 28, 2024 23:04
@DeekshaMohanty DeekshaMohanty marked this pull request as draft July 28, 2024 23:06
@DeekshaMohanty
Copy link
Author

DeekshaMohanty commented Jul 28, 2024

Points 6 and 7 for the issue linked to this PR need some further discussion. #2701

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 93.50649% with 5 lines in your changes missing coverage. Please review.

Project coverage is 70.87%. Comparing base (62395d3) to head (a95096c).
Report is 39 commits behind head on master.

Files with missing lines Patch % Lines
tardis/io/logger/logger.py 92.95% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2700      +/-   ##
==========================================
- Coverage   70.99%   70.87%   -0.13%     
==========================================
  Files         209      208       -1     
  Lines       15650    15639      -11     
==========================================
- Hits        11111    11084      -27     
- Misses       4539     4555      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@jaladh-singhal jaladh-singhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition @DeekshaMohanty - thanks for taking initiative on this!

I've left some comments, please address them when you get a chance. We need to make sure that we address all the points in #2701

@@ -116,7 +116,7 @@
"sim = run_tardis(\"tardis_example.yml\", \n",
" virtual_packet_logging=True,\n",
" show_convergence_plots=True,\n",
" export_convergence_plots=True,\n",
" export_convergence_plots=False, #TODO: to avoid double plots\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to replace this parameter with a new parameter (maybe called export_static_output) which can show convergence plots and logger-widget (or atleast a fixed height html text area) for static HTML documentation website.

And setting this param to True should be controllable by identifying if the notebook execution is being done by nbsphinx/nbconvert - there should be some setting to detect that but needs research.


logging_level = (
log_level if log_level else tardis_config["debug"]["log_level"]
tardis_config["debug"].get("specific_log_level", specific_log_level)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good cleanup!

Comment on lines 79 to 82
"WARNING/ERROR": Output(layout=Layout(height='300px', overflow_y='auto')),
"INFO": Output(layout=Layout(height='300px', overflow_y='auto')),
"DEBUG": Output(layout=Layout(height='300px', overflow_y='auto')),
"ALL": Output(layout=Layout(height='300px', overflow_y='auto'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can define a function that returns a Output widget and call for each of the keys, instead of repeating code.

tab.set_title(2, "DEBUG")
tab.set_title(3, "ALL")

display(tab)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to do it global level? shouldn't display be inside some function/class that gets called/instantiated?

If not, maybe move it together with other global level code at L184

elif record.levelno == logging.DEBUG:
color = 'blue'
else:
color = 'black'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be cleaner if colors come from a dictionary, instead of defining here

@@ -517,7 +517,7 @@ def log_plasma_state(
plasma_state_log["next_w"] = next_dilution_factor
plasma_state_log.columns.name = "Shell No."

if is_notebook():
if False and is_notebook(): #TODO: remove it with something better
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simply remove the if block since we are controlling display now

@DeekshaMohanty DeekshaMohanty marked this pull request as ready for review September 12, 2024 01:25
display(tab)


def remove_ansi_escape_sequences(text):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this function?

return ansi_escape.sub("", text)


class WidgetHandler(logging.Handler):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good name. Should be more specific for logging.

html_output = clean_log_entry

if record.levelno in (logging.WARNING, logging.ERROR):
with log_outputs["WARNING/ERROR"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repetitive code. Would be better as some kind of dictionary.


logger.addHandler(widget_handler)
logging.getLogger("py.warnings").addHandler(widget_handler)
create_and_display_log_tab(log_outputs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lines 233-254 are strange because they are not in a class or function. Why are they set up like this? There seems to be a lot of calls to logger and logging.

create_and_display_log_tab(log_outputs)


class FilterLog(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a full class necessary here, or could it just be a filter function?

@wkerzendorf
Copy link
Member

has been superseded by panel implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add logger widget for run_tardis():
6 participants