salilab / bayesian_hdx

Support code for HDX data reduction
GNU Lesser General Public License v2.1
3 stars 3 forks source link

write mismatch with numpy.savetxt in sampling #1

Open saltzberg opened 8 years ago

saltzberg commented 8 years ago

Bruce found the error below when running workbench_executable.py. Unable to recreate on OSX and Fedora with numpy 1.11.2.

This occurs when the sigmas are written to log file. I suspect that it is because numpy.savetxt writes in binary and we pass it a file that has been opened in text mode?

The sigmas are written out at each step (rather than storing them). We could instead store it and write them at the end, as this write step probably slows down the calculation some.

170 Apo_score= 388.320098563 3339095_score= 369.400900234
180 Apo_score= 382.973455731 3339095_score= 372.586502734
190 Apo_score= 376.017419592 3339095_score= 510.183047531
WARNING: Running this sampling protocol will potentially overwrite results in directory  C:\dev\bayesian_hdx-master\examples\HDXWorkbench_example
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\numpy\lib\npyio.py", line 1158, in savetxt
    fh.write(asbytes(format % tuple(row) + newline))
TypeError: must be str, not bytes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "workbench_executable.py", line 143, in <module>
    outfile_prefix="Macro", outdir=outputdir)
  File "C:\dev\bayesian_hdx-master\pyext\src\sampling.py", line 39, in simulated_annealing
    save_results=True, outdir=outdir, outfile_prefix=outfile_prefix, noclobber=noclobber)
  File "C:\dev\bayesian_hdx-master\pyext\src\sampling.py", line 97, in do_mc_sampling
    numpy.savetxt( outfile3 , numpy.atleast_2d(sigs), "%f")
  File "C:\Python34\lib\site-packages\numpy\lib\npyio.py", line 1162, in savetxt
    % (str(X.dtype), format))
TypeError: Mismatch between array dtype ('float64') and format specifier ('%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f')
benmwebb commented 8 years ago

Bruce found the error below when running workbench_executable.py. Unable to recreate on OSX and Fedora with numpy 1.11.2.

Probably because Bruce is using Python 3 and you're trying to reproduce with Python 2. Your best solution would be to write a unit test to exercise this case. IMP nightly builds run all the unit tests on a Python 3 system, e.g. https://salilab.org/internal/imp/nightly/results/?comp=177&plat=3 (it'll be hard to spot the failure though since you have a bunch of other test failures right now!)

I suspect that it is because numpy.savetxt writes in binary and we pass it a file that has been opened in text mode?

Looks like it. Why not open the file in binary mode instead? On Python 2 this will make no difference, but on Python 3 it'll treat the file as a set of bytes rather than a string of Unicode characters, and that's probably what you want. Just open the file with "wb" rather than "w".

saltzberg commented 8 years ago

That change works for me (but of course, it worked before).

And yes, I need to go through and rewrite/expand a bunch of the test functions, including this issue, so keep this open until I write one.