diff --git a/nupic/support/__init__.py b/nupic/support/__init__.py index d774e34e15..a8fe4fa2c8 100644 --- a/nupic/support/__init__.py +++ b/nupic/support/__init__.py @@ -566,45 +566,6 @@ def handleErrorPatch(*args, **kwargs): handler.handleError = handleErrorPatch return - - - -def clippedObj(obj, maxElementSize=64): - """ - Return a clipped version of obj suitable for printing, This - is useful when generating log messages by printing data structures, but - don't want the message to be too long. - - If passed in a dict, list, or namedtuple, each element of the structure's - string representation will be limited to 'maxElementSize' characters. This - will return a new object where the string representation of each element - has been truncated to fit within maxElementSize. - """ - - # Is it a named tuple? - if hasattr(obj, '_asdict'): - obj = obj._asdict() - - - # Printing a dict? - if isinstance(obj, dict): - objOut = dict() - for key,val in obj.iteritems(): - objOut[key] = clippedObj(val) - - # Printing a list? - elif hasattr(obj, '__iter__'): - objOut = [] - for val in obj: - objOut.append(clippedObj(val)) - - # Some other object - else: - objOut = str(obj) - if len(objOut) > maxElementSize: - objOut = objOut[0:maxElementSize] + '...' - - return objOut @@ -744,6 +705,3 @@ def aggregationDivide(dividend, divisor): else: return float(dividendMonthSec['seconds']) / divisorMonthSec['seconds'] - - - diff --git a/nupic/swarming/DummyModelRunner.py b/nupic/swarming/DummyModelRunner.py index 5e89b7f82b..7a4a76c301 100644 --- a/nupic/swarming/DummyModelRunner.py +++ b/nupic/swarming/DummyModelRunner.py @@ -31,7 +31,7 @@ from nupic.frameworks.opf.modelfactory import ModelFactory from nupic.frameworks.opf import opfhelpers from nupic.frameworks.opf.opfutils import ModelResult -from nupic.swarming import utils +from nupic.swarming.hypersearch import utils from nupic.swarming.ModelRunner import OPFModelRunner diff --git a/nupic/swarming/HypersearchV2.py b/nupic/swarming/HypersearchV2.py index 3d24579d47..fea131cd6a 100644 --- a/nupic/swarming/HypersearchV2.py +++ b/nupic/swarming/HypersearchV2.py @@ -36,14 +36,14 @@ from nupic.data import dictutils from nupic.frameworks.opf import opfhelpers from nupic.frameworks.opf.opfutils import InferenceType -from nupic.support import clippedObj +from nupic.swarming.hypersearch.utils import clippedObj from nupic.support.serializationutils import sortedJSONDumpS from nupic.support.configuration import Configuration from nupic.swarming.hypersearch.errorcodes import ErrorCodes from nupic.database.ClientJobsDAO import ( ClientJobsDAO, InvalidConnectionException) -from nupic.swarming.utils import (runModelGivenBaseAndParams, - runDummyModel) +from nupic.swarming.hypersearch.utils import (runModelGivenBaseAndParams, + runDummyModel) from nupic.swarming.permutationhelpers import * from nupic.swarming.exp_generator.ExpGenerator import expGenerator diff --git a/nupic/swarming/HypersearchWorker.py b/nupic/swarming/HypersearchWorker.py index 41a8060060..cc2199bf8e 100755 --- a/nupic/swarming/HypersearchWorker.py +++ b/nupic/swarming/HypersearchWorker.py @@ -33,7 +33,7 @@ import traceback from nupic.data import jsonhelpers -from nupic.support import clippedObj +from nupic.swarming.hypersearch.utils import clippedObj from nupic.support import initLogging from nupic.support.configuration import Configuration from nupic.support.ExtendedLogger import ExtendedLogger diff --git a/nupic/swarming/ModelRunner.py b/nupic/swarming/ModelRunner.py index 2ffd57f707..b7d4dfabe8 100644 --- a/nupic/swarming/ModelRunner.py +++ b/nupic/swarming/ModelRunner.py @@ -42,7 +42,7 @@ from nupic.swarming.hypersearch.errorcodes import ErrorCodes from nupic.database.ClientJobsDAO import ClientJobsDAO from nupic.swarming import regression -from nupic.swarming import utils +from nupic.swarming.hypersearch import utils diff --git a/nupic/swarming/ModelTerminator.py b/nupic/swarming/ModelTerminator.py index 7306d4ab36..1ea2e45a3d 100644 --- a/nupic/swarming/ModelTerminator.py +++ b/nupic/swarming/ModelTerminator.py @@ -21,7 +21,7 @@ import functools -from nupic.swarming.utils import PeriodicActivityRequest +from nupic.swarming.hypersearch.utils import PeriodicActivityRequest diff --git a/nupic/swarming/utils.py b/nupic/swarming/hypersearch/utils.py similarity index 94% rename from nupic/swarming/utils.py rename to nupic/swarming/hypersearch/utils.py index ce4021a1ca..a97ac12790 100644 --- a/nupic/swarming/utils.py +++ b/nupic/swarming/hypersearch/utils.py @@ -559,3 +559,42 @@ def generatePersistentJobGUID(): """ return "JOB_UUID1-" + str(uuid.uuid1()) + + + +def clippedObj(obj, maxElementSize=64): + """ + Return a clipped version of obj suitable for printing, This + is useful when generating log messages by printing data structures, but + don't want the message to be too long. + + If passed in a dict, list, or namedtuple, each element of the structure's + string representation will be limited to 'maxElementSize' characters. This + will return a new object where the string representation of each element + has been truncated to fit within maxElementSize. + """ + + # Is it a named tuple? + if hasattr(obj, '_asdict'): + obj = obj._asdict() + + + # Printing a dict? + if isinstance(obj, dict): + objOut = dict() + for key,val in obj.iteritems(): + objOut[key] = clippedObj(val) + + # Printing a list? + elif hasattr(obj, '__iter__'): + objOut = [] + for val in obj: + objOut.append(clippedObj(val)) + + # Some other object + else: + objOut = str(obj) + if len(objOut) > maxElementSize: + objOut = objOut[0:maxElementSize] + '...' + + return objOut diff --git a/nupic/swarming/permutations_runner.py b/nupic/swarming/permutations_runner.py index 2d9b8d8482..107d4b3b13 100644 --- a/nupic/swarming/permutations_runner.py +++ b/nupic/swarming/permutations_runner.py @@ -39,7 +39,8 @@ from nupic.support import object_json as json import nupic.database.ClientJobsDAO as cjdao -from nupic.swarming import HypersearchWorker, utils +from nupic.swarming import HypersearchWorker +from nupic.swarming.hypersearch import utils from nupic.swarming.HypersearchV2 import HypersearchV2 from nupic.swarming.exp_generator.ExpGenerator import expGenerator diff --git a/tests/integration/nupic/opf/expgenerator_test.py b/tests/integration/nupic/opf/expgenerator_test.py index f40b4e7bec..f1da523633 100755 --- a/tests/integration/nupic/opf/expgenerator_test.py +++ b/tests/integration/nupic/opf/expgenerator_test.py @@ -42,7 +42,7 @@ TestCaseBase as HelperTestCaseBase) from nupic.swarming import HypersearchWorker from nupic.swarming.permutationhelpers import PermuteChoices -from nupic.swarming.utils import generatePersistentJobGUID +from nupic.swarming.hypersearch.utils import generatePersistentJobGUID from nupic.frameworks.opf.expdescriptionapi import OpfEnvironment from nupic.swarming.exp_generator import ExpGenerator from nupic.frameworks.opf.opfutils import (InferenceType, diff --git a/tests/regression/run_opf_benchmarks_test.py b/tests/regression/run_opf_benchmarks_test.py index 69a2975ff1..0e6cd47ad1 100755 --- a/tests/regression/run_opf_benchmarks_test.py +++ b/tests/regression/run_opf_benchmarks_test.py @@ -46,7 +46,7 @@ from nupic.support.configuration import Configuration from nupic.support.unittesthelpers.testcasebase import unittest from nupic.swarming import permutations_runner -from nupic.swarming.utils import generatePersistentJobGUID +from nupic.swarming.hypersearch.utils import generatePersistentJobGUID diff --git a/tests/swarming/nupic/swarming/swarming_test.py b/tests/swarming/nupic/swarming/swarming_test.py index 781e08a195..63aec58159 100755 --- a/tests/swarming/nupic/swarming/swarming_test.py +++ b/tests/swarming/nupic/swarming/swarming_test.py @@ -48,7 +48,7 @@ TestCaseBase as HelperTestCaseBase) from nupic.swarming import HypersearchWorker from nupic.swarming.api import getSwarmModelParams, createAndStartSwarm -from nupic.swarming.utils import generatePersistentJobGUID +from nupic.swarming.hypersearch.utils import generatePersistentJobGUID from nupic.swarming.DummyModelRunner import OPFDummyModelRunner DEFAULT_JOB_TIMEOUT_SEC = 60 * 2