Exemple #1
0
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.machine = Machine("treadmill_test")

    def test_get_all(self):
        try:
            self.machine = Machine("treadmill_0")

            ms = self.machine.get_all_machines()
            print(ms)

            self.assertTrue(len(ms) > 0)

        except Exception as e:
            print(e)

    def test_get_machine_schedules(self):
        self.machine = Machine("tr11")

        res = self.machine.get_machine_schedule_dictionaries()
        print("dict")
        print(res)

    def tearDown(self):
        self.machine.db_close()
Exemple #2
0
 def process_machine_settings(self, mset):
     if 'machine_info' in mset:
         machine_info = mset.machine_info
         if isinstance(machine_info, dict) or isinstance(machine_info, obj):
             for machine_name, minfo in machine_info.iteritems():
                 mname = machine_name.lower()
                 if Machine.exists(mname):
                     machine = Machine.get(mname)
                     machine.incorporate_user_info(minfo)
                 else:
                     self.error(
                         'machine {0} is unknown\n  cannot set machine_info'
                         .format(machine_name))
                 #end if
             #end for
         else:
             self.error(
                 'machine_info must be a dict or obj\n  you provided type '
                 + machine_info.__class__.__name__)
         #end if
     #end if
     if 'machine' in mset:
         machine_name = mset.machine
         if not Machine.exists(machine_name):
             self.error('machine {0} is unknown'.format(machine_name))
         #end if
         Job.machine = machine_name
         ProjectManager.machine = Machine.get(machine_name)
         if 'account' in mset:
             account = mset.account
             if not isinstance(account, str):
                 self.error(
                     'account for {0} must be a string\n  you provided: {1}'
                     .format(machine_name, account))
             #end if
             ProjectManager.machine.account = account
         #end if
         if 'machine_mode' in mset:
             machine_mode = mset.machine_mode
             if machine_mode in Machine.modes:
                 machine_mode = Machine.modes[machine_mode]
             #end if
             if machine_mode == Machine.modes.interactive:
                 if ProjectManager.machine == None:
                     ProjectManager.class_error(
                         'no machine specified for interactive mode')
                 #end if
                 if not isinstance(ProjectManager.machine, Supercomputer):
                     self.error(
                         'interactive mode is not supported for machine type '
                         + ProjectManager.machine.__class__.__name__)
                 #end if
                 if not 'interactive_cores' in mset:
                     self.error(
                         'interactive mode requested, but interactive_cores not set'
                     )
                 #end if
                 ProjectManager.machine = ProjectManager.machine.interactive_representation(
                     mset.interactive_cores)
                 Job.machine = ProjectManager.machine.name
Exemple #3
0
    def test_get_all(self):
        try:
            self.machine = Machine("treadmill_0")

            ms = self.machine.get_all_machines()
            print(ms)

            self.assertTrue(len(ms) > 0)

        except Exception as e:
            print(e)
Exemple #4
0
 def process_machine_settings(self,mset):
     if 'machine_info' in mset:
         machine_info = mset.machine_info
         if isinstance(machine_info,dict) or isinstance(machine_info,obj):
             for machine_name,minfo in machine_info.iteritems():
                 mname = machine_name.lower()
                 if Machine.exists(mname):
                     machine = Machine.get(mname)
                     machine.incorporate_user_info(minfo)
                 else:
                     self.error('machine {0} is unknown\n  cannot set machine_info'.format(machine_name))
                 #end if
             #end for
         else:
             self.error('machine_info must be a dict or obj\n  you provided type '+machine_info.__class__.__name__)
         #end if
     #end if
     if 'machine' in mset:
         machine_name = mset.machine
         if not Machine.exists(machine_name):
             self.error('machine {0} is unknown'.format(machine_name))
         #end if
         Job.machine = machine_name
         ProjectManager.machine = Machine.get(machine_name)
         if 'account' in mset:
             account = mset.account
             if not isinstance(account,str):
                 self.error('account for {0} must be a string\n  you provided: {1}'.format(machine_name,account))
             #end if
             ProjectManager.machine.account = account
         #end if
         if 'machine_mode' in mset:
             machine_mode = mset.machine_mode
             if machine_mode in Machine.modes:
                 machine_mode = Machine.modes[machine_mode]
             #end if
             if machine_mode==Machine.modes.interactive:
                 if ProjectManager.machine==None:
                     ProjectManager.class_error('no machine specified for interactive mode')
                 #end if
                 if not isinstance(ProjectManager.machine,Supercomputer):
                     self.error('interactive mode is not supported for machine type '+ProjectManager.machine.__class__.__name__)
                 #end if
                 if not 'interactive_cores' in mset:
                     self.error('interactive mode requested, but interactive_cores not set')
                 #end if
                 ProjectManager.machine = ProjectManager.machine.interactive_representation(mset.interactive_cores)
Exemple #5
0
def fsm0(label):
    m = Machine(label)
    entry = m.S("entry")  # first names state is "start"
    foo = m.S("foo")
    bar = m.S("bar")
    stop = m.S("stop.")  # anything with a "." is a "stop"
    #-- machine
    m.T(entry, walk, foo)
    m.T(foo, walk, foo)
    m.T(foo, sit, stop)
    return m
Exemple #6
0
def main(argv):
    """
    The main program
    """

    try:
        #pylint: disable=unused-variable
        opts, args = getopt.getopt(argv, "h", ["help"])

    except getopt.GetoptError:
        usage()

    #pylint: disable=unused-variable
    for opt, val in opts:
        if opt in ('-h', '--help'):
            usage()

    print('Testing the machines')
    my_host = Machine()
    my_host.set_name('hurukan')
    my_host.set_ip_nbr('132.166.28.183')

    print(my_host.get_id())
Exemple #7
0
from pwscf_postprocessors import Dos, DosInput, DosAnalyzer, generate_dos_input, generate_dos
from pwscf_postprocessors import Bands, BandsInput, BandsAnalyzer, generate_bands_input, generate_bands
from pwscf_postprocessors import Projwfc, ProjwfcInput, ProjwfcAnalyzer, generate_projwfc_input, generate_projwfc
from pwscf_postprocessors import Cppp, CpppInput, CpppAnalyzer, generate_cppp_input, generate_cppp
from pwscf_postprocessors import Pwexport, PwexportInput, PwexportAnalyzer, generate_pwexport_input, generate_pwexport

from qmcpack import loop, linear, cslinear, vmc, dmc
from qmcpack import generate_jastrows, generate_jastrow, generate_jastrow1, generate_jastrow2, generate_jastrow3, generate_opt, generate_opts
from qmcpack import generate_cusp_correction

from qmcpack_workflows import qmcpack_workflow

from debug import *

#set the machine if known, otherwise user will provide
hostmachine = Machine.get_hostname()
if Machine.exists(hostmachine):
    Job.machine = hostmachine
    ProjectManager.machine = Machine.get(hostmachine)
#end if


