Skip to content

Deprecated NumPy 'tostring' method is called in the codebase #286

@robotastray

Description

@robotastray

Describe the bug
When runing tox -e unit-tests for newer version of Python and NumPy the following error is displayed

AttributeError: 'numpy.ndarray' object has no attribute 'tostring'

This is because the method has been deprecated since NumPy 1.19.0

https://numpy.org/doc/2.1/reference/generated/numpy.ndarray.tostring.html

To reproduce

  • run tox -e unit-tests for numpy >= 1.19.0 and Python >= 3.9
  • where the method tostring() is called the corresponding test will fail with AttributeError: 'numpy.ndarray' object has no attribute 'tostring'

Expected behavior
All tests should pass with no issue
Line 370 in simulator.py should use tobytes() not tostring()

Screenshots or logs
Please see the failure here https://github.com/amazon-braket/amazon-braket-default-simulator-python/actions/runs/15591371868/job/43914410256?pr=285

System information
The error was spotted upon creating PR 285

Additional context
the issue is in simulator.py line 370 return str(hash(str(observable.matrix.tostring())))
The issue can be addressed as part of PR 285 by substituting tostring with tobytes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions