question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Logging does not work again with pennylane

See original GitHub issue

Expected behavior

Similar to this issue, I was expecting writing logs into a log file by setting:

logging.basicConfig(
      format='%(asctime)s - %(levelname)s: %(message)s',
      filename='log.txt',
      filemode='w'
)

Actual behavior

However, the logger still outputs everything to stdout. I guess that PennyLane may overwrite my logging setting.

Additional information

No response

Source code

# Some qml functions I used
qml.BasisStatePreparation
qml.StronglyEntanglingLayers
qml.AngleEmbedding
qml.StronglyEntanglingLayers
qml.expval
qml.PauliZ
qml.StronglyEntanglingLayers.shape
qml.device
qml.QNode
qml.qnn.TorchLayer

Tracebacks

No response

System information

Name: PennyLane
Version: 0.19.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: None
Author-email: None
License: Apache License 2.0
Location: /home/qlan3/miniconda3/lib/python3.9/site-packages
Requires: scipy, semantic-version, autograd, pennylane-lightning, cachetools, networkx, autoray, toml, numpy, appdirs
Required-by: PennyLane-Lightning
Platform info:           Linux-5.8.0-44-generic-x86_64-with-glibc2.31
Python version:          3.9.5
Numpy version:           1.20.3
Scipy version:           1.7.1
Installed devices:
- default.gaussian (PennyLane-0.19.1)
- default.mixed (PennyLane-0.19.1)
- default.qubit (PennyLane-0.19.1)
- default.qubit.autograd (PennyLane-0.19.1)
- default.qubit.jax (PennyLane-0.19.1)
- default.qubit.tf (PennyLane-0.19.1)
- default.qubit.torch (PennyLane-0.19.1)
- default.tensor (PennyLane-0.19.1)
- default.tensor.tf (PennyLane-0.19.1)
- lightning.qubit (PennyLane-Lightning-0.19.0)

  • I have searched existing GitHub issues to make sure the issue does not already exist.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Jaybsonicommented, Jan 10, 2022

So as a closing comment I would like summarize:

When using logging and PennyLane, one should make sure to import and setup logging first BEFORE importing PL to ensure the logger settings are not ignored.

import logging
logging.basicConfig(filename='mylogfile.txt', level=logging.INFO)
logging.info('A log entry.')

import pennylane as qml

@josh146, after looking into this, it seems that the logging we currently do is not used anywhere else in the codebase. In fact, we don’t log to file at all. It might be worth removing completely. Let me know what you think.

1reaction
Jaybsonicommented, Dec 16, 2021

@raghavven and @qlan3,

I just want to confirm if there are any action items here? From the above thread it seems you were able to get your loggers working by swapping the order of the imports and/or removing the line from configuration.py which called the logger in the first place?

Thanks again for pointing this out! Let me know if you are seeing any additional issues around this bug and I can address this it in a bug fix PR, otherwise if it was just a matter of keeping an eye on which order the logger is being imported then we can close the issue here 👍🏼

Cheers,

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release notes — PennyLane 0.28.0 documentation
An exception is BasisEmbedding , which is not broadcastable. Improvements. The qml.math.expand_matrix() method now allows the sparse matrix representation of an ...
Read more >
PennyLane - PyPI
PennyLane is a Python quantum machine learning library by Xanadu Inc. ... Issue Tracker: https://github.com/PennyLaneAI/pennylane/issues.
Read more >
ReportingBugs - Community Help Wiki
Many times, a problem you're running into isn't a bug in Ubuntu, ... or if you don't have the time to learn how...
Read more >
The Beat Bugs - Penny Lane paroles | Musixmatch
Stop and say hello On the corner is a banker with a motorcar The little children laugh at him behind his back And...
Read more >
Chat log from the meeting on 2010-08-31 - OpenSimulator
[18:15] Justin Clark-Casey: if it doesn't work in the real world it will just ... [18:24] Penny Lane: I'm just worried about Opensim...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found