當前位置: 首頁>>代碼示例>>Python>>正文


Python PropertyTree.parse_xml方法代碼示例

本文整理匯總了Python中pycap.PropertyTree.parse_xml方法的典型用法代碼示例。如果您正苦於以下問題:Python PropertyTree.parse_xml方法的具體用法?Python PropertyTree.parse_xml怎麽用?Python PropertyTree.parse_xml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pycap.PropertyTree的用法示例。


在下文中一共展示了PropertyTree.parse_xml方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from pycap import PropertyTree [as 別名]
# 或者: from pycap.PropertyTree import parse_xml [as 別名]
def run():
    # parse uq database
    input_database=PropertyTree()
    input_database.parse_xml('uq.xml')
    uq_database=input_database.get_child('uq')

    # declare parameters
    params=uq_database.get_int('params')
    parameter_list=[]
    for p in range(params):
        parameter_database=uq_database.get_child('param_'+str(p))
        distribution_type=parameter_database.get_string('distribution_type')
        parameter_name=parameter_database.get_string('name')
        if distribution_type=='uniform':
            parameter_range=parameter_database.get_array_double('range')
            parameter_list.append(UniformParameter('param_'+str(p),
                                                   parameter_name,
                                                   min=parameter_range[0],
                                                   max=parameter_range[1]))
        elif distribution_type=='normal':
            parameter_mean=parameter_database.get_double('mean')
            parameter_standard_deviation=parameter_database.get_double('standard_deviation')
            parameter_list.append(NormalParameter('param_'+str(p),
                                                  parameter_name,
                                                  mean=parameter_mean,
                                                  dev=parameter_standard_deviation))
        else:
            raise RuntimeError('invalid distribution type '+distribution_type+' for param_'+str(p))

    # create a host
    host_database=uq_database.get_child('host')
    host_type=host_database.get_string('type')
    if host_type=="Interactive":
        host=InteractiveHost(cpus=host_database.get_int_with_default_value('cpus',1),
                             cpus_per_node=host_database.get_int_with_default_value('cpus_per_node',0))
    elif host_type=="PBS":
        host=PBSHost(host_database.get_string('env'),
                     cpus=host_database.get_int_with_default_value('cpus',0),
                     cpus_per_node=host_database.get_int_with_default_value('cpus_per_node',0),
                     qname=host_database.get_string_with_default_value('qname','standby'),
                     walltime=host_database.get_string_with_default_value('walltime','1:00:00'),
                     modules=host_database.get_string_with_default_value('modules',''),
                     pack=host_database.get_int_with_default_value('pack',1),
                     qlimit=host_database.get_int_with_default_value('qlimit',200))
    else:
        raise RuntimeError('invalid host type '+host_type)

    # pick UQ method
    method=uq_database.get_string('method')
    if method=='SmolyakSparseGrid':
        level=uq_database.get_int('level')
        uq=Smolyak(parameter_list,level=level)
    elif method=='MonteCarlo':
        samples=uq_database.get_int('samples')
        uq=MonteCarlo(parameter_list,num=samples)
    elif method=='LatinHypercubeSampling':
        samples=uq_database.get_int('samples')
        uq=LHS(parameter_list,num=samples)
    else:
        raise RuntimeError('invalid UQ method '+method)

    # make a test program
    test_program_database=uq_database.get_child('test_program')
    description=test_program_database.get_string('description')
    executable_name=test_program_database.get_string('executable')
    for p in range(params):
        executable_name+=' --param_'+str(p)+' $param_'+str(p)
    prog=TestProgram(exe=executable_name,
                     desc=description)

    # run
    return Sweep(uq,host,prog)
開發者ID:dalg24,項目名稱:cap-notebooks,代碼行數:74,代碼來源:run_sweep.py

示例2: range

# 需要導入模塊: from pycap import PropertyTree [as 別名]
# 或者: from pycap.PropertyTree import parse_xml [as 別名]
#!/usr/bin/env python

from puq import dump_hdf5
from optparse import OptionParser
from pycap import PropertyTree,EnergyStorageDevice
from pycap import measure_impedance_spectrum
from numpy import real,imag,log10,absolute,angle

# read uq database
uq_database=PropertyTree()
uq_database.parse_xml('uq.xml')
# get number of parameters
params=uq_database.get_int('uq.params')

# usage
usage='usage: %prog'
for p in range(params):
    usage+=' --param_'+str(p)+' val_'+str(p)
parser=OptionParser(usage)
# register options
for p in range(params):
    parser.add_option('--param_'+str(p),type=float)
# parse the command line arguments
(options,args)=parser.parse_args()

# make device database
device_database=PropertyTree()
device_database.parse_xml('super_capacitor.xml')
# adjust the parameters in the database
options_dict=vars(options)
for var in options_dict:
開發者ID:dalg24,項目名稱:cap-notebooks,代碼行數:33,代碼來源:pycap_measure_impedance_spectrum.py


注:本文中的pycap.PropertyTree.parse_xml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。