From cd16402f52bc0bd261dcbbba0ec431f68be84b61 Mon Sep 17 00:00:00 2001 From: Pablo Andres-Martinez <104848389+PabloAndresCQ@users.noreply.github.com> Date: Tue, 30 Jul 2024 11:15:43 +0100 Subject: [PATCH] [bugfix] GPU properties not displayed by logger (#145) # Description Fixed the issue below. The issue has a code snippet to reproduce the error (and see what the fix did). # Related issues Solves issue #143 # Checklist - [x] I have run the tests on a device with GPUs. - [x] I have performed a self-review of my code. - [ ] I have commented hard-to-understand parts of my code. - [ ] I have made corresponding changes to the public API documentation. - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have updated the changelog with any user-facing changes. --- docs/changelog.rst | 5 +++++ pytket/extensions/cutensornet/general.py | 16 ++++++++-------- tests/test_utils.py | 10 ++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 30e97c79..5ac06223 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,11 @@ Changelog ~~~~~~~~~ +Unreleased +---------- + +* Fixed a bug causing the logger to fail displaying device properties. + 0.7.0 (July 2024) ----------------- diff --git a/pytket/extensions/cutensornet/general.py b/pytket/extensions/cutensornet/general.py index 0f5d3af7..9b095664 100644 --- a/pytket/extensions/cutensornet/general.py +++ b/pytket/extensions/cutensornet/general.py @@ -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()) + 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( diff --git a/tests/test_utils.py b/tests/test_utils.py index a4aad95f..fa6c68b2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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, ) @@ -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")