class Settings(NexusCore):
    singleton = None

    machine_vars = set('''
        machine         account         machine_info    interactive_cores
        machine_mode
        '''.split())

    core_assign_vars = set('''
Exemple #8
0
from pw2casino   import Pw2casino  , Pw2casinoInput  , Pw2casinoAnalyzer  , generate_pw2casino_input  , generate_pw2casino
from pw2qmcpack  import Pw2qmcpack , Pw2qmcpackInput , Pw2qmcpackAnalyzer , generate_pw2qmcpack_input , generate_pw2qmcpack
from wfconvert   import Wfconvert  , WfconvertInput  , WfconvertAnalyzer  , generate_wfconvert_input  , generate_wfconvert
from gamess      import Gamess     , GamessInput     , GamessAnalyzer     , generate_gamess_input     , generate_gamess, FormattedGroup
from convert4qmc import Convert4qmc, Convert4qmcInput, Convert4qmcAnalyzer, generate_convert4qmc_input, generate_convert4qmc
from qmcpack     import Qmcpack    , QmcpackInput    , QmcpackAnalyzer    , generate_qmcpack_input    , generate_qmcpack
from vasp        import Vasp       , VaspInput       , VaspAnalyzer       , generate_vasp_input       , generate_vasp
from qmcpack import loop,linear,cslinear,vmc,dmc
from qmcpack import generate_jastrows,generate_jastrow,generate_jastrow1,generate_jastrow2,generate_jastrow3,generate_opt,generate_opts
from qmcpack import generate_cusp_correction
from auxiliary import *
from debug import *


#set the machine if known, otherwise user will provide
hostmachine = Machine.get_hostname()
if Machine.exists(hostmachine):
    Job.machine = hostmachine
    ProjectManager.machine = Machine.get(hostmachine)
#end if



class Settings(Pobj):
    singleton = None

    project_vars = set([
            'machine','account','generate_only','verbose','debug','mode',
            'local_directory','remote_directory','runs','results','sleep',
            'file_locations','load_images','trace','machine_mode','stages',
            'pseudo_dir','skip_submit','interactive_cores','monitor',
Exemple #9
0
    def test_get_machine_schedules(self):
        self.machine = Machine("tr11")

        res = self.machine.get_machine_schedule_dictionaries()
        print("dict")
        print(res)
Exemple #10
0
class TestMachine(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        self._edison = Machine("edison", 24)

    def test_init(self):
        edison = Machine("edison", 24)
        self.assertEqual(edison._cores_per_node, 24)
        self.assertEqual(edison._machine_name, "edison")

    def test_populate_inter_generator(self):
        create_times = [2, 10, 10, 20, 20]  # 8, 0, 10, 0

        generator = self._edison._populate_inter_generator(create_times)
        self.assertEqual(generator.get_probabilities(), [0.50, 0.75, 1.0])
        self.assertEqual(generator.get_value_ranges(), [(0, 1), (8, 9),
                                                        (10, 11)])

    def test_populate_cores_generator(self):
        cores = [24, 24, 48, 96]
        generator = self._edison._populate_cores_generator(cores)

        self.assertEqual(generator.get_probabilities(), [0.50, 0.75, 1.0])
        self.assertEqual(generator.get_value_ranges(), [(24, 48), (48, 72),
                                                        (96, 120)])

    def test_populate_wallclock_limit_generator(self):
        wallclock = [120, 120, 240, 960]
        generator = self._edison._populate_wallclock_limit_generator(wallclock)

        self.assertEqual(generator.get_probabilities(), [0.50, 0.75, 1.0])
        self.assertEqual(generator.get_value_ranges(), [(2, 3), (4, 5),
                                                        (16, 17)])

    def test_populate_wallclock_accuracy(self):
        wallclock = [120, 120, 240, 960]
        runtime = [60, 120, 120, 240]
        generator = self._edison._populate_wallclock_accuracy(
            wallclock, runtime)

        self.assertEqual(generator.get_probabilities(), [0.25, 0.75, 1.0])

        the_ranges = generator.get_value_ranges()
        r0 = the_ranges[0]
        r1 = the_ranges[1]
        r2 = the_ranges[2]
        self.assertTrue(0.25 >= r0[0] and 0.25 <= r0[1])
        self.assertTrue(0.50 >= r1[0] and 0.50 <= r1[1])
        self.assertTrue(1.0 >= r2[0] and 1.0 <= r2[1])

    def test_create_empty_generators(self):
        self._edison._create_empty_generators()

    def test_get_new_job_details(self):
        create_times = [2, 10, 10, 20, 20]
        self._edison._generators["inter"] = (
            self._edison._populate_inter_generator(create_times))

        cores = [24, 24, 24, 24]
        self._edison._generators["cores"] = (
            self._edison._populate_cores_generator(cores))

        wallclock = [120, 120, 120, 120]
        self._edison._generators["wc_limit"] = \
            self._edison._populate_wallclock_limit_generator(wallclock)

        wallclock = [120, 120, 120, 120]
        runtime = [60, 60, 60, 60]
        self._edison._generators["accuracy"] = \
             self._edison._populate_wallclock_accuracy(wallclock,
                                                              runtime)
        cores, wc_limit, run_time = self._edison.get_new_job_details()
        self.assertEqual(cores, 24)
        self.assertLess(abs(wc_limit - 2), 1)
        self.assertLess(abs(run_time - 60), 30)

    def test_save_load(self):
        create_times = [2, 10, 10, 20, 20]
        self._edison._generators["inter"] = (
            self._edison._populate_inter_generator(create_times))

        cores = [24, 24, 48, 96]
        self._edison._generators["cores"] = (
            self._edison._populate_cores_generator(cores))

        wallclock = [120, 120, 240, 960]
        self._edison._generators["wc_limit"] = \
            self._edison._populate_wallclock_limit_generator(wallclock)

        wallclock = [120, 120, 240, 960]
        runtime = [60, 120, 120, 240]
        self._edison._generators["accuracy"] = \
             self._edison._populate_wallclock_accuracy(wallclock,
                                                              runtime)

        file_name_base = gen_random_string()
        self._edison.save_to_file("/tmp", file_name_base)
        new_edison = Edison()
        new_edison.load_from_file("/tmp", file_name_base)
        self.assertEqual(new_edison._generators["inter"].get_probabilities(),
                         [0.50, 0.75, 1.0], "Data didn't load correctly")
        self.assertEqual(new_edison._generators["inter"].get_value_ranges(),
                         [(0, 1), (8, 9), (10, 11)])
        self.assertEqual(new_edison._generators["cores"].get_probabilities(),
                         [0.50, 0.75, 1.0], "Data didn't load correctly")
        self.assertEqual(new_edison._generators["cores"].get_value_ranges(),
                         [(24, 48), (48, 72), (96, 120)])
        self.assertEqual(
            new_edison._generators["wc_limit"].get_probabilities(),
            [0.50, 0.75, 1.0], "Data didn't load correctly")
        self.assertEqual(new_edison._generators["wc_limit"].get_value_ranges(),
                         [(2, 3), (4, 5), (16, 17)])
        self.assertEqual(
            new_edison._generators["accuracy"].get_probabilities(),
            [0.25, 0.75, 1.0], "Data didn't load correctly")
Exemple #11
0
def test_set_ip_nbr():
    """ Sets the ip number of the machine """
    host = Machine()
    ip_nbr = '132.166.28.183'
    host.set_ip_nbr(ip_nbr)
    assert host.get_ip_nbr() == ip_nbr
Exemple #12
0
def test_is_octet_3():
    """ Checks that a string represents an octet """
    host = Machine()
    val = '258'
    assert not host.is_octet(val)
Exemple #13
0
def test_set_name():
    """ Changes the name of the machine """
    host = Machine()
    name = 'hurukan'
    host.set_name(name)
    assert host.get_name() == name
Exemple #14
0
def test_get_id():
    """ Returns the identity of the machine """
    host = Machine()
    assert host.get_id() == 'Host : localhost 127.0.0.1'
Exemple #15
0
    def __call__(self,**kwargs):

        # guard against invalid settings
        not_allowed = set(kwargs.keys()) - self.all_vars
        if len(not_allowed)>0:
            self.error('unrecognized variables provided.\n  You provided: '+str(list(not_allowed))+'\n  Allowed variables are: '+str(list(vars)))
        #end if

        # extract settings based on keyword groups
        kw = Settings.kw_set(self.project_vars,kwargs)       # project settings
        gamess_kw = Settings.kw_set(self.gamess_vars,kwargs) # gamess settings
        if len(kwargs)>0:
            self.error('some settings keywords have not been accounted for\nleftover keywords: {0}\nthis is a developer error'.format(sorted(kwargs.keys())))
        #end if

        # transfer project variables to project base class
        for name,value in kw.iteritems():
            Pobj.__dict__[name] = value
        #end for

        # process project manager settings
        if 'debug' in kw and kw.debug:
            Pobj.verbose = True
        #end if
        if 'mode' in kw:
            Pobj.set_mode(kw.mode)
        #end if

        # process machine settings
        if 'machine_info' in kw:
            machine_info = Pobj.machine_info
            del Pobj.machine_info
            if isinstance(machine_info,dict) or isinstance(machine_info,obj):
                for machine_name,minfo in machine_info.iteritems():
                    mname = machine_name.lower()
                    if Machine.exists(mname):
                        machine = Machine.get(mname)
                        machine.incorporate_user_info(minfo)
                    else:
                        self.error('machine {0} is unknown\n  cannot set machine_info'.format(machine_name))
                    #end if
                #end for
            else:
                self.error('machine_info must be a dict or obj\n  you provided type '+machine_info.__class__.__name__)
            #end if
        #end if
        if 'machine' in kw:
            machine_name = kw.machine
            if not Machine.exists(machine_name):
                Pobj.class_error('machine {0} is unknown'.format(machine_name))
            #end if
            Job.machine = machine_name
            ProjectManager.machine = Machine.get(machine_name)
            #del Pobj.machine
            if 'account' in kw:
                account = Pobj.account
                #del Pobj.account
                if not isinstance(account,str):
                    self.error('account for {0} must be a string\n  you provided: {1}'.format(machine_name,account))
                #end if
                ProjectManager.machine.account = account
            #end if
            if 'machine_mode' in kw:
                machine_mode = kw.machine_mode
                if machine_mode in Machine.modes:
                    machine_mode = Machine.modes[machine_mode]
                #end if
                if machine_mode==Machine.modes.interactive:
                    if ProjectManager.machine==None:
                        ProjectManager.class_error('no machine specified for interactive mode')
                    #end if
                    if not isinstance(ProjectManager.machine,Supercomputer):
                        self.error('interactive mode is not supported for machine type '+ProjectManager.machine.__class__.__name__)
                    #end if
                    if not 'interactive_cores' in kw:
                        self.error('interactive mode requested, but interactive_cores not set')
                    #end if
                    ProjectManager.machine = ProjectManager.machine.interactive_representation(Pobj.interactive_cores)
                    del Pobj.interactive_cores
                #end if
                del Pobj.machine_mode
            #end if
        #end if

        # process simulation settings
        if 'local_directory' in kw:
            Pobj.file_locations.append(kw.local_directory)
        #end if
        if 'skip_submit' in kw:
            Pobj.skip_submission = Pobj.skip_submit
            del Pobj.skip_submit
        #end if
        if 'file_locations' in kw:
            fl = kw.file_locations
            if isinstance(fl,str):
                Pobj.file_locations.extend([fl])
            else:
                Pobj.file_locations.extend(list(fl))
            #end if
        #end if
        if not 'pseudo_dir' in kw:
            Pobj.pseudopotentials = Pseudopotentials()
        else:
            pseudo_dir = kw.pseudo_dir
            Pobj.file_locations.append(pseudo_dir)
            if not os.path.exists(pseudo_dir):
                self.error('pseudo_dir "{0}" does not exist'.format(pseudo_dir),trace=False)
            #end if
            files = os.listdir(pseudo_dir)
            ppfiles = []
            for f in files:
                pf = os.path.join(pseudo_dir,f)
                if os.path.isfile(pf):
                    ppfiles.append(pf)
                #end if
            #end for
            Pobj.pseudopotentials = Pseudopotentials(ppfiles)        
        #end if

        # more simulation/project manager settings processing
        mode = Pobj.mode
        modes = Pobj.modes
        if mode==modes.stages:
            stages = Pobj.stages
        elif mode==modes.all:
            stages = list(Pobj.primary_modes)
        else:
            stages = [kw.mode]
        #end if
        allowed_stages = set(Pobj.primary_modes)
        if isinstance(stages,str):
            stages = [stages]
        #end if
        if len(stages)==0:
            stages = list(Pobj.primary_modes)
            #self.error('variable stages must be a list of primary modes.\n  Options are '+str(list(allowed_stages)))
        elif 'all' in stages:
            stages = list(Pobj.primary_modes)
        else:
            forbidden = set(Pobj.stages)-allowed_stages
            if len(forbidden)>0:
                self.error('some stages provided are not primary stages.\n  You provided '+str(list(forbidden))+'\n  Options are '+str(list(allowed_stages)))
            #end if
        #end if
        Pobj.mode = modes.stages
        Pobj.stages     = stages
        Pobj.stages_set = set(Pobj.stages)

        # process gamess settings
        Gamess.settings(**gamess_kw)

        return
Exemple #16
0
 def setUp(self):
     self.machine = Machine("treadmill_test")
Exemple #17
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self._edison = Machine("edison", 24)
Exemple #18
0
 def test_init(self):
     edison = Machine("edison", 24)
     self.assertEqual(edison._cores_per_node, 24)
     self.assertEqual(edison._machine_name, "edison")
Exemple #19
0
from products import Lot
from sites import Site

machines = []
lots = []
sites = []

data = xlrd.open_workbook('machines.xlsx')
num_of_catagories = len(data.sheets())
for i in range(num_of_catagories):
    table = data.sheets()[i]
    num_of_rows = table.nrows
    num_of_cols = table.ncols
    #print(num_of_rows,num_of_cols)
    for i in range(2, num_of_cols):
        machines.append(Machine(table.cell(0, i).value, 0))  #以机器名称实例化Machine
        for j in range(num_of_rows):
            if (table.cell(j, i).value == 'Y'):
                machines[len(machines) - 1].product_push(
                    int(table.cell(j, 0).value), int(table.cell(j, 1).value))
                if (len(machines[-1].all_possible_sites) == 0):
                    machines[len(machines) - 1].all_possible_sites.append(
                        int(table.cell(j, 0).value))
                elif (machines[-1].all_possible_sites[-1] != table.cell(
                        j, 0).value):
                    machines[len(machines) - 1].all_possible_sites.append(
                        int(table.cell(j, 0).value))
        #print(machines[len(machines)-1].name,machines[len(machines)-1].all_possible_sites,machines[len(machines)-1].products)

data = xlrd.open_workbook('overall.xlsx')
table = data.sheets()[1]
Exemple #20
0
    def __call__(self,**kwargs):
        vars = set(['machine','account','generate_only','verbose','debug','mode',
                    'local_directory','remote_directory','runs','results','sleep',
                    'file_locations','load_images','trace','machine_mode','stages',
                    'pseudo_dir','skip_submit','interactive_cores','monitor',
                    'status_only','machine_info'])

        keys = set(kwargs.keys())
        not_allowed = keys - vars
        if len(not_allowed)>0:
            Pobj.class_error('unrecognized variables provided.\n  You provided: '+str(list(not_allowed))+'\n  Allowed variables are: '+str(list(vars)),'settings')
        #end if

        for name,value in kwargs.iteritems():
            Pobj.__dict__[name] = value
        #end for

        if 'debug' in kwargs and kwargs['debug']:
            Pobj.verbose = True
        #end if
        if 'mode' in kwargs:
            Pobj.set_mode(kwargs['mode'])
        #end if
        if 'machine_info' in kwargs:
            machine_info = Pobj.machine_info
            del Pobj.machine_info
            if isinstance(machine_info,dict) or isinstance(machine_info,obj):
                for machine_name,minfo in machine_info.iteritems():
                    mname = machine_name.lower()
                    if Machine.exists(mname):
                        machine = Machine.get(mname)
                        machine.incorporate_user_info(minfo)
                    else:
                        Pobj.class_error('machine {0} is unknown\n  cannot set machine_info'.format(machine_name),'settings')
                    #end if
                #end for
            else:
                Pobj.class_error('machine_info must be a dict or obj\n  you provided type '+machine_info.__class__.__name__,'settings')
            #end if
        #end if
        if 'machine' in kwargs:
            machine_name = kwargs['machine']
            if not Machine.exists(machine_name):
                Pobj.class_error('machine {0} is unknown'.format(machine_name),'settings')
            #end if
            Job.machine = machine_name
            ProjectManager.machine = Machine.get(machine_name)
            #del Pobj.machine
            if 'account' in kwargs:
                account = Pobj.account
                #del Pobj.account
                if not isinstance(account,str):
                    Pobj.class_error('account for {0} must be a string\n  you provided: {1}'.format(machine_name,account),'settings')
                #end if
                ProjectManager.machine.account = account
            #end if
            if 'machine_mode' in kwargs:
                machine_mode = kwargs['machine_mode']
                if machine_mode in Machine.modes:
                    machine_mode = Machine.modes[machine_mode]
                #end if
                if machine_mode==Machine.modes.interactive:
                    if ProjectManager.machine==None:
                        ProjectManager.class_error('no machine specified for interactive mode','settings')
                    #end if
                    if not isinstance(ProjectManager.machine,Supercomputer):
                        Pobj.class_error('interactive mode is not supported for machine type '+ProjectManager.machine.__class__.__name__,'settings')
                    #end if
                    if not 'interactive_cores' in kwargs:
                        Pobj.class_error('interactive mode requested, but interactive_cores not set','settings')
                    #end if
                    ProjectManager.machine = ProjectManager.machine.interactive_representation(Pobj.interactive_cores)
                    del Pobj.interactive_cores
                #end if
                del Pobj.machine_mode
            #end if
        #end if
        if 'local_directory' in kwargs:
            Pobj.file_locations.append(kwargs['local_directory'])
        #end if
        if 'skip_submit' in kwargs:
            Pobj.skip_submission = Pobj.skip_submit
            del Pobj.skip_submit
        #end if
        if 'file_locations' in kwargs:
            fl = kwargs['file_locations']
            if isinstance(fl,str):
                Pobj.file_locations.extend([fl])
            else:
                Pobj.file_locations.extend(list(fl))
            #end if
        #end if
        if not 'pseudo_dir' in kwargs:
            Pobj.pseudopotentials = Pseudopotentials()
        else:
            pseudo_dir = kwargs['pseudo_dir']
            Pobj.file_locations.append(pseudo_dir)
            files = os.listdir(pseudo_dir)
            ppfiles = []
            for f in files:
                pf = os.path.join(pseudo_dir,f)
                if os.path.isfile(pf):
                    ppfiles.append(pf)
                #end if
            #end for
            Pobj.pseudopotentials = Pseudopotentials(ppfiles)        
        #end if

        mode = Pobj.mode
        modes = Pobj.modes
        if mode==modes.stages:
            stages = Pobj.stages
        elif mode==modes.all:
            stages = list(Pobj.primary_modes)
        else:
            stages = [kwargs['mode']]
        #end if
        allowed_stages = set(Pobj.primary_modes)
        if isinstance(stages,str):
            stages = [stages]
        #end if
        if len(stages)==0:
            stages = list(Pobj.primary_modes)
            #Pobj.class_error('variable stages must be a list of primary modes.\n  Options are '+str(list(allowed_stages)),'settings')
        elif 'all' in stages:
            stages = list(Pobj.primary_modes)
        else:
            forbidden = set(Pobj.stages)-allowed_stages
            if len(forbidden)>0:
                Pobj.class_error('some stages provided are not primary stages.\n  You provided '+str(list(forbidden))+'\n  Options are '+str(list(allowed_stages)),'settings')
            #end if
        #end if
        Pobj.mode = modes.stages
        Pobj.stages     = stages
        Pobj.stages_set = set(Pobj.stages)

        return
Exemple #21
0
    def __call__(self,**kwargs):

        # guard against invalid settings
        not_allowed = set(kwargs.keys()) - self.all_vars
        if len(not_allowed)>0:
            self.error('unrecognized variables provided.\n  You provided: '+str(list(not_allowed))+'\n  Allowed variables are: '+str(list(vars)))
        #end if

        # extract settings based on keyword groups
        kw = Settings.kw_set(self.project_vars,kwargs)       # project settings
        gamess_kw = Settings.kw_set(self.gamess_vars,kwargs) # gamess settings
        if len(kwargs)>0:
            self.error('some settings keywords have not been accounted for\nleftover keywords: {0}\nthis is a developer error'.format(sorted(kwargs.keys())))
        #end if

        # transfer project variables to project base class
        for name,value in kw.iteritems():
            Pobj.__dict__[name] = value
        #end for

        # process project manager settings
        if 'debug' in kw and kw.debug:
            Pobj.verbose = True
        #end if
        if 'mode' in kw:
            Pobj.set_mode(kw.mode)
        #end if

        # process machine settings
        if 'machine_info' in kw:
            machine_info = Pobj.machine_info
            del Pobj.machine_info
            if isinstance(machine_info,dict) or isinstance(machine_info,obj):
                for machine_name,minfo in machine_info.iteritems():
                    mname = machine_name.lower()
                    if Machine.exists(mname):
                        machine = Machine.get(mname)
                        machine.incorporate_user_info(minfo)
                    else:
                        self.error('machine {0} is unknown\n  cannot set machine_info'.format(machine_name))
                    #end if
                #end for
            else:
                self.error('machine_info must be a dict or obj\n  you provided type '+machine_info.__class__.__name__)
            #end if
        #end if
        if 'machine' in kw:
            machine_name = kw.machine
            if not Machine.exists(machine_name):
                Pobj.class_error('machine {0} is unknown'.format(machine_name))
            #end if
            Job.machine = machine_name
            ProjectManager.machine = Machine.get(machine_name)
            #del Pobj.machine
            if 'account' in kw:
                account = Pobj.account
                #del Pobj.account
                if not isinstance(account,str):
                    self.error('account for {0} must be a string\n  you provided: {1}'.format(machine_name,account))
                #end if
                ProjectManager.machine.account = account
            #end if
            if 'machine_mode' in kw:
                machine_mode = kw.machine_mode
                if machine_mode in Machine.modes:
                    machine_mode = Machine.modes[machine_mode]
                #end if
                if machine_mode==Machine.modes.interactive:
                    if ProjectManager.machine==None:
                        ProjectManager.class_error('no machine specified for interactive mode')
                    #end if
                    if not isinstance(ProjectManager.machine,Supercomputer):
                        self.error('interactive mode is not supported for machine type '+ProjectManager.machine.__class__.__name__)
                    #end if
                    if not 'interactive_cores' in kw:
                        self.error('interactive mode requested, but interactive_cores not set')
                    #end if
                    ProjectManager.machine = ProjectManager.machine.interactive_representation(Pobj.interactive_cores)
                    del Pobj.interactive_cores
                #end if
                del Pobj.machine_mode
            #end if
        #end if

        # process simulation settings
        if 'local_directory' in kw:
            Pobj.file_locations.append(kw.local_directory)
        #end if
        if 'skip_submit' in kw:
            Pobj.skip_submission = Pobj.skip_submit
            del Pobj.skip_submit
        #end if
        if 'file_locations' in kw:
            fl = kw.file_locations
            if isinstance(fl,str):
                Pobj.file_locations.extend([fl])
            else:
                Pobj.file_locations.extend(list(fl))
            #end if
        #end if
        if not 'pseudo_dir' in kw:
            Pobj.pseudopotentials = Pseudopotentials()
        else:
            pseudo_dir = kw.pseudo_dir
            Pobj.file_locations.append(pseudo_dir)
            if not os.path.exists(pseudo_dir):
                self.error('pseudo_dir "{0}" does not exist'.format(pseudo_dir),trace=False)
            #end if
            files = os.listdir(pseudo_dir)
            ppfiles = []
            for f in files:
                pf = os.path.join(pseudo_dir,f)
                if os.path.isfile(pf):
                    ppfiles.append(pf)
                #end if
            #end for
            Pobj.pseudopotentials = Pseudopotentials(ppfiles)        
        #end if

        # more simulation/project manager settings processing
        mode = Pobj.mode
        modes = Pobj.modes
        if mode==modes.stages:
            stages = Pobj.stages
        elif mode==modes.all:
            stages = list(Pobj.primary_modes)
        else:
            stages = [kw.mode]
        #end if
        allowed_stages = set(Pobj.primary_modes)
        if isinstance(stages,str):
            stages = [stages]
        #end if
        if len(stages)==0:
            stages = list(Pobj.primary_modes)
            #self.error('variable stages must be a list of primary modes.\n  Options are '+str(list(allowed_stages)))
        elif 'all' in stages:
            stages = list(Pobj.primary_modes)
        else:
            forbidden = set(Pobj.stages)-allowed_stages
            if len(forbidden)>0:
                self.error('some stages provided are not primary stages.\n  You provided '+str(list(forbidden))+'\n  Options are '+str(list(allowed_stages)))
            #end if
        #end if
        Pobj.mode = modes.stages
        Pobj.stages     = stages
        Pobj.stages_set = set(Pobj.stages)

        # process gamess settings
        Gamess.settings(**gamess_kw)

        return
Exemple #22
0
# ----------------------------------------------
def walk(w, a):
    return maybe()


def sit(w, a):
    return maybe()


def ok(w, a):
    return True


def fail(w, a):
    return maybe()


def again(w, a):
    return maybe()


if __name__ == '__main__':
    fsm0(1)
    fsm0(2)
    fsm0(4)
    if len(sys.argv) > 1:
        Machine.run(int(sys.argv[1]))
    else:
        Machine.run()