Repository: pytorch/ignite

Issue:
TypeError: type object got multiple values for keyword argument 'logdir'
>from ignite.contrib.handlers.tensorboard_logger import TensorboardLogger
>tb = TensorboardLogger(log_dir=None) 

gives the following error:

>     self.file_writer = FileWriter(logdir=log_dir, **kwargs)
> TypeError: type object got multiple values for keyword argument 'logdir'

This also happens when I run

>from tensorboardX import SummaryWriter
>sw = SummaryWriter(log_dir=None)

>     self.file_writer = FileWriter(logdir=log_dir, **kwargs)
> TypeError: type object got multiple values for keyword argument 'logdir'

However, when I do don't put in logdir=log_dir, and simply pass in log_dir, it works fine.

I was looking to see if there's any conflicting reference with `self` or anything like that, but it doesn't seem like that's the problem, since all the `self`'s seem to be in place, so I'm not sure.

Any ideas?

ignite version: 1.1.0
tensorboard version: 1.13.1
tensorboardX version: 1.6


Discussion:
Could you please detail ignite and tensorboard versions you have?
Please check out my updated question. I've included the versions.
@UltraSpecialException unfortunately, ignite latest pypi/conda version is still 0.2.0. So I suppose you mean pytorch `1.1.0`. My question is whether you installed ignite from master or the latest release? 
@vfdev-5 My bad, I was looking at another ignite, my pytorch-ignite is indeed 0.2.0. I installed through master.
@UltraSpecialException ~~I can not reproduce your problem:~~
```bash
(test) # conda list
# packages in environment at /opt/conda/envs/test:
#
# Name                    Version                   Build  Channel
absl-py                   0.7.1                    pypi_0    pypi
blas                      1.0                         mkl
ca-certificates           2019.1.23                     0
certifi                   2019.3.9                 py36_0
cffi                      1.12.3           py36h2e261b9_0
cudatoolkit               10.0.130                      0
grpcio                    1.21.1                   pypi_0    pypi
ignite                    0.2.0                    py36_0    pytorch
intel-openmp              2019.3                      199
libedit                   3.1.20181209         hc058e9b_0
libffi                    3.2.1                hd88cf55_4
libgcc-ng                 8.2.0                hdf63c60_1
libgfortran-ng            7.3.0                hdf63c60_0
libstdcxx-ng              8.2.0                hdf63c60_1
markdown                  3.1.1                    pypi_0    pypi
mkl                       2019.3                      199
mkl_fft                   1.0.12           py36ha843d7b_0
mkl_random                1.0.2            py36hd81dba3_0
ncurses                   6.1                  he6710b0_1
ninja                     1.9.0            py36hfd86e86_0
numpy                     1.16.3           py36h7e9f1db_0
numpy-base                1.16.3           py36hde5b4d6_0
openssl                   1.1.1b               h7b6447c_1
pip                       19.1.1                   py36_0
protobuf                  3.7.1                    pypi_0    pypi
pycparser                 2.19                     py36_0
python                    3.6.8                h0371630_0
pytorch                   1.1.0           py3.6_cuda10.0.130_cudnn7.5.1_0    pytorch
readline                  7.0                  h7b6447c_5
setuptools                41.0.1                   py36_0
six                       1.12.0                   pypi_0    pypi
sqlite                    3.28.0               h7b6447c_0
tensorboard               1.13.1                   pypi_0    pypi
tensorboardx              1.6                      pypi_0    pypi
tk                        8.6.8                hbc83047_0
werkzeug                  0.15.4                   pypi_0    pypi
wheel                     0.33.4                   py36_0
xz                        5.2.4                h14c3975_4
zlib                      1.2.11               h7b6447c_3
```
and 
```
python -c "from ignite.contrib.handlers.tensorboard_logger import TensorboardLogger; tb = TensorboardLogger(log_dir=None)"
```
Please, check your dependencies or tell me if I'm missing something.

