tsdev / spinw

SpinW Matlab library for spin wave calculation
www.psi.ch/spinw
GNU General Public License v3.0
30 stars 35 forks source link

Unicode error in pyspinw #42

Open mincentatties opened 6 years ago

mincentatties commented 6 years ago

{system: MacOS Sierra 10.12.6}

Hi Sandor

After installing pyspinw and trying your sample script I get the following:

Last login: Fri Aug 11 11:31:29 on ttys000
[rosss-imac:~] rossstewart% python3
Python 3.6.2 (default, Jul 17 2017, 16:44:45) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> spinw='/Applications/pyspinw.app/pyspinw.sh'
>>> from transplant import Matlab
>>> from transplant import MatlabStruct
>>> import numpy as np
>>> m=Matlab(spinw)
SpinW process is running...
>>> tri = m.sw_model('triAF',1.)
Preparing 'triAF' model ...
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/transplant/transplant_master.py", line 124, in reader
    print(line.decode(), end='')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc5 in position 41: invalid continuation byte

>>> 

Cheers Ross

tsdev commented 6 years ago

This is a problem with the communication between Python and pyspinw. Please download the updated release from here (and remove the original executable from your machine): https://github.com/tsdev/spinw/releases/tag/v3.0.2py Now run the code:

tri = m.sw_model('triAF',1.)
m.swpref.setpref('fid',1.)
tri = m.sw_model('triAF',1.)

What did you get? The setting of fid to 1 switches on the text output in pyspinw which caused your problem. It should be 0 by default which removes all text output from pyspinw.

mincentatties commented 6 years ago

That has fixed the problem. The first time I ran tri = m.sw_model('triAF',1.) I got the same error. Then after the fid setting it went away.

Thanks

tsdev commented 6 years ago

Strange, it should have been the opposite way. fid is zero by default, so the first run should be fine, but the second after setting fid to 1 should produce the error. Can you check what is the value of fid right after pyspinw is started by using the command:

m.swpref.getpref('fid')

Thanks!

mincentatties commented 6 years ago

Thanks Sandor

mincentatties commented 6 years ago

Ok so I now get:

>>> m.swpref.getpref('fid')
{'label': 'file identifier for text output, default value is 1 (Command Window)', 'name': 'fid', 'val': 0.0}
tsdev commented 6 years ago

Thanks! I didn't really solved the problem, just switched of the text output in pyspinw that caused it. I will do some tests to figure out what caused it.