Пример #1
0
 def register(self):
     '''告诉master'''
     try:
         rt = self.proxy.register_worker(self.node_info)
     except Exception,e:
         logging.warning(e)
         logging.warning('''Server is not available!\nPlease check:\n1. Server is running.\n2. Network is ok''')
         exit(1)
Пример #2
0
 def run(self):
     while True:
         try:
             time.sleep(self.heartbeat_duration)
             worker = self.worker_node.get_node_info()
             self.proxy.heartbeat(worker)
         except Exception,e:
             logging.warning(e.message)
             logging.warning(u"心跳失败")
Пример #3
0
    def finish_task(self, task, result):
        self.working = False
        if self.is_idle():
            self.node_info.status = NodeStatus.idle
        else:
            self.node_info.status = NodeStatus.working

        self.node_info.update_heartbeat()
        try:
            self.proxy.task_complete(self.node_info, result)
        except Exception,e:
            logging.warning(e)
Пример #4
0
def get_worker(port):
    ip = utils.IPGetter.get_ip_address()
    master_info = NodeInfo(name="master",ip=conf.MASTER_IP,
                           port=conf.MASTER_PORT, status=NodeStatus.working)
    node_info = NodeInfo(name="worker", ip=ip, port=port, status=NodeStatus.idle)

    if common.doesServiceExist(node_info.ip, node_info.port):
        logging.warning("%s:%s already been used! change another port" % (node_info.ip, node_info.port))
        exit(1)

    worker_node = WorkerNode(master_info, node_info)
    logging.info("%s startup" % worker_node.get_node_info())

    return worker_node
Пример #5
0
 def solve(self):
     '''
     This is just a wrapper to call the chosen algorithm for solving the
     collocation equation system.
     '''
     
     if (self.method == 'leven'):
         logging.debug("Run Levenberg-Marquardt method")
         self.leven()
     
     if (self.sol is None):
         logging.warning("Wrong solver, returning initial value.")
         return self.x0
     else:
         return self.sol
Пример #6
0
def add_keyword_path(keyword, ts_name, fp):

    if len(keyword) == 0:
        return None

    testsuite_content = ""
    #fp.write("\n")
    for key in keyword:
        key_list = key.split("|")
        path = key_list[1]
        libname = key_list[0]
        testsuite_content = testsuite_content + "Resource           " + path + "." + libname + "\n"
        #fp.write("Resource           "+path+"."+libname+"\n")
        logg.warning("Resource           " + path + "." + libname + "\n")
    fp.flush()

    return testsuite_content
Пример #7
0
    def dx(self, t):
        '''
        Returns the state of the 1st derivatives of the system variables.
        
        Parameters
        ----------
        
        t : float
            The time point in (a,b) to evaluate the 1st derivatives at.
        '''

        if not self.sys.a <= t <= self.sys.b:
            logging.warning("Time point 't' has to be in (a,b)")
            arr = None
        else:
            arr = np.array([self.dx_fnc[xx](t) for xx in self.sys.states])

        return arr
Пример #8
0
 def dx(self, t):
     '''
     Returns the state of the 1st derivatives of the system variables.
     
     Parameters
     ----------
     
     t : float
         The time point in (a,b) to evaluate the 1st derivatives at.
     '''
     
     if not self.sys.a <= t <= self.sys.b:
         logging.warning("Time point 't' has to be in (a,b)")
         arr = None
     else:
         arr = np.array([self.dx_fnc[xx](t) for xx in self.sys.states])
     
     return arr
Пример #9
0
    def x(self, t):
        '''
        Returns the current system state.
        
        Parameters
        ----------
        
        t : float
            The time point in (a,b) to evaluate the system at.
        '''

        if not self.sys.a <= t <= self.sys.b:
            logging.warning("Time point 't' has to be in (a,b)")
            arr = None
        else:
            arr = np.array([self.x_fnc[xx](t) for xx in self.sys.states])

        return arr
Пример #10
0
 def x(self, t):
     '''
     Returns the current system state.
     
     Parameters
     ----------
     
     t : float
         The time point in (a,b) to evaluate the system at.
     '''
     
     if not self.sys.a <= t <= self.sys.b:
         logging.warning("Time point 't' has to be in (a,b)")
         arr = None
     else:
         arr = np.array([self.x_fnc[xx](t) for xx in self.sys.states])
                         
     return arr
Пример #11
0
def add_library_path(library, ts_name):

    if len(library) == 0:
        logg.warning("Nothing Generation Done ")
        return None

    logg.warning("Library Generation Done ")
    fp = open("userhandler/" + ts_name + ".robot", "a")
    fp.write(
        "*** Setting ***    Value\n\n" +
        "Library           ${ProductTarget}/libs/python/lib/PublicAPI.py   scg_ip=10.110.219.42  pubapi_version=v5_0\n"
    )
    for lib in library:
        lib_list = lib.split("|")
        path = lib_list[1]
        libname = lib_list[0]
        fp.write("Library           " + path + "." + libname + "\n")

    fp.flush()
    fp.close()
Пример #12
0
    def run(self):

        rpc = RPCWorkerThread(self)
        rpc.setDaemon(True)

        heartbeat_thread = HeartbeatThread(self)
        heartbeat_thread.setDaemon(True)

        rpc.start()

        self.register()

        heartbeat_thread.start()

        while True:
            try:
                self.do_task()
            except Exception, e:
                traceback.print_exc()
                logging.warning('task failed!')
Пример #13
0
def get_worker(port):
    ip = utils.IPGetter.get_ip_address()
    master_info = NodeInfo(name="master",
                           ip=conf.MASTER_IP,
                           port=conf.MASTER_PORT,
                           status=NodeStatus.working)
    node_info = NodeInfo(name="worker",
                         ip=ip,
                         port=port,
                         status=NodeStatus.idle)

    if common.doesServiceExist(node_info.ip, node_info.port):
        logging.warning("%s:%s already been used! change another port" %
                        (node_info.ip, node_info.port))
        exit(1)

    worker_node = WorkerNode(master_info, node_info)
    logging.info("%s startup" % worker_node.get_node_info())

    return worker_node
Пример #14
0
    def run(self):

        rpc = RPCWorkerThread(self)
        rpc.setDaemon(True)

        heartbeat_thread = HeartbeatThread(self)
        heartbeat_thread.setDaemon(True)

        rpc.start()

        self.register()

        heartbeat_thread.start()

        while True:
            try:
                self.do_task()
            except Exception,e:
                traceback.print_exc()
                logging.warning('task failed!')
Пример #15
0
    def function(self):

        request_url = "tsp/continental-gateway/continental-gateway/realTimeUploadData"
        request_params = {"Content-type": "application/json"}
        request_json = ""
        try:
            with open("D:/locust/real_time_upload_data.json", "r") as f:
                request_json = json.load(f)
        except (IOError):
            logging.error("open json file fail!!!")

        try:
            response = self.client.post(url=request_url,
                                        headers=request_params,
                                        data=json.dumps(request_json))
        except (UnboundLocalError):
            logging.error("json fail")

        if response.status_code != 200:
            logging.warning("返回内容:%s" % (response.text))
            logging.warning("返回异常,请求状态码:%s" % (response.status_code))
Пример #16
0
	def getSearchBySphinx(self, q, index = '*'):
		"""
		从sphinx搜索结果

		Args:
			q 		- 搜索词
			index 	- 需要使用的索引, default: '*'

		Returns:
			Id list.
		"""
		res = self.sp.query(q, index)

		lastError = self.sp.getLastError()
		lastWarning = self.sp.getLastWarning()
		if lastError:
			logging.error('getSearchBySphinx has error: %s' % (lastError))
		if lastWarning:
			logging.warning('getSearchBySphinx has warning: %s' % (lastWarning))
		
		return res
Пример #17
0
def generatefile(request):
    context = {}
    logg.warning("Editor %s" % request.POST.get('tc'))
    workspace_name=request.session["workspace"]
    testsuitename=request.session["testsuite"]
    ws_list = workspace.objects.filter(name=workspace_name)
    ts_list = testsuite.objects.filter(testsuitename=testsuitename)
    ws_name = ws_list.values()[0]["name"]
    ws_path = ws_list.values()[0]["path"]
    ws_ip = ws_list.values()[0]["ip"]
    ws_uname = ws_list.values()[0]["uname"]
    ws_passwd = ws_list.values()[0]["passwd"]
    ts_name = ts_list.values()[0]["testsuitename"]
    library = ts_list.values()[0]["library"]
    keyword = ts_list.values()[0]["keyword"]
    variable = ts_list.values()[0]["variable"]
    logg.warning("************* Editor %s" % ts_list.values())
    fil = gen.generate_test_suite_file(teststeps=request.POST.get('tc'),
            ws_name=ws_name,ws_ip=ws_ip,ws_uname=ws_uname,ws_passwd=ws_passwd,
            ts_name=ts_name,library=[library],keyword=[keyword],variable=[variable])

    logg.warning("************* Editor %s" % fil)

    _ws = wks.workspace(ip=ws_ip,uname=ws_uname,passwd=ws_passwd,path=ws_path)
    _ws.copy_testuite_lib_files(ws_ip=ws_ip,ws_uname=ws_uname,
            ws_passwd=ws_passwd,path=ws_path,testsuite_name=ts_name)

    context.update({'object':fil,'status':"success"})
    return JsonResponse(context)
Пример #18
0
def generate_test_suite_file(teststeps, ws_name, ws_ip, ws_uname, ws_passwd,
                             ts_name, library, keyword, variable):
    make_new_template(ts_name)
    fp = open("userhandler/" + ts_name + ".robot", "a")
    add_library_path(library, ts_name, fp)
    #add_keyword_path(keyword,ts_name)

    ln_testcase = teststeps.split("\n")
    if ln_testcase[-1] != "":
        ln_testcase.append("")
    test_steps = []
    new_testcase = []
    for teststep in ln_testcase:
        logg.warning("testcase %s" % teststep)
        if teststep == "":
            test_steps.append(new_testcase)
            logg.warning("test_steps %s" % test_steps)
            new_testcase = []
        else:
            new_testcase.append(teststep)

    if len(test_steps) == 0:
        test_steps.append(new_testcase)

    logg.warning("Derived %s" % test_steps)
    tc_no = 0

    logg.warning("userhandler/" + ts_name + ".robot")
    fp.write("*** Test Case ***\n")
    fp.flush()
    fp.close()

    for testcase in test_steps:
        tsteps = verify_step_params(testcase)
        final_steps = replace_id_for_name(tsteps)
        tc_no = tc_no + 1
        write_testcase(final_steps, tc_no, ts_name)

    logg.warning("Generation Done ")
    return True
Пример #19
0
def pingtest(interval: float,
             batchnum: int,
             timeout: float,
             proto: str,
             addr: str,
             family=None):
    # seq 可能重复?
    try:
        if proto == 'icmp':

            def func(addr):
                return icmpping(addr, random.randint(0, 65535), timeout,
                                family)
        elif proto == 'tcp':

            def func(addr):
                return tcpping(addr, timeout, family)

        res = []
        for _ in range(0, batchnum):
            delay = func(addr)
            if delay > 0:
                res.append(delay)
            time.sleep(interval)

        resnum = len(res)

        if resnum == 0:
            return (0, 0, 0, 0)

        ressum = sum(res)
        resavg = ressum / resnum
        resmax = max(res)
        resmin = min(res)
        res_stddev = (sum([(x - resavg)**2 for x in res]) / resnum)**0.5

        return (resmin, resavg, resmax, res_stddev)
    except BaseException as e:
        logging.warning(e)
        return (0, 0, 0, 0)
Пример #20
0
def replace_id_for_name(teststeps):
    tsteps = []
    for steps in teststeps:
        st_steps = steps.split("  ")
        s_steps = copy.deepcopy(st_steps)
        insert_get_id = False
        for var in st_steps:
            logg.warning("STEPS %s" % var)
            if re.match("\s*\S*id=", var, re.I):
                ln_var = var.strip().split("=")
                logg.warning("ID STEP %s" % var)
                if len(ln_var) == 2 and ln_var[0] != "ssid":
                    name = ln_var[1]
                    s_steps.remove(var)
                    s_steps.append(ln_var[0] + "=${" + name + "_id}")
                    insert_get_id = True

        if insert_get_id is True:
            tsteps.append("${" + name +
                          "_id}=  get_id_from_name  name=%s" % name)

        tsteps.append("  ".join(s_steps))
        logg.warning("steps %s" % tsteps)

    return tsteps
Пример #21
0
    def getSearchBySphinx(self, q, index='*'):
        """
		从sphinx搜索结果

		Args:
			q 		- 搜索词
			index 	- 需要使用的索引, default: '*'

		Returns:
			Id list.
		"""
        res = self.sp.query(q, index)

        lastError = self.sp.getLastError()
        lastWarning = self.sp.getLastWarning()
        if lastError:
            logging.error('getSearchBySphinx has error: %s' % (lastError))
        if lastWarning:
            logging.warning('getSearchBySphinx has warning: %s' %
                            (lastWarning))

        return res
Пример #22
0
def collocation_nodes(a, b, npts, coll_type):
    """
    Create collocation points/nodes for the equation system.

    Parameters
    ----------

    a : float
        The left border of the considered interval.

    b : float
        The right border of the considered interval.

    npts : int
        The number of nodes.

    coll_type : str
        Specifies how to generate the nodes.

    Returns
    -------

    numpy.ndarray
        The collocation nodes.
    """

    if coll_type == 'equidistant':
        # get equidistant collocation points
        cpts = np.linspace(a, b, npts, endpoint=True)
    elif coll_type == 'chebychev':
        cpts = aux.calc_chebyshev_nodes(a, b, npts)
    else:
        logging.warning('Unknown type of collocation points.')
        logging.warning('--> will use equidistant points!')
        cpts = np.linspace(a, b, npts, endpoint=True)

    return cpts
Пример #23
0
def write_testcase(tsteps, tc_id, ts_name, fp):
    logg.warning("test case %s" % tsteps)
    testcase_content = "\nTest Case %s\n" % tc_id
    #fp.write("\nTest Case %s\n" % tc_id)
    for step in tsteps:
        logg.warning("test case %s" % step)
        testcase_content = testcase_content + "    " + step + "\n"
        #fp.write("\t" + step + "\n")
        logg.warning("    " + step + "\n")

    return testcase_content
Пример #24
0
def add_library_path(library, ts_name, fp):

    if len(library) == 0:
        logg.warning("Nothing Generation Done ")
        return None

    testsuite_content = ""
    logg.warning("Library Generation Done ")
    testsuite_content = testsuite_content + "*** Setting ***    \n\n" + "Library           ${ProjectTarget}/libs/python/lib/PublicAPI.py   scg_ip=10.110.219.42  pubapi_version=v5_0\n"
    #fp.write("*** Setting ***    Value\n\n" + "Library           ${ProductTarget}/libs/python/lib/PublicAPI.py   scg_ip=10.110.219.42  pubapi_version=v5_0\n")
    for lib in library:
        lib_list = lib.split("|")
        path = lib_list[1]
        libname = lib_list[0]
        testsuite_content = testsuite_content + "Library           " + path + "." + libname + "\n"
        #fp.write("Library           "+path+"."+libname+"\n")
        logg.warning("Library           " + path + "." + libname + "\n")

    fp.flush()
    return testsuite_content
Пример #25
0
    if result == 0:
        return True
    os.system('ps -ef | grep "./neo-cli" | awk \'{print $2}\' | xargs kill')
    return True


def restartRecently():
    if timedelta(minutes=START_SILENT) < datetime.now() - lastRestartTimestamp:
        return True
    return False


while True:
    if not isLocalRunning():
        startLocalNode()
        continue
    time.sleep(INTERVAL)
    localBlockCount = getLocalBlockCount()
    bestBlockCount = getBestBlockCount()
    if localBlockCount < 0 or bestBlockCount < 0:
        logging.error(
            '[wrongheight] wrong height, localheight: {0}, bestheight: {1}'.
            format(localBlockCount, bestBlockCount))
        continue
    if RESTART_THRESHOLD < bestBlockCount - localBlockCount and not restartRecently(
    ):
        restart_cnt += 1
        logging.warning(
            '[restart] restarting, restart_cnt: {0}, localheight: {1}, bestheight: {2}'
            .format(restart_cnt, localBlockCount, bestBlockOount))
        stopLocalNode()
Пример #26
0
def make_steady(S):
    '''
    This method sets up and solves equations that satisfy boundary conditions and
    ensure steadiness and smoothness conditions of the spline `S` in every joining point.
    
    Please see the documentation for more details: :ref:`candidate_functions`
    
    Parameters
    ----------
    
    S : Spline
        The spline function object for which to solve smoothness and boundary conditions.
    '''

    # This should be yet untouched
    if S._steady_flag:
        logging.warning('Spline already has been made steady.')
        return

    # get spline coefficients and interval size
    coeffs = S._coeffs
    h = S._h

    # nu represents degree of boundary conditions
    nu = -1
    for k, v in S._boundary_values.items():
        if all(item is not None for item in v):
            nu += 1

    # now we determine the free parameters of the spline function
    if nu == -1:
        a = np.hstack([coeffs[:, 0], coeffs[0, 1:]])
    elif nu == 0:
        a = np.hstack([coeffs[:, 0], coeffs[0, 2]])
    elif nu == 1:
        a = coeffs[:-1, 0]
    elif nu == 2:
        a = coeffs[:-3, 0]

    # `b` is, what is not in `a`
    coeffs_set = set(coeffs.ravel())
    a_set = set(a)
    b_set = coeffs_set - a_set

    # transfer b_set to ordered list
    b = sorted(list(b_set), key=lambda c: c.name)
    #b = np.array(sorted(list(b_set), key = lambda c: c.name))

    # now we build the matrix for the equation system
    # that ensures the smoothness conditions

    # get matrix dimensions --> (3.21) & (3.22)
    N1 = 3 * (S.n - 1) + 2 * (nu + 1)
    N2 = 4 * S.n

    # get matrix and right hand site of the equation system
    # that ensures smoothness and compliance with the boundary values
    M, r = get_smoothness_matrix(S, N1, N2)

    # get A and B matrix such that
    #
    #       M*c = r
    # A*a + B*b = r
    #         b = B^(-1)*(r-A*a)
    #
    # we need B^(-1)*r [absolute part -> tmp1] and B^(-1)*A [coefficients of a -> tmp2]

    #a_mat = np.zeros((N2,N2-N1))
    #b_mat = np.zeros((N2,N1))
    a_mat = sparse.lil_matrix((N2, N2 - N1))
    b_mat = sparse.lil_matrix((N2, N1))

    for i, aa in enumerate(a):
        tmp = aa.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])
        a_mat[4 * j + k, i] = 1

    for i, bb in enumerate(b):
        tmp = bb.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])
        b_mat[4 * j + k, i] = 1

    M = sparse.csr_matrix(M)
    a_mat = sparse.csr_matrix(a_mat)
    b_mat = sparse.csr_matrix(b_mat)

    A = M.dot(a_mat)
    B = M.dot(b_mat)

    # do the inversion
    A = sparse.csc_matrix(A)
    B = sparse.csc_matrix(B)
    r = sparse.csc_matrix(r)

    tmp1 = spsolve(B, r)
    tmp2 = spsolve(B, -A)

    if sparse.issparse(tmp1):
        tmp1 = tmp1.toarray()
    if sparse.issparse(tmp2):
        tmp2 = tmp2.toarray()

    dep_array = np.zeros((coeffs.shape[0], coeffs.shape[1], a.size))
    dep_array_abs = np.zeros_like(coeffs, dtype=float)

    for i, bb in enumerate(b):
        tmp = bb.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])

        dep_array[j, k, :] = tmp2[i]
        dep_array_abs[j, k] = tmp1[i]

    tmp3 = np.eye(len(a))
    for i, aa in enumerate(a):
        tmp = aa.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])

        dep_array[j, k, :] = tmp3[i]

    S._dep_array = dep_array
    S._dep_array_abs = dep_array_abs

    # a is vector of independent spline coeffs (free parameters)
    S._indep_coeffs = a

    # now we are done and this can be set to True
    S._steady_flag = True
Пример #27
0
def savestep(request):
    context = {}
    logg.warning("Editor %s" % request.POST.get('tstep'))
    context.update({'object':"success",'status':"success"})
    return JsonResponse(context)
Пример #28
0
from log import logging

# current version
__version__ = '1.2.0'

# Placeholder for the datetime string of latest commit
__date__ = "2016-01-15 14:12:08"

# `__date__` contains the date and time of the latest commit
# (will be altered with every commit using git's pre-commit hook)

# check versions of dependencies
import numpy
import scipy
import sympy

np_info = numpy.__version__.split('.')
scp_info = scipy.__version__.split('.')
sp_info = sympy.__version__.split('.')

if not (int(np_info[0]) >= 1 and int(np_info[1]) >= 8):
    logging.warning('numpy version ({}) may be out of date'.format(numpy.__version__))
if not (int(scp_info[0]) >= 0 and int(scp_info[1]) >= 13 and int(scp_info[2][0]) >= 0):
    logging.warning('scipy version ({}) may be out of date'.format(scipy.__version__))
if not (int(sp_info[0]) >= 0 and int(sp_info[1]) >= 7 and int(sp_info[2][0]) >= 5):
    logging.warning('sympy version ({}) may be out of date'.format(sympy.__version__))

# log information about current version
logging.debug('This is PyTrajectory version {} of {}'.format(__version__, __date__))

Пример #29
0
def make_steady(S):
    '''
    This method sets up and solves equations that satisfy boundary conditions and
    ensure steadiness and smoothness conditions of the spline `S` in every joining point.
    
    Please see the documentation for more details: :ref:`candidate_functions`
    
    Parameters
    ----------
    
    S : Spline
        The spline function object for which to solve smoothness and boundary conditions.
    '''
    
    # This should be yet untouched
    if S._steady_flag:
        logging.warning('Spline already has been made steady.')
        return
    
    # get spline coefficients and interval size
    coeffs = S._coeffs
    h = S._h

    # nu represents degree of boundary conditions
    nu = -1
    for k, v in S._boundary_values.items():
        if all(item is not None for item in v):
            nu += 1
    
    # now we determine the free parameters of the spline function
    if nu == -1:
        a = np.hstack([coeffs[:,0], coeffs[0,1:]])
    elif nu == 0:
        a = np.hstack([coeffs[:,0], coeffs[0,2]])
    elif nu == 1:
        a = coeffs[:-1,0]
    elif nu == 2:
        a = coeffs[:-3,0]
    
    # `b` is, what is not in `a`
    coeffs_set = set(coeffs.ravel())
    a_set = set(a)
    b_set = coeffs_set - a_set
    
    # transfer b_set to ordered list
    b = sorted(list(b_set), key = lambda c: c.name)
    #b = np.array(sorted(list(b_set), key = lambda c: c.name))
    
    # now we build the matrix for the equation system
    # that ensures the smoothness conditions
    
    # get matrix dimensions --> (3.21) & (3.22)
    N1 = 3 * (S.n - 1) + 2 * (nu + 1)
    N2 = 4 * S.n
    
    # get matrix and right hand site of the equation system
    # that ensures smoothness and compliance with the boundary values
    M, r = get_smoothness_matrix(S, N1, N2)
    
    # get A and B matrix such that
    #
    #       M*c = r
    # A*a + B*b = r
    #         b = B^(-1)*(r-A*a)
    #
    # we need B^(-1)*r [absolute part -> tmp1] and B^(-1)*A [coefficients of a -> tmp2]

    #a_mat = np.zeros((N2,N2-N1))
    #b_mat = np.zeros((N2,N1))
    a_mat = sparse.lil_matrix((N2,N2-N1))
    b_mat = sparse.lil_matrix((N2,N1))
    
    for i,aa in enumerate(a):
        tmp = aa.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])
        a_mat[4*j+k,i] = 1

    for i,bb in enumerate(b):
        tmp = bb.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])
        b_mat[4*j+k,i] = 1
    
    M = sparse.csr_matrix(M)
    a_mat = sparse.csr_matrix(a_mat)
    b_mat = sparse.csr_matrix(b_mat)
    
    A = M.dot(a_mat)
    B = M.dot(b_mat)
    
    # do the inversion
    A = sparse.csc_matrix(A)
    B = sparse.csc_matrix(B)
    r = sparse.csc_matrix(r)
    
    tmp1 = spsolve(B,r)
    tmp2 = spsolve(B,-A)
    
    if sparse.issparse(tmp1):
        tmp1 = tmp1.toarray()
    if sparse.issparse(tmp2):
        tmp2 = tmp2.toarray()
    
    dep_array = np.zeros((coeffs.shape[0], coeffs.shape[1], a.size))
    dep_array_abs = np.zeros_like(coeffs, dtype=float)
    
    for i,bb in enumerate(b):
        tmp = bb.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])

        dep_array[j,k,:] = tmp2[i]
        dep_array_abs[j,k] = tmp1[i]

    tmp3 = np.eye(len(a))
    for i,aa in enumerate(a):
        tmp = aa.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])

        dep_array[j,k,:] = tmp3[i]
    
    S._dep_array = dep_array
    S._dep_array_abs = dep_array_abs
    
    # a is vector of independent spline coeffs (free parameters)
    S._indep_coeffs = a
    
    # now we are done and this can be set to True
    S._steady_flag = True
Пример #30
0
# Placeholder for the datetime string of latest commit
__date__ = "2016-01-15 14:12:08"

# `__date__` contains the date and time of the latest commit
# (will be altered with every commit using git's pre-commit hook)

# check versions of dependencies
import numpy
import scipy
import sympy

np_info = numpy.__version__.split('.')
scp_info = scipy.__version__.split('.')
sp_info = sympy.__version__.split('.')

if not (int(np_info[0]) >= 1 and int(np_info[1]) >= 8):
    logging.warning('numpy version ({}) may be out of date'.format(
        numpy.__version__))
if not (int(scp_info[0]) >= 0 and int(scp_info[1]) >= 13
        and int(scp_info[2][0]) >= 0):
    logging.warning('scipy version ({}) may be out of date'.format(
        scipy.__version__))
if not (int(sp_info[0]) >= 0 and int(sp_info[1]) >= 7
        and int(sp_info[2][0]) >= 5):
    logging.warning('sympy version ({}) may be out of date'.format(
        sympy.__version__))

# log information about current version
logging.debug('This is PyTrajectory version {} of {}'.format(
    __version__, __date__))
Пример #31
0
def shutdownScreen():
    result = os.system('./shell/shutdownScreen.sh')
    logging.warning('[{0}] shutdown.res:{1}'.format(type, result))
    if result == 0:
        return True
    return False
Пример #32
0
def make_steady(S):
    """
    This method sets up and solves equations that satisfy boundary conditions and
    ensure steadiness and smoothness conditions of the spline `S` in every joining point.

    Please see the documentation for more details: :ref:`candidate_functions`

    Parameters
    ----------

    S : Spline
        The spline function object for which to solve smoothness and boundary conditions.
    """

    # This should be yet untouched
    if S._steady_flag:
        logging.warning('Spline already has been made steady.')
        return

    # get spline coefficients and interval size
    coeffs = S._coeffs  ##:: =self._coeffs=array([[cxi_0_0,...,cxi_0_3],...,[cxi_9_0,...,cxi_9_3]])
    h = S._h  # TODO: do we need this?

    # nu represents degree of boundary conditions
    nu = -1  ##:: equations about boundary conditions at the begin and end of the spline
    for k, v in S._boundary_values.items():
        if all(item is not None for item in v):  ##:: Note: 0 != None.
            nu += 1

    # now we determine the free parameters of the spline function

    # (**) Background information: The algorithm has some degrees of freedom at this point,
    # that is the choice which of the coefficients are chosen as free parameters.
    # we tried to use mainly 0th order and some of first order but got worse convergence
    # behavior than in the case of mainly third order

    # coeffs is a matrix with shape (S.n, 4), i.e., each row represents one cubic polynomial
    # (4 parameters), each row represents one order of coefficients

    if nu == -1:
        # no boundary values at all
        # we need n + 3 free parameters

        # mainly 3rd order and all (additional) coeffs of the first spline
        a = np.hstack((coeffs[:, -1], coeffs[0, :-1]))

    elif nu == 0:
        # this is the most relevant case
        # bc for the function value itself
        # we need n + 1 free parameters

        a = np.hstack((coeffs[:, -1], coeffs[0, 1]))

    elif nu == 1:
        # bc for the function value itself and 1st derivative
        # we need n - 1 free parameters

        a = coeffs[:-1, -1]  # last coeffs
    elif nu == 2:
        # bc for the function value itself, 1st and 2nd derivative
        # we need n - 3 free parameters
        a = coeffs[:-3, -1]

    # `b` is, what is not in `a`
    coeffs_set = set(coeffs.ravel())  ##:: ravel: bian ping hua
    a_set = set(a)
    assert len(a_set) == len(a)

    b_set = coeffs_set - a_set  ##:: bu ji
    # ensure lexical sorting
    a = np.array(sorted(a, key=lambda cc: cc.name))
    b = sorted(list(b_set), key=lambda cc: cc.name)  ##:: type(b) = list
    # just for debugging
    c = sorted(list(coeffs_set), key=lambda cc: cc.name)

    # now we build the matrix for the equation system
    # that ensures the smoothness conditions

    # get matrix and right hand site of the equation system
    # that ensures smoothness and compliance with the boundary values
    M, r = get_smoothness_matrix(S, nu)  ##:: see the docs:
    N1, N2 = M.shape
    # http://pytrajectory.readthedocs.io/en/master/guide/background.html#candidate-functions

    # get A and B matrix such that
    #
    #       M*c = r
    # A*a + B*b = r
    #         b = B^(-1)*(r-A*a)
    #
    # we need B^(-1)*r [absolute part -> tmp1] and B^(-1)*A [coefficients of a -> tmp2, because of (B^(-1)*A*a)]

    # a_mat = sparse.lil_matrix((N2,N2-N1)) # size(a_mat)=(40,11)
    # b_mat = sparse.lil_matrix((N2,N1)) # size(b_mat)=(40,29)

    # matrices to select the relevant columns from M, i.e. A, B corresponding to a, b
    a_select = sparse.lil_matrix((N2, N2 - N1))
    b_mat = sparse.lil_matrix((N2, N1))

    # coeff names are like cx1_<i>_<k>  i: piece number, k: order
    for i, aa in enumerate(a):
        tmp = aa.name.split('_')[
            -2:]  # aa= cx1_0_0, aa.name='cx1_0_0', tmp=['0','0']
        j = int(tmp[0])
        k = int(tmp[1])
        a_select[4 * j + k, i] = 1

    for i, bb in enumerate(b):
        tmp = bb.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])
        b_mat[4 * j + k, i] = 1

    M = sparse.csr_matrix(M)
    a_select = sparse.csr_matrix(a_select)
    b_mat = sparse.csr_matrix(b_mat)

    A = M.dot(a_select)
    B = M.dot(b_mat)

    # do the inversion
    A = sparse.csc_matrix(A)
    B = sparse.csc_matrix(B)
    r = sparse.csc_matrix(r)

    tmp1 = spsolve(B, r)
    tmp2 = spsolve(B, -A)

    if sparse.issparse(tmp1):
        tmp1 = tmp1.toarray()
    if sparse.issparse(tmp2):
        tmp2 = tmp2.toarray()

    dep_array = np.zeros((coeffs.shape[0], coeffs.shape[1], a.size))
    dep_array_abs = np.zeros_like(coeffs, dtype=float)

    for i, bb in enumerate(b):
        tmp = bb.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])

        dep_array[j, k, :] = tmp2[i]
        dep_array_abs[j, k] = tmp1[i]

    tmp3 = np.eye(len(a))
    for i, aa in enumerate(a):
        tmp = aa.name.split('_')[-2:]
        j = int(tmp[0])
        k = int(tmp[1])

        dep_array[j, k, :] = tmp3[i]

    S._dep_array = dep_array
    S._dep_array_abs = dep_array_abs

    # a is vector of independent spline coeffs (free parameters)
    S._indep_coeffs = a

    # now we are done and this can be set to True
    S._steady_flag = True
Пример #33
0
    return False
	
while True:
    if not isLocalRunning():
        if not shutdownScreen():
            continue;
        startLocalNode()

    time.sleep(INTERVAL)
    #get rss
    mem = state.getRss()
    if 0 < mem:
        logging.info('[{0}] getrss rss: {1}KiB'.format(type, mem))
    #check block count
    localBlockCount = getLocalBlockCount()
    bestBlockCount = getBestBlockCount()
    if localBlockCount < 0 or bestBlockCount < 0:
        logging.error('[{0}] wrong height, localheight: {1}, bestheight: {2}'.format(type, localBlockCount, bestBlockCount))
        continue
	if localBlockCount > lastRecordLocalIndex:
		lastRecordLocalIndex = localBlockCount
		lastRecordLocalTime = datetime.now()
	if localBlockCount == lastRecordLocalIndex and notChangeOverLimit():
        restart_cnt += 1
        logging.warning('[{0}] restarting, restart_cnt: {1}, localheight: {2}, bestheight: {3}'.format(type, restart_cnt, localBlockCount, bestBlockCount))
        stopLocalNode()
        continue
    if RESTART_THRESHOLD < bestBlockCount - localBlockCount and not restartRecently():
        restart_cnt += 1
        logging.warning('[{0}] restarting, restart_cnt: {1}, localheight: {2}, bestheight: {3}'.format(type, restart_cnt, localBlockCount, bestBlockCount))
        stopLocalNode()