def test_session_push_sklearn():
    '''Tests basic model pushing functionality with sklearn'''
    clear_jwt()

    with _patch_auth():
        with MockServer() as server:
            iris = load_iris()
            X = iris.data
            y = iris.target

            clf = RandomForestClassifier(random_state=0)
            clf.fit(X, y)

            columns = [
                'sepallength', 'sepalwidth', 'petallength', 'petalwidth'
            ]
            X_df = pd.DataFrame(X, columns=columns)

            DataFrame = create_dataframe('DataFrame', X_df)
            Predictions = create_namedtuple('Predictions',
                                            [('predictions', List[int])])

            def predict(df: DataFrame) -> Predictions:
                '''Predicts the class of iris'''
                X = np.column_stack(df)
                yhat = clf.predict(X)
                preds = Predictions(predictions=yhat)
                return preds

            model = Model(predict=predict)

            model_url, auth_url, _, _ = server.config
            s = AcumosSession(model_url, auth_url)
            s.push(model, name='sklearn_iris_push')
Esempio n. 2
0
    def test_rcp_functions(self):
        c = Client()
        with MockServer(c.address.port) as s:
            self.assertTrue(c.call('foo'))
            with self.assertRaises(RPCError):
                c.call('not_existing')

            c.add_functions()
            self.assertTrue(c.call(Client.FUNCNAME_PING))
            self.assertTrue(c.call('sum', 1, 2) == c.sum(1, 2))
Esempio n. 3
0
 def test_reconnect_to_new(self):
     c = Client(server_port=None, reconnect_limit=100)
     import concurrent.futures
     with concurrent.futures.ThreadPoolExecutor() as executor:
         # calling rpc function before the server is launched. The call should just hang in there waiting for the
         # server to come on line (up until set limit of reconnect attempts)
         future = executor.submit(c.call, 'sum', 1, 2)
         with MockServer(c.address.port) as s:
             return_value = future.result()
             self.assertEqual(return_value, 3)
def _push_dummy_model(extra_headers=None):
    '''Generic dummy model push routine'''
    def my_transform(x: int, y: int) -> int:
        return x + y

    model = Model(transform=my_transform)

    with MockServer() as server:
        model_url, auth_url, _, _ = server.config
        s = AcumosSession(model_url, auth_url)
        s.push(model, name='my-model', extra_headers=extra_headers)
    def setUp(self):
        self.lldb_debugger = lldb.SBDebugger.Create()
        self.lldb_debugger.CreateTargetWithFileAndArch(
            self.__class__.test_executable.executable_path,
            lldb.LLDB_ARCH_DEFAULT)

        self.server = MockServer()
        file_manager = FileManager(self.server)
        self.remote_object_manager = RemoteObjectManager()
        self.debugger = DebuggerDomain(None,
                                       file_manager,
                                       self.remote_object_manager,
                                       debugger=self.lldb_debugger,
                                       socket=self.server)
Esempio n. 6
0
    def setUp(self):
        self.lldb_debugger = lldb.SBDebugger.Create()
        self.lldb_debugger.CreateTargetWithFileAndArch(
            self.__class__.test_executable.executable_path,
            lldb.LLDB_ARCH_DEFAULT)

        self.server = MockServer()
        file_manager = FileManager(self.server)
        self.location_serializer = LocationSerializer(file_manager, '.')
        self.remote_object_manager = RemoteObjectManager()
        self.thread_manager = ThreadManager(
                                self.server,
                                self.location_serializer,
                                self.remote_object_manager)
Esempio n. 7
0
def _push_dummy_model(extra_headers=None,
                      use_model_url=True,
                      use_auth_url=False,
                      options=None):
    '''Generic dummy model push routine'''
    def my_transform(x: int, y: int) -> int:
        return x + y

    model = Model(transform=my_transform)

    with MockServer() as server:
        _model_url, _auth_url, _, _ = server.config
        model_url = _model_url if use_model_url else None
        auth_url = _auth_url if use_auth_url else None

        session = AcumosSession(model_url, auth_url)
        session.push(model,
                     name='my-model',
                     extra_headers=extra_headers,
                     options=options)
def test_session_push_keras():
    '''Tests basic model pushing functionality with keras'''
    clear_jwt()

    with _patch_auth():
        with MockServer() as server:
            iris = load_iris()
            X = iris.data
            y = pd.get_dummies(iris.target).values

            clf = Sequential()
            clf.add(Dense(3, input_dim=4, activation='relu'))
            clf.add(Dense(3, activation='softmax'))
            clf.compile(loss='categorical_crossentropy',
                        optimizer='adam',
                        metrics=['accuracy'])
            clf.fit(X, y)

            columns = [
                'sepallength', 'sepalwidth', 'petallength', 'petalwidth'
            ]
            X_df = pd.DataFrame(X, columns=columns)

            DataFrame = create_dataframe('DataFrame', X_df)
            Predictions = create_namedtuple('Predictions',
                                            [('predictions', List[int])])

            def predict(df: DataFrame) -> Predictions:
                '''Predicts the class of iris'''
                X = np.column_stack(df)
                yhat = clf.predict(X)
                preds = Predictions(predictions=yhat)
                return preds

            model = Model(predict=predict)

            model_url, auth_url, _, _ = server.config
            s = AcumosSession(model_url, auth_url)
            s.push(model, name='keras_iris_push')
Esempio n. 9
0
 def setUp(self):
     self.server = MockServer()
     self.console = ConsoleDomain(socket=self.server, debugger=None)