Repository: piskvorky/gensim

Issue:
"AttributeError: 'Visdom' object has no attribute 'updateTrace'" when running "Training_visualizations.ipynb"
"updateTrace" has been deprecated in the newest version of  Visdom, but it is still being called in Gensim, so failed to run callbacks in "Training_visualizations.ipynb". Hope this issue can be fixed, thanks!
See
https://github.com/facebookresearch/visdom/issues/358


Discussion:
Thanks for report @yingchengsun.
What should we use now instead of this function? What's concrete version of when this was removed?
One author of Visdom (JackUrb) said "Rather than calling updateTrace, you can simply use scatter or line with the update you want to make. ", but I tried to use scatter or line, still could not see the plot results, maybe you can have a try? 
See
https://github.com/facebookresearch/visdom/issues/359

Also, I failed to find the concrete version of when this was removed. No clues.
add the  flag (update = 'append') in your line func

Resolving patch:
diff --git a/gensim/models/callbacks.py b/gensim/models/callbacks.py
--- a/gensim/models/callbacks.py
+++ b/gensim/models/callbacks.py
@@ -549,8 +549,12 @@ def on_epoch_end(self, epoch, topics=None):
                         )
                         self.diff_mat.put(diff_mat)
                     else:
-                        self.viz.updateTrace(
-                            Y=np.array([value]), X=np.array([epoch]), env=metric.viz_env, win=self.windows[i]
+                        self.viz.line(
+                            Y=np.array([value]),
+                            X=np.array([epoch]),
+                            env=metric.viz_env,
+                            win=self.windows[i],
+                            update='append'
                         )
 
             if metric.logger == "shell":
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -232,6 +232,7 @@ def finalize_options(self):
     'testfixtures',
     'scikit-learn',
     'Morfessor==2.0.2a4',
+    'visdom >= 0.1.8',
 ]
 
 linux_testenv = win_testenv[:]


Test patch:
diff --git a/gensim/test/test_lda_callback.py b/gensim/test/test_lda_callback.py
new file mode 100644
--- /dev/null
+++ b/gensim/test/test_lda_callback.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2018 Allenyl <allen7575@gmail.com>
+# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
+
+"""
+Automated tests for checking visdom API
+"""
+import unittest
+import subprocess
+import time
+
+from gensim.models import LdaModel
+from gensim.test.utils import datapath, common_dictionary
+from gensim.corpora import MmCorpus
+from gensim.models.callbacks import CoherenceMetric
+
+try:
+    from visdom import Visdom
+    VISDOM_INSTALLED = True
+except ImportError:
+    VISDOM_INSTALLED = False
+
+
+@unittest.skipIf(VISDOM_INSTALLED is False, "Visdom not installed")
+class TestLdaCallback(unittest.TestCase):
+
+    def setUp(self):
+        self.corpus = MmCorpus(datapath('testcorpus.mm'))
+        self.ch_umass = CoherenceMetric(corpus=self.corpus, coherence="u_mass", logger="visdom", title="Coherence")
+        self.callback = [self.ch_umass]
+        self.model = LdaModel(id2word=common_dictionary, num_topics=2, passes=10, callbacks=self.callback)
+
+        self.host = "http://localhost"
+        self.port = 8097
+
+    def testCallbackUpdateGraph(self):
+
+        # Popen have no context-manager in 2.7, for this reason - try/finally.
+        try:
+            # spawn visdom.server
+            proc = subprocess.Popen(['python', '-m', 'visdom.server', '-port', str(self.port)])
+
+            # wait for visdom server startup (any better way?)
+            time.sleep(3)
+
+            viz = Visdom(server=self.host, port=self.port)
+            assert viz.check_connection()
+
+            # clear screen
+            viz.close()
+
+            self.model.update(self.corpus)
+        finally:
+            proc.kill()
+
+
+if __name__ == '__main__':
+    unittest.main()