Пример #1
0
def test_logging():
    '''Test logging to a file'''
    # create a stringio and a handler to log to it
    def get_handler():
        try:
            from StringIO import StringIO
        except ImportError:
            from io import StringIO
        sobj = StringIO()
        hdlr = logging.StreamHandler(sobj)
        hdlr.setLevel(logging.DEBUG)
        return hdlr

    oc = Oct2Py()
    hdlr = get_handler()
    oc.logger.addHandler(hdlr)

    # generate some messages (logged and not logged)
    oc.ones(1, verbose=True)

    oc.logger.setLevel(logging.DEBUG)
    oc.zeros(1)

    # check the output
    lines = hdlr.stream.getvalue().strip().split('\n')
    assert len(lines) == 8
    assert lines[0].startswith('load')

    # now make an object with a desired logger
    logger = oct2py.get_log('test')
    hdlr = get_handler()
    logger.addHandler(hdlr)
    logger.setLevel(logging.INFO)
    oc2 = Oct2Py(logger=logger)

     # generate some messages (logged and not logged)
    oc2.ones(1, verbose=True)

    oc2.logger.setLevel(logging.DEBUG)
    oc2.zeros(1)

    # check the output
    lines = hdlr.stream.getvalue().strip().split('\n')
    assert len(lines) == 8
    assert lines[0].startswith('load')
Пример #2
0
def test_logging():
    # create a stringio and a handler to log to it
    def get_handler():
        sobj = StringIO()
        hdlr = logging.StreamHandler(sobj)
        hdlr.setLevel(logging.DEBUG)
        return hdlr

    oc = Oct2Py()
    hdlr = get_handler()
    oc.logger.addHandler(hdlr)

    # generate some messages (logged and not logged)
    oc.ones(1, verbose=True)

    oc.logger.setLevel(logging.DEBUG)
    oc.zeros(1)

    # check the output
    lines = hdlr.stream.getvalue().strip().split('\n')
    resp = '\n'.join(lines)
    assert 'zeros(A__)' in resp
    assert 'ans =  1' in resp
    assert lines[0].startswith('load')

    # now make an object with a desired logger
    logger = oct2py.get_log('test')
    hdlr = get_handler()
    logger.addHandler(hdlr)
    logger.setLevel(logging.INFO)
    oc2 = Oct2Py(logger=logger)

    # generate some messages (logged and not logged)
    oc2.ones(1, verbose=True)

    oc2.logger.setLevel(logging.DEBUG)
    oc2.zeros(1)

    # check the output
    lines = hdlr.stream.getvalue().strip().split('\n')
    resp = '\n'.join(lines)
    assert 'zeros(A__)' in resp
    assert 'ans =  1' in resp
    assert lines[0].startswith('load')
Пример #3
0
def test_logging():
    # create a stringio and a handler to log to it
    def get_handler():
        sobj = StringIO()
        hdlr = logging.StreamHandler(sobj)
        hdlr.setLevel(logging.DEBUG)
        return hdlr

    oc = Oct2Py()
    hdlr = get_handler()
    oc.logger.addHandler(hdlr)

    # generate some messages (logged and not logged)
    oc.ones(1, verbose=True)

    oc.logger.setLevel(logging.DEBUG)
    oc.zeros(1)

    # check the output
    lines = hdlr.stream.getvalue().strip().split('\n')
    resp = '\n'.join(lines)
    assert 'zeros(A__)' in resp
    assert 'ans =  1' in resp
    assert lines[0].startswith('load')

    # now make an object with a desired logger
    logger = oct2py.get_log('test')
    hdlr = get_handler()
    logger.addHandler(hdlr)
    logger.setLevel(logging.INFO)
    oc2 = Oct2Py(logger=logger)

     # generate some messages (logged and not logged)
    oc2.ones(1, verbose=True)

    oc2.logger.setLevel(logging.DEBUG)
    oc2.zeros(1)

    # check the output
    lines = hdlr.stream.getvalue().strip().split('\n')
    resp = '\n'.join(lines)
    assert 'zeros(A__)' in resp
    assert 'ans =  1' in resp
    assert lines[0].startswith('load')
