Example #1
0
def parseParam():
	global HostIP
	global Port
	global TargetClients
	global RequestPerConnection
	global MaxRequests
	global MinClients
	global MaxClients
	global StepClients
	global IntervalTime
	global LastTime
	global RequestSleepTime
	global PipelineNum

	if len(sys.argv) < 3:
		print "usage: %s HostIP PortNumber [ClientNumber=%d or Min/Max/Step/IntervalTime/LastTime] [RequestPerConnection=%d] [PipelineNum=%d] [MaxRequests=%d] [RequestSleepTime=%.1f] [LogLevel=%d]" \
			% (sys.argv[0], TargetClients, RequestPerConnection, PipelineNum, MaxRequests, RequestSleepTime, log.getLogLevel())
		sys.exit()

	paramIndex = 1
	HostIP = sys.argv[paramIndex]

	paramIndex += 1
	Port = int(sys.argv[paramIndex])

	paramIndex += 1
	if len(sys.argv) > paramIndex:
		args = sys.argv[paramIndex].split("/")

		if len(args) == 5 :
			TargetClients = -1
			MinClients = int(args[0])
			MaxClients = int(args[1])
			StepClients = int(args[2])
			IntervalTime = int(args[3])
			LastTime = int(args[4])

		else:
			TargetClients = int(sys.argv[paramIndex])

	paramIndex += 1
	if len(sys.argv) > paramIndex:
		RequestPerConnection = int(sys.argv[paramIndex])

	paramIndex += 1
	if len(sys.argv) > paramIndex:
		PipelineNum = int(sys.argv[paramIndex])

	paramIndex += 1
	if len(sys.argv) > paramIndex:
		MaxRequests = int(sys.argv[paramIndex])

	paramIndex += 1
	if len(sys.argv) > paramIndex:
		RequestSleepTime = float(sys.argv[paramIndex])

	paramIndex += 1
	if len(sys.argv) > paramIndex:
		log.setLogLevel(int(sys.argv[paramIndex]))
Example #2
0
   net1 = topnet.createNetwork(name="net1", topo="tree", size=4, k_ary =2, \
                               hosts_in_sw = 4, bw = 1000000000, delay = 0.001)
   #bw in bytes, delay in second 0.001=1ms, 1GBytes/s, 8 Gbps
   #deploy network to create emulated hosts and resources
   #net1.deploy(model=params['model'], name = "left_net")
   
   debug("***Duplicating: "+net1.name+"\n" )
   net2 = topnet.copyNetwork(fromNetName ="net1" , toNetName = "net2")
    
   #topnet.connectNetworks(srcnet=net1 , dstnet=net2, src="h64", dst= "h64")
   topnet.traffic_pattern = "doubling"
   topnet.writeNetToFile(model = params['model'])

###############################################################################
if __name__ =="__main__":
   #print "argv",sys.argv
   lvl = None
   model = "MPIModel"
   for arg in sys.argv:
      if "--log" in arg:
         assert "=" in arg, "Please supply log level. e.g. --log=debug"
         lvl= arg.split('=')[-1]
         assert lvl is not None, "Please supply log level. e.g. --log=debug"
      if "--model" in arg:
         assert "=" in arg, "Please supply model name. e.g. --model=ModelFileName"
         model =  arg.split('=')[-1]
         assert model is not None, "Please supply model name. e.g. --model=ModelFileName"
   setLogLevel(lvl)
   #Calling main function
   main(model=model)
Example #3
0
RULE_EXECUTION_LIMIT_ONCE			=  1
RULE_EXECUTION_LIMIT_COUNTER		=  2

#when the rule is executed
RULE_TRIGGER_EXTERNAL				= 0
RULE_TRIGGER_DATETIME				= 1
RULE_TRIGGER_PERIODIC				= 2

########################################################################
#
#                 I N I T I A L I Z A T I O N S
#
########################################################################


log.setLogLevel(log.LOG_DEBUG)


########################################################################
#
#                U T I L I T Y    F U N C T I O N S
#
########################################################################
def log(level, message):

	print "(LOG): 
	
	
