k-wave-python icon indicating copy to clipboard operation
k-wave-python copied to clipboard

AssertionError from `uff` in example bmode reconstruction example

Open kwsp opened this issue 3 years ago • 8 comments

Traceback (most recent call last):
  File "C:\Users\nhl08\code\k-wave-python\examples\bmode_reconstruction_example.py", line 207, in <module>
    beamform(channel_data)
  File "C:\Users\nhl08\code\k-wave-python\kwave\reconstruction\beamform.py", line 73, in beamform
    transform = ShiftedTransform.deserialize(probe.transform.serialize())
  File "C:\Users\nhl08\miniconda3\envs\kwave\lib\site-packages\uff\uff_io.py", line 58, in deserialize
    assert k in fields, f'Class {cls} does not have property named {k}.'
AssertionError: Class <class 'kwave.reconstruction.shifted_transform.ShiftedTransform'> does not have property named translation.

fresh install of k-wave-python with the example dependencies.

Seems to be caused by the Serializable mechanism in uff. Opened an issue in uff to discuss.

kwsp avatar Oct 11 '22 19:10 kwsp

Which version of Python are you running the example with? I was able to reproduce this behavior with python 3.10.6. Can you share the output of python --version with me?

waltsims avatar Oct 11 '22 20:10 waltsims

Update: The example does work with python 3.9.13. It would seem uff.py is not compatible with 3.10.x. I will investigate where the break originates.

waltsims avatar Oct 11 '22 20:10 waltsims

I am indeed using 3.10.x. Thanks!

kwsp avatar Oct 11 '22 20:10 kwsp

Going back to UFF.py I see that I at some point found uff was not compatible with python 3.10 but did not yet address it. I'll let this be my motivation.

waltsims avatar Oct 11 '22 20:10 waltsims

The __annotation__ mechanism that uff relies on changed in 3.10 See https://docs.python.org/3/howto/annotations.html for best practices in inspecting __annotations__.

kwsp avatar Oct 11 '22 20:10 kwsp

It maybe more maintainable and forward/backward compatible to us something like pydantic to handle serialization/deserialization

kwsp avatar Oct 11 '22 20:10 kwsp

We had discussed that when we were developing uff.py. Right now we are working to finish building out testing against k-Wave for this project. I'm always welcome to PRs if you have a suggestion.

Also feel free to drop by the development meeting if you want to discuss further.

waltsims avatar Oct 11 '22 21:10 waltsims

I'll try to come this week!

kwsp avatar Oct 11 '22 22:10 kwsp

Hi, May I ask if there is any update for python 3.10.x? I also encountered the same issue when using the code on Google Colab and cannot really downgrade the Python version ...

tonyzzr avatar May 06 '23 06:05 tonyzzr

Hi @tonyzzr, overall k-wave-python supports Python 3.10 but uff library does not support it yet. So the example which require uff library will not work with Python 3.10.

As a workaround and depending on your use case, I think it should be possible (example) to change the Python version in Colab. Though you might need to re-install the pre-installed libraries that come with the default Python version in Colab.

faridyagubbayli avatar May 06 '23 12:05 faridyagubbayli

Thank you @faridyagubbayli ! Let me try to follow the example to work it around.

tonyzzr avatar May 07 '23 05:05 tonyzzr