Пример #4
0
    def test_logging(self):
        # create a stringio and a handler to log to it
        def get_handler():
            sobj = StringIO()
            hdlr = logging.StreamHandler(sobj)
            hdlr.setLevel(logging.DEBUG)
            return hdlr

        hdlr = get_handler()
        self.oc.logger.addHandler(hdlr)

        # generate some messages (logged and not logged)
        self.oc.ones(1, verbose=True)

        self.oc.logger.setLevel(logging.DEBUG)
        self.oc.zeros(1)

        # check the output
        lines = hdlr.stream.getvalue().strip().split("\n")
        resp = "\n".join(lines)
        assert 'exist("zeros")' in resp
        assert 'exist("ones")' not in resp
        assert "_pyeval(" in resp

        # now make an object with a desired logger
        logger = oct2py.get_log("test")
        hdlr = get_handler()
        logger.addHandler(hdlr)
        logger.setLevel(logging.INFO)
        with Oct2Py(logger=logger) as oc2:
            # generate some messages (logged and not logged)
            oc2.ones(1, verbose=True)
            oc2.logger.setLevel(logging.DEBUG)
            oc2.zeros(1)

        # check the output
        lines = hdlr.stream.getvalue().strip().split("\n")
        resp = "\n".join(lines)
        assert 'exist("zeros")' in resp
        assert 'exist("ones")' not in resp
        assert "_pyeval(" in resp
Пример #5
0
    def test_logging(self):
        # create a stringio and a handler to log to it
        def get_handler():
            sobj = StringIO()
            hdlr = logging.StreamHandler(sobj)
            hdlr.setLevel(logging.DEBUG)
            return hdlr
        hdlr = get_handler()
        self.oc.logger.addHandler(hdlr)

        # generate some messages (logged and not logged)
        self.oc.ones(1, verbose=True)

        self.oc.logger.setLevel(logging.DEBUG)
        self.oc.zeros(1)

        # check the output
        lines = hdlr.stream.getvalue().strip().split('\n')
        resp = '\n'.join(lines)
        assert 'exist("zeros")' in resp
        assert 'exist("ones")' not in resp
        assert '_pyeval(' in resp

        # now make an object with a desired logger
        logger = oct2py.get_log('test')
        hdlr = get_handler()
        logger.addHandler(hdlr)
        logger.setLevel(logging.INFO)
        with Oct2Py(logger=logger) as oc2:
            # generate some messages (logged and not logged)
            oc2.ones(1, verbose=True)
            oc2.logger.setLevel(logging.DEBUG)
            oc2.zeros(1)

        # check the output
        lines = hdlr.stream.getvalue().strip().split('\n')
        resp = '\n'.join(lines)
        assert 'exist("zeros")' in resp
        assert 'exist("ones")' not in resp
        assert '_pyeval(' in resp
Пример #6
0
from pilco.models import MGPR
from pilco.models.pilco import PILCO
import numpy as np
import os
from gpflow import autoflow
from gpflow import settings
import oct2py
import logging
octave = oct2py.Oct2Py(logger=oct2py.get_log())
octave.logger = oct2py.get_log('new_log')
octave.logger.setLevel(logging.INFO)
dir_path = os.path.dirname(os.path.realpath("__file__")) + "/tests/Matlab Code"
octave.addpath(dir_path)

float_type = settings.dtypes.float_type


@autoflow((float_type, [None, None]), (float_type, [None, None]),
          (np.int32, []))
def predict_wrapper(pilco, m, s, horizon):
    return pilco.predict(m, s, horizon)


@autoflow((float_type, [None, None]), (float_type, [None, None]))
def compute_action_wrapper(pilco, m, s):
    return pilco.controller.compute_action(m, s)


def test_cascade():
    np.random.seed(0)
    d = 2  # State dimenstion