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

[bugfix] GPU properties not displayed by logger #145

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
~~~~~~~~~

Unreleased
----------

* Fixed a bug causing the logger to fail displaying device properties.

0.7.0 (July 2024)
-----------------

Expand Down
16 changes: 8 additions & 8 deletions pytket/extensions/cutensornet/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def __exit__(self, exc_type: Any, exc_value: Any, exc_tb: Any) -> None:
def print_device_properties(self, logger: Logger) -> None:
"""Prints local GPU properties."""
device_props = cp.cuda.runtime.getDeviceProperties(self.dev.id)
logger.debug("===== device info ======")
logger.debug("GPU-name:", device_props["name"].decode())
logger.debug("GPU-clock:", device_props["clockRate"])
logger.debug("GPU-memoryClock:", device_props["memoryClockRate"])
logger.debug("GPU-nSM:", device_props["multiProcessorCount"])
logger.debug("GPU-major:", device_props["major"])
logger.debug("GPU-minor:", device_props["minor"])
logger.debug("========================")
logger.info("===== device info ======")
logger.info("GPU-name: " + device_props["name"].decode())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Purely nitpicking: why not opt for fstrings?

E.g.

logger.info(f"GPU-name: {device_props['name'].decode()}")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went for that in the first commit, and mypy did not know how to parse that for some reason, so I went for this other approach 🤷

logger.info("GPU-clock: " + str(device_props["clockRate"]))
logger.info("GPU-memoryClock: " + str(device_props["memoryClockRate"]))
logger.info("GPU-nSM: " + str(device_props["multiProcessorCount"]))
logger.info("GPU-major: " + str(device_props["major"]))
logger.info("GPU-minor: " + str(device_props["minor"]))
logger.info("========================")


def set_logger(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
import numpy
from pytket.extensions.cutensornet.general import CuTensorNetHandle, set_logger
from pytket.extensions.cutensornet.general_state.utils import (
circuit_statevector_postselect,
)
Expand Down Expand Up @@ -31,3 +33,11 @@ def test_circuit_statevector_postselect() -> None:
sv_postselect = circuit_statevector_postselect(circ, post_select_dict)

numpy.testing.assert_array_equal(sv_postselect, sv_post_select)


def test_device_properties_logger() -> None:
try:
with CuTensorNetHandle() as libhandle:
libhandle.print_device_properties(set_logger("GeneralState", 10))
except:
pytest.fail("Could not print device properties")
Loading