########################################################################
#
#                        F U N C T I O N S
Example #4
0
def main():
    ''' Main routine '''
    setupLogger()

    # Add options
    usage = ('usage: %prog [-cpnN] Instr [-sndftgahi] '
             'params={val|min,max|min,guess,max}...')
    parser = OptionParser(usage, version=mccode_config.configuration['MCCODE_VERSION'])

    add_mcrun_options(parser)
    add_mcstas_options(parser)

    # Parse options
    (options, args) = parser.parse_args()

    # Write user config file and exit
    if options.write_user_config:
        mccode_config.save_user_config()
        quit()

    
    # Extract instrument and parameters
    if len(args) == 0:
        print(parser.get_usage())
        parser.exit()

    # Set path of instrument-file after locating it
    options.instr = find_instr_file(args[0])

    if options.param:
        # load params from file 
        text = open(options.param).read()
        import re
        params = re.findall('[\w0-9]+=[^=\s]+', text)
        options.params = map(clean_quotes, params)
    else:
        # Clean out quotes (perl mcgui requires this step)
        options.params = map(clean_quotes, args[1:])

    # On windows, ensure that backslashes in the filename are escaped
    if sys.platform == "win32":
        options.instr = options.instr.replace("\\","\\\\")
        
    # Fill out extra information
    expand_options(options)

    if options.verbose:
        setLogLevel(DEBUG)

    # Inform user of what is happening
    # TODO: More info?
    LOG.info('Using directory: "%s"' % options.dir)
    if options.dir == "." or options.dir == "./" or options == ".\\":
        LOG.warning('Existing files in "%s" will be overwritten!' % options.dir)
        LOG.warning(' - and datafiles catenated...')
        options.dir = '';

    # Run McStas
    mcstas = McStas(options.instr)
    mcstas.prepare(options)

    (fixed_params, intervals) = get_parameters(options)

    # Indicate end of setup / start of computations
    LOG.info('===')

    if options.info:
        print('info!')
        mcstas.run(override_mpi=False)
        exit()

    # Set fixed parameters
    for key, value in fixed_params.items():
        mcstas.set_parameter(key, value)

    # Check for linear scanning
    interval_points = None

    # Can't both do list and interval scanning
    if options.list and options.numpoints:
        raise OptionValueError('--numpoints cannot be used with --list')

    if options.list:
        if len(intervals) == 0:
            raise OptionValueError(
                '--list was chosen but no lists was presented.')
        pointlist=list(intervals.values())
        points = len(pointlist[0])
        if not(all(map(lambda i: len(i) == points, intervals.values()))):
            raise OptionValueError(
                'All variables much have an equal amount of points.')
        interval_points = LinearInterval.from_list(
            points, intervals)

    scan = options.multi or options.numpoints
    if ((options.numpoints is not None and options.numpoints < 2)
        or (scan and options.numpoints is None)):
        raise OptionValueError(
            ('Cannot scan variable(s) %s using only one data point. '
             'Please use -N to specify the number of points.') % \
            ', '.join(intervals.keys()))
        # Check that input is valid decimals
        if not all(map(lambda i:
                       len(i) == 2 and
                       all(map(is_decimal, i)), intervals.values())):
            raise OptionValueError('Could not parse intervals -- result: %s'
                                   % str(intervals))

    if options.multi is not None:
        interval_points = MultiInterval.from_range(
            options.numpoints, intervals)

    elif options.numpoints is not None:
        interval_points = LinearInterval.from_range(
            options.numpoints, intervals)

    # Parameters for linear scanning present
    if interval_points:
        scanner = Scanner(mcstas, intervals)
        scanner.set_points(interval_points)
        if (not options.dir == ''):
            mkdir(options.dir)
        scanner.run()
    else:
        # Only run a simulation if we have a nonzero ncount
        if not options.ncount == 0.0:
            mcstas.run()

    if isdir(options.dir):
        LOG.info('Placing instr file copy %s in dataset %s',options.instr,options.dir)
        copyfile(options.instr, join(options.dir,basename(options.instr)))

    if options.autoplot is not None:
        autoplotter = mccode_config.configuration['MCPLOT']
        # apply selected autoplotter, if used
        if options.autoplotter is not None:
            autoplotter = options.autoplotter
        if isdir(options.dir):
            LOG.info('Running plotter %s on dataset %s',mccode_config.configuration['MCPLOT'],options.dir)
            Process(autoplotter).run([options.dir])
Example #5
0
def main():
    ''' Main routine '''
    setupLogger()

    # Add options
    usage = ('usage: %prog [-cpnN] Instr [-sndftgahi] '
             'params={val|min,max|min,guess,max}...')
    parser = OptionParser(usage, version=config.VERSION)

    add_mcrun_options(parser)
    add_mcstas_options(parser)

    # Parse options
    (options, args) = parser.parse_args()

    # Extract instrument and parameters
    if len(args) == 0:
        print parser.get_usage()
        parser.exit()

    # Set path of instrument-file after locating it
    options.instr = find_instr_file(args[0])

    # Clean out quotes (perl mcgui requires this step)
    options.params = map(clean_quotes, args[1:])

    # Fill out extra information
    expand_options(options)

    if options.verbose:
        setLogLevel(DEBUG)

    # Inform user of what is happening
    # TODO: More info?
    LOG.info('Using directory: "%s"' % options.dir)
    if options.dir == "." or options.dir == "./" or options == ".\\":
        LOG.warning('Existing files in "%s" will be overwritten!' % options.dir)
        options.dir = '';

    # Run McStas
    mcstas = McStas(options.instr)
    mcstas.prepare(options)

    (fixed_params, intervals) = get_parameters(options)

    # Indicate end of setup / start of computations
    LOG.info('===')

    if options.info:
        print 'info!'
        mcstas.run(override_mpi=False)
        exit()

    # Set fixed parameters
    for key, value in fixed_params.items():
        mcstas.set_parameter(key, value)

    # Check for linear scanning
    interval_points = None

    # Can't both do list and interval scanning
    if options.list and options.numpoints:
        raise OptionValueError('--numpoints cannot be used with --list')

    if options.list:
        if len(intervals) == 0:
            raise OptionValueError(
                '--list was chosen but no lists was presented.')
        points = len(intervals.values()[0])
        if not(all(map(lambda i: len(i) == points, intervals.values()))):
            raise OptionValueError(
                'All variables much have an equal amount of points.')
        interval_points = LinearInterval.from_list(
            points, intervals)

    scan = options.multi or options.numpoints
    if ((options.numpoints is not None and options.numpoints < 2)
        or (scan and options.numpoints is None)):
        raise OptionValueError(
            ('Cannot scan variable(s) %s using only one data point. '
             'Please use -N to specify the number of points.') % \
            ', '.join(intervals.keys()))
        # Check that input is valid decimals
        if not all(map(lambda i:
                       len(i) == 2 and
                       all(map(is_decimal, i)), intervals.values())):
            raise OptionValueError('Could not parse intervals -- result: %s'
                                   % str(intervals))

    if options.multi is not None:
        interval_points = MultiInterval.from_range(
            options.numpoints, intervals)

    elif options.numpoints is not None:
        interval_points = LinearInterval.from_range(
            options.numpoints, intervals)

    # Parameters for linear scanning present
    if interval_points:
        scanner = Scanner(mcstas, intervals)
        scanner.set_points(interval_points)
        mkdir(options.dir)
        scanner.run()
    else:
        # Only run a simulation if we have a nonzero ncount
        if not options.ncount == 0.0:
            mcstas.run()
Example #6
0
stdout("tests converting back and forth between strings and integer log levels:\n")
stdout("{0:d} tests, {1:d} failures\n\n".format(tests, errors))

stdout("should see debug message test 1\n")
log.debug("log test 1")
if test_fileobj('{0:s}'.format(pgm)) != 1:
    stdout('log file \"{0:s}\" should not have been created\n'.format(pgm), pgm)
    errors += 1
else:
    stdout('Should see "Parameter not a file or file object."\n')
tests += 1
    
print

stdout("testing setLogLevel('warn'), should see only WARN: log test 2\n")
setLogLevel("warn")
log.debug("log test 2")
log.warn("log test 2")
print

stdout("shutting down logger, reinitializing with log level 0\n")
stdout("NullHander should prevent logger calls from generating warnings/errors.\n")
logging.shutdown()

initLogger(logLevel=0, logConsole=True, logDisk=False)
log.debug("this is an error.")
stdout('you should not see "this is an error." above\n')

stdout('after installing null handler, setting log level to debug\n')
setLogLevel('debug')
log.debug("this is not an error.")