**EDIT**: I see you installed pytorch-ignite from master. Thanks for reporting!
I think the problem is in `self.writer = SummaryWriter(logdir=log_dir)` in `tensorboard_logger.py` (line 408 in the class TensorboardLogger). `logdir` should be `log_dir`(since the class SummaryWriter has parameter `log_dir`, not `logdir`). 
@UltraSpecialException it depends on the version of installed tensorboardX. In 1.6 it is `log_dir` and since 1.7 it is `logdir`.
I think we need handle both version for instance until 0.3.0. So we need to intercept the exception
```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/conda/envs/test/lib/python3.6/site-packages/ignite/contrib/handlers/tensorboard_logger.py", line 408, in __init__
    self.writer = SummaryWriter(logdir=log_dir)
  File "/opt/conda/envs/test/lib/python3.6/site-packages/tensorboardX/writer.py", line 279, in __init__
    self.file_writer = FileWriter(logdir=log_dir, **kwargs)
TypeError: type object got multiple values for keyword argument 'logdir'
```
and raise a warning saying to update to tensorboardX==1.7 and setup `self.writer` with another argument.

cc @anmolsjoshi 

Resolving patch:
diff --git a/ignite/contrib/handlers/tensorboard_logger.py b/ignite/contrib/handlers/tensorboard_logger.py
--- a/ignite/contrib/handlers/tensorboard_logger.py
+++ b/ignite/contrib/handlers/tensorboard_logger.py
@@ -405,7 +405,16 @@ def __init__(self, log_dir):
             raise RuntimeError("This contrib module requires tensorboardX to be installed. "
                                "Please install it with command: \n pip install tensorboardX")
 
-        self.writer = SummaryWriter(logdir=log_dir)
+        try:
+            self.writer = SummaryWriter(logdir=log_dir)
+        except TypeError as err:
+            if "type object got multiple values for keyword argument 'logdir'" == str(err):
+                self.writer = SummaryWriter(log_dir=log_dir)
+                warnings.warn('tensorboardX version < 1.7 will not be supported '
+                              'after ignite 0.3.0; please upgrade',
+                              DeprecationWarning)
+            else:
+                raise err
 
     def close(self):
         self.writer.close()


Test patch:
diff --git a/tests/ignite/contrib/handlers/test_tensorboard_logger.py b/tests/ignite/contrib/handlers/test_tensorboard_logger.py
--- a/tests/ignite/contrib/handlers/test_tensorboard_logger.py
+++ b/tests/ignite/contrib/handlers/test_tensorboard_logger.py
@@ -3,10 +3,9 @@
 import shutil
 import math
 
-import numpy as np
 import pytest
 
-from mock import MagicMock, call, ANY
+from mock import MagicMock, call, ANY, Mock
 
 import torch
 
@@ -541,3 +540,40 @@ def test_no_tensorboardX(dirname, no_site_packages):
 
     with pytest.raises(RuntimeError, match=r"This contrib module requires tensorboardX to be installed"):
         TensorboardLogger(log_dir=dirname)
+
+
+@pytest.fixture
+def mock_tb_module():
+    import sys
+    import types
+
+    module_name = 'tensorboardX'
+    tb_module = types.ModuleType(module_name)
+    prev_tb_module = sys.modules[module_name]
+    sys.modules[module_name] = tb_module
+
+    yield tb_module
+    sys.modules[module_name] = prev_tb_module
+
+
+def test_init_tb1p6(mock_tb_module):
+
+    def side_effect_v1p6(*args, **kwargs):
+        if 'logdir' in kwargs:
+            raise TypeError("type object got multiple values for keyword argument 'logdir'")
+
+    mock_tb_module.SummaryWriter = Mock(name='tensorboardX.SummaryWriter', side_effect=side_effect_v1p6)
+
+    with pytest.warns(DeprecationWarning, match=r'tensorboardX version < 1.7 will not be supported'):
+        TensorboardLogger(log_dir=None)
+
+
+def test_init_typeerror_exception(mock_tb_module):
+
+    def side_effect(*args, **kwargs):
+        raise TypeError("a problem")
+
+    mock_tb_module.SummaryWriter = Mock(name='tensorboardX.SummaryWriter', side_effect=side_effect)
+
+    with pytest.raises(TypeError, match=r'a problem'):
+        TensorboardLogger(log_dir=None)