-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix visdom integration (using
viz.line()
instead of `viz.updatetrac…
…e()`) (#2252) * using viz.line() instead of viz.updatetrace() Visdom had changed it's API according to this post: fossasia/visdom#359 * add simple test for visdom viz.line() update graph API (for visdom >= 0.1.8) * use easydict instead of argparse * use self defined class instead of easydict * change to test lda callback update graph function * fix python2 subprocess don't have TimeoutExpired Atttribute error * fix lint error * fix lint error * upd test
- Loading branch information
1 parent
680de8d
commit 007afa1
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters