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

Fix logging trace statement with empty gradient_fn #4669

Merged
merged 8 commits into from
Oct 20, 2023

Conversation

mlxd
Copy link
Member

@mlxd mlxd commented Oct 12, 2023

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    test directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the doc/releases/changelog-dev.md file, summarizing the
    change, and including a link back to the PR.

  • The PennyLane source code conforms to
    PEP8 standards.
    We check all of our code against Pylint.
    To lint modified files, simply pip install pylint, and then
    run pylint pennylane/path/to/file.py.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context: The logging implementation for the TRACE level assumes the existence of several functions to report their source when enabled. If the gradient_fn is None, the logger attempts to retrieve the source and fails.

Description of the Change: This adds an existence check for all execute-enabled TRACE level log statements, and reports only if the associated functions exist.

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@mlxd
Copy link
Member Author

mlxd commented Oct 12, 2023

[sc-47564]

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5cc309b) 99.64% compared to head (fdadb59) 99.63%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4669      +/-   ##
==========================================
- Coverage   99.64%   99.63%   -0.01%     
==========================================
  Files         377      377              
  Lines       34002    33741     -261     
==========================================
- Hits        33881    33619     -262     
- Misses        121      122       +1     
Files Coverage Δ
pennylane/interfaces/autograd.py 100.00% <ø> (ø)
pennylane/interfaces/execution.py 97.20% <ø> (-0.03%) ⬇️
pennylane/interfaces/jacobian_products.py 100.00% <ø> (ø)
pennylane/interfaces/jax.py 99.00% <ø> (ø)
pennylane/interfaces/tensorflow.py 96.11% <ø> (ø)
pennylane/interfaces/torch.py 96.63% <ø> (ø)
pennylane/qnode.py 100.00% <ø> (ø)

... and 41 files with indirect coverage changes

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

@mudit2812 mudit2812 added this to the v0.33 milestone Oct 19, 2023
@mlxd mlxd requested a review from a team October 19, 2023 14:16
Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

not sure I totally get what's being handled here. I thought it was the difference when gradient_fn is None, but they seem the same?

>>> def fn1():
...     return 2
>>> fn2 = None
>>> print(isfunction(fn1), isfunction(fn2))
True False
>>> print(callable(fn1), callable(fn2))
True False

Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

I think some minimal testing would be good, since this was never caught by CI, otherwise looks good!

@mlxd
Copy link
Member Author

mlxd commented Oct 19, 2023

not sure I totally get what's being handled here. I thought it was the difference when gradient_fn is None, but they seem the same?

>>> def fn1():
...     return 2
>>> fn2 = None
>>> print(isfunction(fn1), isfunction(fn2))
True False
>>> print(callable(fn1), callable(fn2))
True False

Did you enable the trace logging level? This config requires explicit edits to the YAML file at

level = "DEBUG" # Set to TRACE for highest verbosity

I see failures without this, and success with.

@mlxd
Copy link
Member Author

mlxd commented Oct 19, 2023

I think some minimal testing would be good, since this was never caught by CI, otherwise looks good!

Testing with the previous logging contribution wasn't easily possible, so this will likely need to be skipped.

Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

talked offline, looks good 👍

@mlxd mlxd added the merge-ready ✔️ All tests pass and the PR is ready to be merged. label Oct 19, 2023
@mudit2812 mudit2812 enabled auto-merge (squash) October 20, 2023 13:59
@mudit2812 mudit2812 merged commit 89c2759 into master Oct 20, 2023
33 checks passed
@mudit2812 mudit2812 deleted the bugfix_logging_trace branch October 20, 2023 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-ready ✔️ All tests pass and the PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants