Ejemplo n.º 1
0
def execHirecsNounwrap(execpool, netfile, asym, timeout, pathid=''):
    """Hirecs which performs the clustering, but does not unwrappes the hierarchy into levels,
	just outputs the folded hierarchy"""
    assert execpool and netfile and (
        asym is None or isinstance(asym, bool)
    ) and timeout + 0 >= 0, (
        'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
        .format(execpool, netfile, asym, timeout))
    # Fetch the task name and chose correct network filename
    netfile = os.path.splitext(netfile)[0]  # Remove the extension
    task = os.path.split(netfile)[1]  # Base name of the network
    assert task, 'The network name should exists'
    netfile += '.hig'  # Use network in the required format
    algname = funcToAppName(
        inspect.currentframe().f_code.co_name)  # Or 'hirecshfold'
    taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

    preparePath(taskpath)

    args = ('../exectime', ''.join(
        ('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(
            ('-n=', task, pathid)), '-s=/etime_' + algname, './hirecs', '-oc',
            '../' + netfile)
    execpool.execute(
        Job(name=_SEPNAMEPART.join((algname, task)),
            workdir=_ALGSDIR,
            args=args,
            timeout=timeout,
            stdout=''.join((taskpath, '.hoc')),
            stderr=taskpath + _EXTLOG))
    return 1
Ejemplo n.º 2
0
def execRandcommuns(execpool, netfile, asym, timeout, pathid='', instances=5):  # _netshuffles + 1
	"""Execute Randcommuns, Random Disjoint Clustering
	Results are not stable => multiple execution is desirable.

	instances  - number of networks instances to be generated
	"""
	assert execpool and netfile and (asym is None or isinstance(asym, bool)) and timeout + 0 >= 0, (
		'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
		.format(execpool, netfile, asym, timeout))
	# Fetch the task name and chose correct network filename
	netfile, netext = os.path.splitext(netfile)  # Remove the extension
	task = os.path.split(netfile)[1]  # Base name of the network
	assert task, 'The network name should exists'
	algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'randcommuns'
	# Backup previous results if exist
	taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

	preparePath(taskpath)

	# ./randcommuns.py -g=../syntnets/1K5.cnl -i=../syntnets/1K5.nsa -n=10
	args = ('../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(('-n=', task, pathid)), '-s=/etime_' + algname
		# Note: igraph-python is a Cython wrapper around C igraph lib. Calls are much faster on CPython than on PyPy
		, 'python', ''.join(('./', algname, '.py')), ''.join(('-g=../', os.path.splitext(netfile)[0], _EXTCLNODES))
		, ''.join(('-i=../', netfile, netext)), ''.join(('-o=../', taskpath))
		, ''.join(('-n=', str(instances))))
	execpool.execute(Job(name=_SEPNAMEPART.join((algname, task)), workdir=_ALGSDIR, args=args, timeout=timeout
		, stdout=os.devnull, stderr=taskpath + _EXTLOG))
	return 1
Ejemplo n.º 3
0
def execHirecs(execpool, netfile, asym, timeout, pathid=''):
    assert execpool and netfile and (
        asym is None or isinstance(asym, bool)
    ) and timeout + 0 >= 0, (
        'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
        .format(execpool, netfile, asym, timeout))
    # Fetch the task name and chose correct network filename
    netfile = os.path.splitext(netfile)[0]  # Remove the extension
    task = os.path.split(netfile)[1]  # Base name of the network
    assert task, 'The network name should exists'
    netfile += '.hig'  # Use network in the required format
    algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'hirecs'
    taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

    preparePath(taskpath)

    args = ('../exectime', ''.join(
        ('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(
            ('-n=', task, pathid)), '-s=/etime_' + algname, './hirecs', '-oc',
            ''.join(('-cls=../', taskpath, '/', task, '_', algname,
                     _EXTCLNODES)), '../' + netfile)
    execpool.execute(
        Job(name=_SEPNAMEPART.join((algname, task)),
            workdir=_ALGSDIR,
            args=args,
            timeout=timeout,
            stdout=os.devnull,
            stderr=taskpath + _EXTLOG))
    return 1
Ejemplo n.º 4
0
def execGanxis(execpool, netfile, asym, timeout, pathid=''):
	#print('> exec params:\n\texecpool: {}\n\tnetfile: {}\n\tasym: {}\n\ttimeout: {}'
	#	.format(execpool, netfile, asym, timeout))
	assert execpool and netfile and (asym is None or isinstance(asym, bool)) and timeout + 0 >= 0, (
		'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
		.format(execpool, netfile, asym, timeout))
	# Fetch the task name
	task = os.path.splitext(os.path.split(netfile)[1])[0]  # Base name of the network
	assert task, 'The network name should exists'

	algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'ganxis'
	taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))
	args = ['../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(('-n=', task, pathid)), '-s=/etime_' + algname
		, 'java', '-jar', './GANXiSw.jar', '-i', '../' + netfile, '-d', '../' + taskpath]
	if not asym:
		args.append('-Sym 1')  # Check existance of the back links and generate them if requried

	preparePath(taskpath)

	def tidy(job):
		# Note: GANXiS leaves empty ./output dir in the _ALGSDIR, which should be deleted
		tmp = _ALGSDIR + 'output/'
		if os.path.exists(tmp):
			#os.rmdir(tmp)
			shutil.rmtree(tmp)

	execpool.execute(Job(name=_SEPNAMEPART.join((algname, task)), workdir=_ALGSDIR, args=args, timeout=timeout, ondone=tidy
		, stdout=taskpath + _EXTLOG, stderr=taskpath + _EXTERR))
	return 1
Ejemplo n.º 5
0
def execOslom2(execpool, netfile, asym, timeout, pathid=''):
    assert execpool and netfile and (
        asym is None or isinstance(asym, bool)
    ) and timeout + 0 >= 0, (
        'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
        .format(execpool, netfile, asym, timeout))
    # Fetch the task name
    task = os.path.split(netfile)[1]  # Base name of the network
    task, netext = os.path.splitext(task)
    assert task, 'The network name should exists'

    algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'oslom2'
    taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))
    # Note: wighted networks (-w) stands for the used null model, not for the input file format.
    # Link weight is set to 1 if not specified in the file for weighted network.
    args = ('../exectime', ''.join(
        ('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(
            ('-n=', task, pathid)), '-s=/etime_' + algname,
            './oslom_undir' if not asym else './oslom_dir', '-f',
            '../' + netfile, '-w')

    preparePath(taskpath)

    netdir = os.path.split(netfile)[0] + '/'

    # Copy results to the required dir on postprocessing
    def postexec(job):
        # Copy communities output from original location to the target one
        origResDir = ''.join((netdir, task, netext, '_oslo_files/'))
        for fname in glob.iglob(escapePathWildcards(origResDir) + 'tp*'):
            shutil.copy2(fname, taskpath)

        # Move whole dir as extra task output to the logsdir
        outpdire = taskpath + '/extra/'
        if not os.path.exists(outpdire):
            os.mkdir(outpdire)
        else:
            # If dest dir already exists, remove it to avoid exception on rename
            shutil.rmtree(outpdire)
        os.rename(origResDir, outpdire)

        # Note: oslom2 leaves ./tp file in the _ALGSDIR, which should be deleted
        fname = _ALGSDIR + 'tp'
        if os.path.exists(fname):
            os.remove(fname)

    execpool.execute(
        Job(name=_SEPNAMEPART.join((algname, task)),
            workdir=_ALGSDIR,
            args=args,
            timeout=timeout,
            ondone=postexec,
            stdout=taskpath + _EXTLOG,
            stderr=taskpath + _EXTERR))
    return 1
Ejemplo n.º 6
0
def execScp(execpool, netfile, asym, timeout, pathid=''):
    assert execpool and netfile and (
        asym is None or isinstance(asym, bool)
    ) and timeout + 0 >= 0, (
        'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
        .format(execpool, netfile, asym, timeout))
    # Fetch the task name
    task, netext = os.path.splitext(netfile)
    task = os.path.split(task)[1]  # Base name of the network
    assert task, 'The network name should exists'

    algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'scp'
    kmin = 3  # Min clique size to be used for the communities identificaiton
    kmax = 8  # Max clique size (~ min node degree to be considered)
    # Run for range of clique sizes
    for k in range(kmin, kmax + 1):
        kstr = str(k)
        kstrex = 'k' + kstr
        # Embed params into the task name
        taskbasex, taskshuf = os.path.splitext(task)
        ktask = ''.join((taskbasex, _SEPPARS, kstrex, taskshuf))
        # Backup previous results if exist
        taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, ktask, pathid))

        preparePath(taskpath)

        # ATTENTION: a single argument is k-clique size, specified later
        steps = '10'  # Use 10 levels in the hierarchy Ganxis
        resbase = ''.join(
            ('../', taskpath, '/', ktask))  # Base name of the result
        # scp.py netname k [start_linksnum end__linksnum numberofevaluations] [weight]
        args = ('../exectime', ''.join(
            ('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(
                ('-n=', ktask, pathid)), '-s=/etime_' + algname, PYEXEC,
                ''.join(('./', algname, '.py')), '../' + netfile, kstr, steps,
                resbase + _EXTCLNODES)

        def tidy(job):
            """Remove empty resulting folders"""
            # Note: GANXiS leaves empty ./output dir in the _ALGSDIR, which should be deleted
            path = os.path.split(job.args[-1])[0][3:]  # Skip '../' prefix
            if os.path.exists(path) and dirempty(path):
                os.rmdir(path)

        #print('> Starting job {} with args: {}'.format('_'.join((ktask, algname, kstrex)), args + [kstr]))
        execpool.execute(
            Job(name=_SEPNAMEPART.join((algname, ktask)),
                workdir=_ALGSDIR,
                args=args,
                timeout=timeout,
                ondone=tidy,
                stderr=taskpath + _EXTLOG))

    return kmax + 1 - kmin
Ejemplo n.º 7
0
def execRandcommuns(execpool,
                    netfile,
                    asym,
                    timeout,
                    pathid='',
                    instances=5):  # _netshuffles + 1
    """Execute Randcommuns, Random Disjoint Clustering
	Results are not stable => multiple execution is desirable.

	instances  - number of networks instances to be generated
	"""
    assert execpool and netfile and (
        asym is None or isinstance(asym, bool)
    ) and timeout + 0 >= 0, (
        'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
        .format(execpool, netfile, asym, timeout))
    # Fetch the task name and chose correct network filename
    netfile, netext = os.path.splitext(netfile)  # Remove the extension
    task = os.path.split(netfile)[1]  # Base name of the network
    assert task, 'The network name should exists'
    algname = funcToAppName(
        inspect.currentframe().f_code.co_name)  # 'randcommuns'
    # Backup previous results if exist
    taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

    preparePath(taskpath)

    # ./randcommuns.py -g=../syntnets/1K5.cnl -i=../syntnets/1K5.nsa -n=10
    args = (
        '../exectime',
        ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)),
        ''.join(('-n=', task, pathid)),
        '-s=/etime_' + algname
        # Note: igraph-python is a Cython wrapper around C igraph lib. Calls are much faster on CPython than on PyPy
        ,
        'python',
        ''.join(('./', algname, '.py')),
        ''.join(('-g=../', os.path.splitext(netfile)[0], _EXTCLNODES)),
        ''.join(('-i=../', netfile, netext)),
        ''.join(('-o=../', taskpath)),
        ''.join(('-n=', str(instances))))
    execpool.execute(
        Job(name=_SEPNAMEPART.join((algname, task)),
            workdir=_ALGSDIR,
            args=args,
            timeout=timeout,
            stdout=os.devnull,
            stderr=taskpath + _EXTLOG))
    return 1
Ejemplo n.º 8
0
def execGanxis(execpool, netfile, asym, timeout, pathid=''):
    #print('> exec params:\n\texecpool: {}\n\tnetfile: {}\n\tasym: {}\n\ttimeout: {}'
    #	.format(execpool, netfile, asym, timeout))
    assert execpool and netfile and (
        asym is None or isinstance(asym, bool)
    ) and timeout + 0 >= 0, (
        'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
        .format(execpool, netfile, asym, timeout))
    # Fetch the task name
    task = os.path.splitext(
        os.path.split(netfile)[1])[0]  # Base name of the network
    assert task, 'The network name should exists'

    algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'ganxis'
    taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))
    args = [
        '../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)),
        ''.join(('-n=', task, pathid)), '-s=/etime_' + algname, 'java', '-jar',
        './GANXiSw.jar', '-i', '../' + netfile, '-d', '../' + taskpath
    ]
    if not asym:
        args.append(
            '-Sym 1'
        )  # Check existance of the back links and generate them if requried

    preparePath(taskpath)

    def tidy(job):
        # Note: GANXiS leaves empty ./output dir in the _ALGSDIR, which should be deleted
        tmp = _ALGSDIR + 'output/'
        if os.path.exists(tmp):
            #os.rmdir(tmp)
            shutil.rmtree(tmp)

    execpool.execute(
        Job(name=_SEPNAMEPART.join((algname, task)),
            workdir=_ALGSDIR,
            args=args,
            timeout=timeout,
            ondone=tidy,
            stdout=taskpath + _EXTLOG,
            stderr=taskpath + _EXTERR))
    return 1
Ejemplo n.º 9
0
def execOslom2(execpool, netfile, asym, timeout, pathid=''):
	assert execpool and netfile and (asym is None or isinstance(asym, bool)) and timeout + 0 >= 0, (
		'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
		.format(execpool, netfile, asym, timeout))
	# Fetch the task name
	task = os.path.split(netfile)[1]  # Base name of the network
	task, netext = os.path.splitext(task)
	assert task, 'The network name should exists'

	algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'oslom2'
	taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))
	# Note: wighted networks (-w) stands for the used null model, not for the input file format.
	# Link weight is set to 1 if not specified in the file for weighted network.
	args = ('../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(('-n=', task, pathid)), '-s=/etime_' + algname
		, './oslom_undir' if not asym else './oslom_dir', '-f', '../' + netfile, '-w')

	preparePath(taskpath)

	netdir = os.path.split(netfile)[0] + '/'
	# Copy results to the required dir on postprocessing
	def postexec(job):
		# Copy communities output from original location to the target one
		origResDir = ''.join((netdir, task, netext, '_oslo_files/'))
		for fname in glob.iglob(escapePathWildcards(origResDir) +'tp*'):
			shutil.copy2(fname, taskpath)

		# Move whole dir as extra task output to the logsdir
		outpdire = taskpath + '/extra/'
		if not os.path.exists(outpdire):
			os.mkdir(outpdire)
		else:
			# If dest dir already exists, remove it to avoid exception on rename
			shutil.rmtree(outpdire)
		os.rename(origResDir, outpdire)

		# Note: oslom2 leaves ./tp file in the _ALGSDIR, which should be deleted
		fname = _ALGSDIR + 'tp'
		if os.path.exists(fname):
			os.remove(fname)

	execpool.execute(Job(name=_SEPNAMEPART.join((algname, task)), workdir=_ALGSDIR, args=args, timeout=timeout, ondone=postexec
		, stdout=taskpath + _EXTLOG, stderr=taskpath + _EXTERR))
	return 1
Ejemplo n.º 10
0
def execScp(execpool, netfile, asym, timeout, pathid=''):
	assert execpool and netfile and (asym is None or isinstance(asym, bool)) and timeout + 0 >= 0, (
		'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
		.format(execpool, netfile, asym, timeout))
	# Fetch the task name
	task, netext = os.path.splitext(netfile)
	task = os.path.split(task)[1]  # Base name of the network
	assert task, 'The network name should exists'

	algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'scp'
	kmin = 3  # Min clique size to be used for the communities identificaiton
	kmax = 8  # Max clique size (~ min node degree to be considered)
	# Run for range of clique sizes
	for k in range(kmin, kmax + 1):
		kstr = str(k)
		kstrex = 'k' + kstr
		# Embed params into the task name
		taskbasex, taskshuf = os.path.splitext(task)
		ktask = ''.join((taskbasex, _SEPPARS, kstrex, taskshuf))
		# Backup previous results if exist
		taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, ktask, pathid))

		preparePath(taskpath)

		# ATTENTION: a single argument is k-clique size, specified later
		steps = '10'  # Use 10 levels in the hierarchy Ganxis
		resbase = ''.join(('../', taskpath, '/', ktask))  # Base name of the result
		# scp.py netname k [start_linksnum end__linksnum numberofevaluations] [weight]
		args = ('../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(('-n=', ktask, pathid)), '-s=/etime_' + algname
			, PYEXEC, ''.join(('./', algname, '.py')), '../' + netfile, kstr, steps, resbase + _EXTCLNODES)

		def tidy(job):
			"""Remove empty resulting folders"""
			# Note: GANXiS leaves empty ./output dir in the _ALGSDIR, which should be deleted
			path = os.path.split(job.args[-1])[0][3:]  # Skip '../' prefix
			if os.path.exists(path) and dirempty(path):
				os.rmdir(path)

		#print('> Starting job {} with args: {}'.format('_'.join((ktask, algname, kstrex)), args + [kstr]))
		execpool.execute(Job(name=_SEPNAMEPART.join((algname, ktask)), workdir=_ALGSDIR, args=args, timeout=timeout
			, ondone=tidy, stderr=taskpath + _EXTLOG))

	return kmax + 1 - kmin
Ejemplo n.º 11
0
def execHirecs(execpool, netfile, asym, timeout, pathid=''):
	assert execpool and netfile and (asym is None or isinstance(asym, bool)) and timeout + 0 >= 0, (
		'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
		.format(execpool, netfile, asym, timeout))
	# Fetch the task name and chose correct network filename
	netfile = os.path.splitext(netfile)[0]  # Remove the extension
	task = os.path.split(netfile)[1]  # Base name of the network
	assert task, 'The network name should exists'
	netfile += '.hig'  # Use network in the required format
	algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'hirecs'
	taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

	preparePath(taskpath)

	args = ('../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(('-n=', task, pathid)), '-s=/etime_' + algname
		, './hirecs', '-oc', ''.join(('-cls=../', taskpath, '/', task, '_', algname, _EXTCLNODES))
		, '../' + netfile)
	execpool.execute(Job(name=_SEPNAMEPART.join((algname, task)), workdir=_ALGSDIR, args=args
		, timeout=timeout, stdout=os.devnull, stderr=taskpath + _EXTLOG))
	return 1
Ejemplo n.º 12
0
def execHirecsNounwrap(execpool, netfile, asym, timeout, pathid=''):
	"""Hirecs which performs the clustering, but does not unwrappes the hierarchy into levels,
	just outputs the folded hierarchy"""
	assert execpool and netfile and (asym is None or isinstance(asym, bool)) and timeout + 0 >= 0, (
		'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
		.format(execpool, netfile, asym, timeout))
	# Fetch the task name and chose correct network filename
	netfile = os.path.splitext(netfile)[0]  # Remove the extension
	task = os.path.split(netfile)[1]  # Base name of the network
	assert task, 'The network name should exists'
	netfile += '.hig'  # Use network in the required format
	algname = funcToAppName(inspect.currentframe().f_code.co_name)  # Or 'hirecshfold'
	taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

	preparePath(taskpath)

	args = ('../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(('-n=', task, pathid)), '-s=/etime_' + algname
		, './hirecs', '-oc', '../' + netfile)
	execpool.execute(Job(name=_SEPNAMEPART.join((algname, task)), workdir=_ALGSDIR, args=args
		, timeout=timeout, stdout=''.join((taskpath, '.hoc'))
		, stderr=taskpath + _EXTLOG))
	return 1
Ejemplo n.º 13
0
def execLouvain_igraph(execpool,
                       netfile,
                       asym,
                       timeout,
                       pathid='',
                       selfexec=False):
    """Execute Louvain
	Results are not stable => multiple execution is desirable.

	returns number of executions or None
	"""
    assert execpool and netfile and (
        asym is None or isinstance(asym, bool)
    ) and timeout + 0 >= 0, (
        'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
        .format(execpool, netfile, asym, timeout))
    # Fetch the task name and chose correct network filename
    netfile, netext = os.path.splitext(netfile)  # Remove the extension
    task = os.path.split(netfile)[1]  # Base name of the network
    assert task, 'The network name should exists'
    #if tasknum:
    #	task = '_'.join((task, str(tasknum)))

    # ATTENTION: for the correct execution algname must be always the same as func lower case name without the prefix "exec"
    algname = funcToAppName(
        inspect.currentframe().f_code.co_name)  # 'louvain_igraph'
    # ./louvain_igraph.py -i=../syntnets/1K5.nsa -ol=louvain_igoutp/1K5/1K5.cnl
    taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

    preparePath(taskpath)

    ## Louvain accumulated statistics over shuffled modification of the network or total statistics for all networks
    #extres = '.acs'
    #if not selfexec:
    #	outpdir = ''.join((_RESDIR, algname, '/'))
    #	if not os.path.exists(outpdir):
    #		os.makedirs(outpdir)
    #	# Just erase the file of the accum results
    #	with open(taskpath + extres, 'w') as accres:
    #		accres.write('# Accumulated results for the shuffles\n')
    #
    #def postexec(job):
    #	"""Copy final modularity output to the separate file"""
    #	# File name of the accumulated result
    #	# Note: here full path is required
    #	accname = ''.join((_ALGSDIR, _RESDIR, algname, extres))
    #	with open(accname, 'a') as accres:  # Append to the end
    #		# TODO: Evaluate the average
    #		subprocess.call(('tail', '-n 1', taskpath + _EXTLOG), stdout=accres)

    args = (
        '../exectime',
        ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)),
        ''.join(('-n=', task, pathid)),
        '-s=/etime_' + algname
        # Note: igraph-python is a Cython wrapper around C igraph lib. Calls are much faster on CPython than on PyPy
        ,
        'python',
        ''.join(('./', algname, '.py')),
        ''.join(('-i=../', netfile, netext)),
        ''.join(('-ol=../', taskpath, _EXTCLNODES)))
    execpool.execute(
        Job(
            name=_SEPNAMEPART.join((algname, task)),
            workdir=_ALGSDIR,
            args=args,
            timeout=timeout
            #, ondone=postexec
            ,
            stdout=os.devnull,
            stderr=''.join((taskpath, _EXTLOG))))

    execnum = 1
    # Note: execution on shuffled network instances is now generalized for all algorithms
    ## Run again for all shuffled nets
    #if not selfexec:
    #	selfexec = True
    #	netdir = os.path.split(netfile)[0] + '/'
    #	#print('Netdir: ', netdir)
    #	for netfile in glob.iglob(''.join((escapePathWildcards(netdir), escapePathWildcards(task), '/*', netext))):
    #		execLouvain_ig(execpool, netfile, asym, timeout, selfexec)
    #		execnum += 1
    return execnum
Ejemplo n.º 14
0
def execLouvain_igraph(execpool, netfile, asym, timeout, pathid='', selfexec=False):
	"""Execute Louvain
	Results are not stable => multiple execution is desirable.

	returns number of executions or None
	"""
	assert execpool and netfile and (asym is None or isinstance(asym, bool)) and timeout + 0 >= 0, (
		'Invalid input parameters:\n\texecpool: {},\n\tnet: {},\n\tasym: {},\n\ttimeout: {}'
		.format(execpool, netfile, asym, timeout))
	# Fetch the task name and chose correct network filename
	netfile, netext = os.path.splitext(netfile)  # Remove the extension
	task = os.path.split(netfile)[1]  # Base name of the network
	assert task, 'The network name should exists'
	#if tasknum:
	#	task = '_'.join((task, str(tasknum)))

	# ATTENTION: for the correct execution algname must be always the same as func lower case name without the prefix "exec"
	algname = funcToAppName(inspect.currentframe().f_code.co_name)  # 'louvain_igraph'
	# ./louvain_igraph.py -i=../syntnets/1K5.nsa -ol=louvain_igoutp/1K5/1K5.cnl
	taskpath = ''.join((_RESDIR, algname, '/', _CLSDIR, task, pathid))

	preparePath(taskpath)

	## Louvain accumulated statistics over shuffled modification of the network or total statistics for all networks
	#extres = '.acs'
	#if not selfexec:
	#	outpdir = ''.join((_RESDIR, algname, '/'))
	#	if not os.path.exists(outpdir):
	#		os.makedirs(outpdir)
	#	# Just erase the file of the accum results
	#	with open(taskpath + extres, 'w') as accres:
	#		accres.write('# Accumulated results for the shuffles\n')
	#
	#def postexec(job):
	#	"""Copy final modularity output to the separate file"""
	#	# File name of the accumulated result
	#	# Note: here full path is required
	#	accname = ''.join((_ALGSDIR, _RESDIR, algname, extres))
	#	with open(accname, 'a') as accres:  # Append to the end
	#		# TODO: Evaluate the average
	#		subprocess.call(('tail', '-n 1', taskpath + _EXTLOG), stdout=accres)

	args = ('../exectime', ''.join(('-o=../', _RESDIR, algname, _EXTEXECTIME)), ''.join(('-n=', task, pathid)), '-s=/etime_' + algname
		# Note: igraph-python is a Cython wrapper around C igraph lib. Calls are much faster on CPython than on PyPy
		, 'python', ''.join(('./', algname, '.py')), ''.join(('-i=../', netfile, netext))
		, ''.join(('-ol=../', taskpath, _EXTCLNODES)))
	execpool.execute(Job(name=_SEPNAMEPART.join((algname, task)), workdir=_ALGSDIR, args=args, timeout=timeout
		#, ondone=postexec
		, stdout=os.devnull, stderr=''.join((taskpath, _EXTLOG))))

	execnum = 1
	# Note: execution on shuffled network instances is now generalized for all algorithms
	## Run again for all shuffled nets
	#if not selfexec:
	#	selfexec = True
	#	netdir = os.path.split(netfile)[0] + '/'
	#	#print('Netdir: ', netdir)
	#	for netfile in glob.iglob(''.join((escapePathWildcards(netdir), escapePathWildcards(task), '/*', netext))):
	#		execLouvain_ig(execpool, netfile, asym, timeout, selfexec)
	#		execnum += 1
	return execnum