Skip to content

Commit

Permalink
[bugfix] GPU properties not displayed by logger (#145)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
PabloAndresCQ authored Jul 30, 2024
1 parent 0fa5f32 commit cd16402
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
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())
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")

0 comments on commit cd16402

Please sign in to comment.