Closed b-dawes closed 6 years ago
Hi Brian,
This is rather odd - I have tested this with Python 3.5, R 3.4 and Windows 10 and it works fine, but perhaps Windows 10 interacts with Python differently. I can add in a workaround in the Python logging module to catch this exception, but the result might be that MAGIC won't print output to the R console. Is that acceptable for you?
Also, if you could please run reticulate::py_config()
in R and post the results for reference that would be appreciated.
Thanks very much for the report.
Best, Scott
@b-dawes if you could please try out the new fix by running
pip install --user git+git://github.com/KrishnaswamyLab/MAGIC.git@windows7_logging#subdirectory=python
and let me know what happens when you run Rmagic
, that would be much appreciated.
Thanks for the quick response Scott!
This isn't a huge issue for me as it still runs and outputs the messages, I mostly just wanted to let you guys know about it. One thing that I noticed might be missing if messages aren't printed is the optimal value of t when running with t=auto. I looked around in the $operator slot for this and wasn't able to find it there (let me know if it is in there somewhere and I just missed it).
I'll try the patched version and let you know the results.
Also my py_config:
python: C:\Users\bdawes\AppData\Local\Continuum\Anaconda2\envs\python3\python.exe
libpython: C:/Users/bdawes/AppData/Local/Continuum/Anaconda2/envs/python3/python35.dll
pythonhome: C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3
version: 3.5.3 | packaged by conda-forge | (default, May 12 2017, 16:16:49) [MSC v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\numpy
numpy_version: 1.14.1
magic: C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\__init__.p
python versions found:
C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\python.exe
C:\Users\bdawes\AppData\Local\Continuum\Anaconda2\envs\python3\python.exe
I installed the patched version and got some even weirder results. Some of the steps printed properly, while other steps did not. Some of the steps that had errors also had an error with _kernel, but there were a few steps where the only error was the OSError and it still threw the error. Also, the properly printed steps seemed to go to STDOUT while the errors were all in STDERR. Here's the full log I recieved:
C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Calculating MAGIC...
Calculating graph and diffusion operator...
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\logging\__init__.py", line 983, in emit
stream.write(msg)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 29, in write_r_safe
os.write(1, bytes(msg, 'utf8'))
OSError: [Errno 9] Bad file descriptor
Call stack:
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 524, in fit_transform
self.fit(X)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 382, in fit
random_state=self.random_state)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\api.py", line 232, in Graph
return Graph(**params)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 80, in __init__
super().__init__(data, n_pca=n_pca, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 601, in __init__
super().__init__(data, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 130, in __init__
self.data_nu = self._reduce_data()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 155, in _reduce_data
log_start("PCA")
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 109, in log_start
get_task_logger().start_task(name)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 50, in start_task
self.log("Calculating {}...".format(name))
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 46, in log
self.logger.info(msg)
Message: 'Calculating PCA...'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\logging\__init__.py", line 983, in emit
stream.write(msg)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 29, in write_r_safe
os.write(1, bytes(msg, 'utf8'))
OSError: [Errno 9] Bad file descriptor
Call stack:
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 524, in fit_transform
self.fit(X)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 382, in fit
random_state=self.random_state)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\api.py", line 232, in Graph
return Graph(**params)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 80, in __init__
super().__init__(data, n_pca=n_pca, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 601, in __init__
super().__init__(data, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 130, in __init__
self.data_nu = self._reduce_data()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 169, in _reduce_data
log_complete("PCA")
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 124, in log_complete
get_task_logger().complete_task(name)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 57, in complete_task
name, runtime))
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 46, in log
self.logger.info(msg)
Message: 'Calculated PCA in 1.98 seconds.'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 482, in K
return self._kernel
AttributeError: 'kNNGraph' object has no attribute '_kernel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\logging\__init__.py", line 983, in emit
stream.write(msg)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 29, in write_r_safe
os.write(1, bytes(msg, 'utf8'))
OSError: [Errno 9] Bad file descriptor
Call stack:
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 524, in fit_transform
self.fit(X)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 382, in fit
random_state=self.random_state)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\api.py", line 232, in Graph
return Graph(**params)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 80, in __init__
super().__init__(data, n_pca=n_pca, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 601, in __init__
super().__init__(data, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 131, in __init__
super().__init__(**kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 346, in __init__
self.K
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 484, in K
self._kernel = self._build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 384, in _build_kernel
kernel = self.build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 185, in build_kernel
K = self.build_kernel_to_data(self.data_nu)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 222, in build_kernel_to_data
log_start("KNN search")
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 109, in log_start
get_task_logger().start_task(name)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 50, in start_task
self.log("Calculating {}...".format(name))
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 46, in log
self.logger.info(msg)
Message: 'Calculating KNN search...'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 482, in K
return self._kernel
AttributeError: 'kNNGraph' object has no attribute '_kernel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\logging\__init__.py", line 983, in emit
stream.write(msg)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 29, in write_r_safe
os.write(1, bytes(msg, 'utf8'))
OSError: [Errno 9] Bad file descriptor
Call stack:
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 524, in fit_transform
self.fit(X)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 382, in fit
random_state=self.random_state)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\api.py", line 232, in Graph
return Graph(**params)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 80, in __init__
super().__init__(data, n_pca=n_pca, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 601, in __init__
super().__init__(data, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 131, in __init__
super().__init__(**kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 346, in __init__
self.K
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 484, in K
self._kernel = self._build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 384, in _build_kernel
kernel = self.build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 185, in build_kernel
K = self.build_kernel_to_data(self.data_nu)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 249, in build_kernel_to_data
log_complete("KNN search")
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 124, in log_complete
get_task_logger().complete_task(name)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 57, in complete_task
name, runtime))
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 46, in log
self.logger.info(msg)
Message: 'Calculated KNN search in 0.23 seconds.'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 482, in K
return self._kernel
AttributeError: 'kNNGraph' object has no attribute '_kernel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\logging\__init__.py", line 983, in emit
stream.write(msg)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 29, in write_r_safe
os.write(1, bytes(msg, 'utf8'))
OSError: [Errno 9] Bad file descriptor
Call stack:
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 524, in fit_transform
self.fit(X)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 382, in fit
random_state=self.random_state)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\api.py", line 232, in Graph
return Graph(**params)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 80, in __init__
super().__init__(data, n_pca=n_pca, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 601, in __init__
super().__init__(data, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 131, in __init__
super().__init__(**kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 346, in __init__
self.K
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 484, in K
self._kernel = self._build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 384, in _build_kernel
kernel = self.build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 185, in build_kernel
K = self.build_kernel_to_data(self.data_nu)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 250, in build_kernel_to_data
log_start("affinities")
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 109, in log_start
get_task_logger().start_task(name)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 50, in start_task
self.log("Calculating {}...".format(name))
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 46, in log
self.logger.info(msg)
Message: 'Calculating affinities...'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 482, in K
return self._kernel
AttributeError: 'kNNGraph' object has no attribute '_kernel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\logging\__init__.py", line 983, in emit
stream.write(msg)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 29, in write_r_safe
os.write(1, bytes(msg, 'utf8'))
OSError: [Errno 9] Bad file descriptor
Call stack:
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 524, in fit_transform
self.fit(X)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\magic\magic.py", line 382, in fit
random_state=self.random_state)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\api.py", line 232, in Graph
return Graph(**params)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 80, in __init__
super().__init__(data, n_pca=n_pca, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 601, in __init__
super().__init__(data, **kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 131, in __init__
super().__init__(**kwargs)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 346, in __init__
self.K
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 484, in K
self._kernel = self._build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\base.py", line 384, in _build_kernel
kernel = self.build_kernel()
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 185, in build_kernel
K = self.build_kernel_to_data(self.data_nu)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\graphs.py", line 300, in build_kernel_to_data
log_complete("affinities")
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 124, in log_complete
get_task_logger().complete_task(name)
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 57, in complete_task
name, runtime))
File "C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\python3\lib\site-packages\graphtools\logging.py", line 46, in log
self.logger.info(msg)
Message: 'Calculated affinities in 0.72 seconds.'
Arguments: ()
Calculated graph and diffusion operator in 3.02 seconds.
Calculating imputation...
Automatically selected t = 12
Calculated imputation in 0.63 seconds.
Calculated MAGIC in 3.84 seconds.
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:\Users\bdawes\AppData\Local\CONTIN~1\ANACON~1\envs\pipenv/python.exe": The system cannot find the file specified
My apologies, this is my fault for having identical logging modules in both graphtools and MAGIC. You'll need to also install
pip install --user git+git://github.com/KrishnaswamyLab/graphtools.git@windows7_logging
Hopefully that resolves the problem. I'll also fix the change to logging which is now returning double whitespace.
Thanks Scott. I had to pip uninstall graphtools before installing the patched version, but it is now working fine. Also the extra whitespace is gone too. My output:
Calculating MAGIC...
Calculating graph and diffusion operator...
Calculating PCA...
Calculated PCA in 1.81 seconds.
Calculating KNN search...
Calculated KNN search in 0.23 seconds.
Calculating affinities...
Calculated affinities in 0.70 seconds.
Calculated graph and diffusion operator in 2.82 seconds.
Calculating imputation...
Automatically selected t = 12
Calculated imputation in 0.59 seconds.
Calculated MAGIC in 3.63 seconds.
Thanks again, Brian
Thanks Brian for the confirmation. This fix is now on the dev
branch and will be a part of the next release.
Hello,
I've been trying to run magic in R for easier compatibility with the seurat library. I'm able to run magic and get results, however there is an issue with the logging. Everytime something is logged, I get an error message followed by the actual message. For example, here's the last part of the log:
I would assume this is probably caused either by running on Windows or running in R. For reference, I'm using R 3.4.1, python 3.5.3, and Windows 7. Let me know if there's any further info you need.
Best, Brian