Ejemplo n.º 1
0
 def __init__(self, varConfig, FileList):
     lg.logging(
         'Start Initialing %s' % (self.__class__.__name__), 'SPECIAL'
     )
     HRB.HtbRunBase.__init__(self, {})
     self.varConfig = varConfig
     self.FileList = FileList
Ejemplo n.º 2
0
 def printover(self, _in, nt):
     tp = type(_in)
     t = ''
     n = 0
     while n < nt:
         t = t + '\t'
         n = n + 1
     if tp is dict:
         for _key, _val in _in.items():
             if type(_val) != dict and\
                type(_val) != list and\
                type(_val) != tuple:
                 fs = t + str(_key) + ': ' + str(_val)
                 lg.logging(fs)
             else:
                 fs = t + 'Elements in %s :' % (str(_key))
                 lg.logging(fs, 'SPECIAL')
                 self.printover(_val, nt+1)
     elif tp is list or tp is tuple:
         for _val in _in:
             if type(_val) != dict and\
                type(_val) != list and\
                type(_val) != tuple:
                 fs = t + str(_val)
                 lg.logging(fs)
             else:
                 fs = t + 'Elements in list :'
                 lg.logging(fs, 'SPECIAL')
                 self.printover(_val, nt+1)
     else:
         fs = t + str(_in)
         lg.logging(fs)
Ejemplo n.º 3
0
 def LoopOver(self, Var, Cut, Bins, Weights):
     varHist = []
     hout = []
     for f in self.DataToLoop:
         fn = self._getName(f)
         lg.logging('\tRunning %s' % (fn), 'SPECIAL')
         varHist.append(self.Do(f, fn, Var, Cut, Bins, Weights))
     if self.Name != "ttbar":
         hn = Var + '_of_' + self.Name
         hist = rt.TH1F(
             self.Name,
             hn,
             Bins['nbin'],
             Bins['xlow'],
             Bins['xup']
         )
         hist.Sumw2()
         for hl in varHist:
             for fn, h in hl.items():
                 hist.Add(h)
         hout.append(hist)
         return hout
     else:
         hn1 = Var + '_of_' + "ttbb"
         hn2 = Var + '_of_' + "ttcc"
         hn3 = Var + '_of_' + "ttlight"
         hist1 = rt.TH1F(
             "tt+bb",
             hn1,
             Bins['nbin'],
             Bins['xlow'],
             Bins['xup']
         )
         hist1.Sumw2()
         hist2 = rt.TH1F(
             "tt+cc",
             hn2,
             Bins['nbin'],
             Bins['xlow'],
             Bins['xup']
         )
         hist2.Sumw2()
         hist3 = rt.TH1F(
             "tt+light",
             hn3,
             Bins['nbin'],
             Bins['xlow'],
             Bins['xup']
         )
         hist3.Sumw2()
         for hl in varHist:
             hist1.Add(hl["tt+bb"])
             hist2.Add(hl["tt+cc"])
             hist3.Add(hl["tt+light"])
         hout.append(hist1)
         hout.append(hist2)
         hout.append(hist3)
         return hout
Ejemplo n.º 4
0
 def _on_qq_request(self, call_back, response):
     body = response.body
     body = ''.join(body.replace(';','').split())
     r = eval(body)
     if hasattr(r, 'error'):
         logging.logging("Error response %s fetching %s", r.error_description, response.request.url)
         call_back(None)
         return
     call_back(r)
Ejemplo n.º 5
0
 def LoopOver(self):
     if type(self.DataToLoop) is list or type(self.DataToLoop) is tuple:
         for i, _val in enumerate(self.DataToLoop):
             lg.logging('Start running %i in List' % (i), 'SUCCESS')
             self.Do(_val)
     elif type(self.DataToLoop) is dict:
         for _key, _val in self.DataToLoop.items():
             lg.logging('Start running %s' % (_key), 'SUCCESS')
             self.Do(_val)
Ejemplo n.º 6
0
 def OpenFile(self):
     OFDict = {}
     for _key, _val in self.FullFN.items():
         FileList = []
         for fn in _val:
             try:
                 rf = rt.TFile(fn, 'r')
             except:
                 lg.logging('Cannot Open File %s' % (fn), 'WART')
                 os._exit(1)
             FileList.append(rf)
         OFDict[_key] = FileList
     self.RootFile = OFDict
Ejemplo n.º 7
0
 def Get(self, _path):
     spath = _path.strip().split('/')
     try:
         _out = self.fConfig
         for sp in spath:
             if sp is '' or sp is ' ' or sp is '\n':
                 continue
             else:
                 _out = _out[sp]
     except:
         lg.logging('Failed to get value, Wrong path', 'WARN')
         _out = None
     return _out
Ejemplo n.º 8
0
 def LoopOver(self):
     self.output = util.CreateRootFile(self.varConfig.General['output'])
     for _cut in self.varConfig.CutList:
         print '#####################################'
         lg.logging('Processing Cut %s' % (_cut))
         PlotDir1 = self.output.mkdir(_cut)
         PlotDir1.cd()
         for _var in self.varConfig.Vars[_cut]:
             lg.logging('\tProcessing Variable %s' % (_var))
             PlotDir2 = PlotDir1.mkdir(_var)
             PlotDir2.cd()
             for fl in self.FileList:
                 weights = [
                     'weight_mc',
                     'weight_leptonSF',
                     'weight_bTagSF_77',
                     'weight_pileup',
                     'weight_jvt'
                 ]
                 hl = fl.LoopOver(
                     _var,
                     self.varConfig.Cuts[_cut],
                     self.varConfig.fConfig[_cut][_var],
                     weights
                 )
                 for hist in hl:
                     hist.SetDirectory(PlotDir2)
                     hist.Write()
             lg.logging('Variable %s Done' % (_var), 'SUCCESS')
         lg.logging('Cut %s Done' % (_cut), 'SUCCESS')
     self.output.Close()
Ejemplo n.º 9
0
 def Get(self, _path):
     spath = _path.strip().split('/')
     try:
         _out = self.RootFile
         for sp in spath:
             if sp is '' or sp is ' ' or sp is '\n':
                 continue
             else:
                 if type(_out) is list:
                     sp = int(sp)
                 _out = _out[sp]
     except:
         lg.logging('Failed to get value, Wrong path', 'WARN')
         _out = None
     return _out
Ejemplo n.º 10
0
 def __init__(self, _inputF):
     lg.logging(
         'Start Initialing %s' % (self.__class__.__name__), 'SPECIAL'
     )
     HCB.HtbConfigBase.__init__(self, _inputF)
     self.DecorateConfig()
     self.General = self.fConfig['General']
     self.CutList = self.fConfig.keys()
     self.CutList.remove('General')
     self.Cuts = {}
     self.Vars = {}
     for cut in self.CutList:
         self.Cuts[cut] = self.fConfig[cut]['cut']
         self.Vars[cut] = self.fConfig[cut].keys()
         self.Vars[cut].remove('cut')
Ejemplo n.º 11
0
 def __init__(self):
   print "created neuron";
   self.Logclass = logging();
   self.Logclass.set_verbosity(0);
   self.bias = 0;
   self.z_ip = 0.0;
   self.a_op = 0.0;# ouput of sigmoid needs to go here
Ejemplo n.º 12
0
 def __init__ (self):
   self.Logclass = logging();
   self.Logclass.set_verbosity(0);
   self.avail_pos_dict = {0 : [x for x in xrange(48)], 1: [x for x in xrange(48)]};
   self.state = [[0 for list_idx in xrange(6)] for vert_idx in xrange(8)];
   self.win = 0;
   self.prev_player = -2;
   self.logv(self.avail_pos_dict, 0);
Ejemplo n.º 13
0
 def eval_out (inp, bias):
   Logclass = logging();
   Logclass.set_verbosity(0);
   ip = np.multiply(-1 , np.add(inp, bias));
   a_op =1 / (1 + np.exp(np.multiply(-1, np.add(inp, bias))));# ouput of sigmoid needs to go here
   diff_op = np.power(a_op, 2) * (np.exp(np.multiply(-1, np.add(inp, bias))));# ouput of sigmoid needs to go here
   Logclass.Logm(diff_op, 1, "DIFF");
   Logclass.Logm(a_op, 1, "ACT");
   return [diff_op, a_op];
Ejemplo n.º 14
0
 def start_game(self):
     self.snakes = []
     self.self_snake = {'sid':-1,'xx':-1,'yy':-1}
     self.self_target = {'xx':-1,'yy':-1}
     self.self_dead = False
     self.ws.send(self.set_username_and_skin())
     self.pong = True
     self.send_ping()
     logging.logging('Started game')
     def set_interval(func, sec):
         def func_wrapper():
             set_interval(func, sec)
             func()
         t = threading.Timer(sec, func_wrapper)
         t.start()
         return t
     self.pingthread = set_interval(self.send_ping,0.25)
     lg.debug('Started ping thread')
Ejemplo n.º 15
0
def XsecInit(xfilename):
    xsecf = open(xfilename)
    output = {}
    lns = xsecf.readlines()
    for ln in lns:
        if ln.strip() == '':
            continue
        elif ln.strip()[0] == '#':
            continue

        sln = ln.strip()
        if '\t' in sln:
            sln = sln.expandtabs(1)
        s = sln.split(' ')
        ss = [i for i in s if i != '']
        try:
            output[str(ss[0])] = float(ss[1]) * float(ss[2])
        except:
            print 'XSection file error, ID %s' % (str(ss[0]))
    lg.logging('Done', 'SUCCESS')
    return output
Ejemplo n.º 16
0
 def __init__(self, Name, LoopData, XSFile, Lumi):
     lg.logging(
         'Starting Initialing %s' % (self.__class__.__name__), 'SPECIAL'
     )
     HRB.HtbRunBase.__init__(self, LoopData)
     self.Xsection = XSFile
     self.Name = Name
     self.Lumi = Lumi
     self.Norm = {}
     self.ZLRW = [361372, 361375, 361378, 361381, 361384, 361387, 361390, 361393, 361396,
                  361399, 361402, 361405, 361408, 361411, 361414, 361417, 361420, 361423,
                  361426, 361429, 361432, 361435, 361438, 361441, 361468, 361470, 361472,
                  361474, 361476, 361478, 361480, 361482, 361484, 361486, 361488, 361490]
     self.ZHRW = [361374, 361377, 361380, 361383, 361386, 361389, 361392, 361395, 361398,
                  361401, 361404, 361407, 361410, 361413, 361416, 361419, 361422, 361425,
                  361428, 361431, 361434, 361437, 361440, 361443, 361469, 361471, 361473,
                  361475, 361477, 361479, 361481, 361483, 361485, 361487, 361489, 361491]
     self.HFcut = {"tt+bb": "abs(HF_Classification) >= 100",
                   "tt+cc": "abs(HF_Classification) > 0 && abs(HF_Classification) < 100",
                   "tt+light": "abs(HF_Classification) <= 0"}
     if 'data' not in self.Name:
         self.CalNorm()
Ejemplo n.º 17
0
    def SearchFile(self):
        full_F = {}
        for _key, _val in self.fConfig.items():
            exf = []
            inf = []
            if 'excludefile' in _val:
                exf = _val['excludefile']
            if 'includefile' in _val:
                inf = _val['includefile']
            try:
                _dir = os.listdir(_val['path'])
            except:
                lg.logging('Cannot Find Path %s' % (_val['path']), 'WARN')
                os._exit(1)

            for _file in _dir:
                if _file in exf:
                    continue
                elif '.root' in _file:
                    inf.append(_val['path'] + _file)
            full_F[_key] = inf
        self.FullFN = full_F
Ejemplo n.º 18
0
 def __init__(self, nn_inp, nn_op):
   self.Logclass = logging();
   self.Logclass.set_verbosity(0);
   self.num_layers = 2;
   self.num_neurons = [2,  1,  1];
   self.z_vector = np.array([[0 for index in xrange(self.num_neurons[list_idx])] for list_idx in xrange(len(self.num_neurons))]); # these are the inputs to neurons
   self.act_vector = np.array([[0 for index in xrange(self.num_neurons[list_idx])] for list_idx in xrange(len(self.num_neurons))]);
   self.err_vector = np.array([[0 for index in xrange(self.num_neurons[list_idx])] for list_idx in xrange(len(self.num_neurons))]);
   self.bias_vector = np.array([[0 for index in xrange(self.num_neurons[list_idx])] for list_idx in xrange(len(self.num_neurons))]);
   self.diff_vector = np.array([[0 for index in xrange(self.num_neurons[list_idx])] for list_idx in xrange(len(self.num_neurons))]);
   self.weights = []
   self.out = [3];
   self.wt_gradient = []
   for count in xrange(len(self.num_neurons) - 1):
     self.weights.append(self.rand_matrix(self.num_neurons[count + 1], self.num_neurons[count])); 
     self.wt_gradient.append(self.rand_matrix(self.num_neurons[count + 1], self.num_neurons[count])); 
   self.logv(self.weights, 1);
   for iter_count in xrange(1000):
     for elem_idx in range(len(nn_inp)):
       self.update_nn(nn_inp[elem_idx]);
       self.out = nn_op[elem_idx];
       self.calc_errors();
       self.update_weights();
   pass;
Ejemplo n.º 19
0
def run_thread(agent, game_num, Synchronizer, difficulty):
    global UPDATE_EVENT, ROLLING_EVENT, Counter, Waiting_Counter, Update_Counter, Result_List

    num = 0
    proc_name = mp.current_process().name

    blue_agent = DummyTerran(diff=difficulty)
    blue_agent.get_power()

    env = SimulatePlatform(red_agent=agent,
                           blue_agent=blue_agent,
                           distance=5,
                           max_steps=100)
    env.init()
    agent.set_env(env)

    while True:
        env.simulate(SHOW_DETAILS)

        if True:
            # check if the num of episodes is enough to update
            num += 1
            Counter += 1
            reward = agent.result
            Result_List.append(reward)
            logging("(diff: %d) %d epoch: %s get %d/%d episodes! return: %f!" %
                    (int(difficulty), Update_Counter, proc_name,
                     len(Result_List), game_num * THREAD_NUM, reward))

            # time for update
            if num == game_num:
                num = 0
                ROLLING_EVENT.clear()
                # worker stops rolling, wait for update
                if agent.agent_id != 0 and THREAD_NUM > 1:
                    Waiting_Counter += 1
                    if Waiting_Counter == THREAD_NUM - 1:  # wait for all the workers stop
                        UPDATE_EVENT.set()
                    ROLLING_EVENT.wait()

                # update!
                else:
                    if THREAD_NUM > 1:
                        UPDATE_EVENT.wait()

                    Synchronizer.wait()  # wait for other processes to update

                    agent.update_network(Result_List)
                    Result_List.clear()
                    agent.global_buffer.reset()
                    Synchronizer.wait()

                    Update_Counter += 1

                    # finish update
                    UPDATE_EVENT.clear()
                    Waiting_Counter = 0
                    ROLLING_EVENT.set()

        win_rate = agent.net.get_win_rate()
        if win_rate > WIN_RATE_THRESHOLD:
            difficulty += 1
            env.blue_agent.set_diff(difficulty)
            print('Increase difficulty to:', difficulty)

        env.reset()
def Parameter_Server(Synchronizer, cluster, log_path, model_path, procs):
    config = tf.ConfigProto(
        allow_soft_placement=True,
        log_device_placement=False,
    )
    config.gpu_options.allow_growth = True
    server = tf.train.Server(cluster,
                             job_name="ps",
                             task_index=0,
                             config=config)
    sess = tf.Session(target=server.target, config=config)
    summary_writer = tf.summary.FileWriter(log_path)
    Net = MiniNetwork(sess=sess,
                      summary_writer=summary_writer,
                      rl_training=FLAGS.training,
                      cluster=cluster,
                      index=0,
                      device=DEVICE[0 % len(DEVICE)],
                      ppo_load_path=FLAGS.restore_model_path,
                      ppo_save_path=model_path,
                      ob_space_add=FLAGS.ob_space_add,
                      act_space_add=FLAGS.act_space_add,
                      freeze_head=FLAGS.freeze_head,
                      use_bn=FLAGS.use_bn,
                      use_sep_net=FLAGS.use_sep_net,
                      restore_model=FLAGS.restore_model,
                      restore_from=FLAGS.restore_from,
                      restore_to=FLAGS.restore_to,
                      load_latest=FLAGS.load_latest,
                      add_image=FLAGS.add_image,
                      partial_restore=FLAGS.partial_restore,
                      weighted_sum_type=FLAGS.weighted_sum_type,
                      initial_type=FLAGS.initial_type)

    agent = mini_source_agent.MiniSourceAgent(
        index=-1,
        net=Net,
        restore_model=FLAGS.restore_model,
        rl_training=FLAGS.training,
        ob_space_add=FLAGS.ob_space_add)

    print("Parameter server: waiting for cluster connection...")
    sess.run(tf.report_uninitialized_variables())
    print("Parameter server: cluster ready!")

    print("Parameter server: initializing variables...")
    agent.init_network()
    print("Parameter server: variables initialized")

    update_counter = 0
    max_win_rate = 0.
    latest_win_rate = 0.

    while update_counter < TRAIN_ITERS:
        agent.reset_old_network()

        # wait for update
        Synchronizer.wait()
        logging("Update Network!")
        # TODO count the time , compare cpu and gpu
        time.sleep(1)

        # update finish
        Synchronizer.wait()
        logging("Update Network finished!")

        steps, win_rate = agent.update_summary(update_counter)
        logging("Steps: %d, win rate: %f" % (steps, win_rate))

        update_counter += 1
        if win_rate >= max_win_rate:
            agent.save_model()
            max_win_rate = win_rate

        latest_win_rate = win_rate
        agent.net.save_latest_policy()

    return max_win_rate, latest_win_rate
def run_thread(agent, game_num, Synchronizer, difficulty):
    global UPDATE_EVENT, ROLLING_EVENT, Counter, Waiting_Counter, Update_Counter, Result_List

    num = 0
    all_num = 0
    proc_name = mp.current_process().name

    C._FPS = 22.4 / FLAGS.step_mul  # 5.6
    step_mul = FLAGS.step_mul  # 4
    if difficulty == 'A':
        C.difficulty = 10
    else:
        C.difficulty = difficulty
    with sc2_env.SC2Env(map_name=FLAGS.map,
                        agent_race=FLAGS.agent_race,
                        bot_race=FLAGS.bot_race,
                        difficulty=difficulty,
                        step_mul=step_mul,
                        score_index=-1,
                        game_steps_per_episode=MAX_AGENT_STEPS,
                        screen_size_px=(FLAGS.screen_resolution,
                                        FLAGS.screen_resolution),
                        minimap_size_px=(FLAGS.minimap_resolution,
                                         FLAGS.minimap_resolution),
                        visualize=False,
                        game_version=FLAGS.game_version) as env:
        # env = available_actions_printer.AvailableActionsPrinter(env)
        agent.set_env(env)

        while all_num != game_num * TRAIN_ITERS:
            agent.play_right_add(verbose=FLAGS.debug_mode)

            if FLAGS.training:
                # check if the num of episodes is enough to update
                num += 1
                all_num += 1
                reward = agent.result['reward']
                Counter += 1
                Result_List.append(reward)
                logging(
                    "(diff: %d) %d epoch: %s get %d/%d episodes! return: %d!" %
                    (int(C.difficulty), Update_Counter, proc_name,
                     len(Result_List), game_num * THREAD_NUM, reward))

                # time for update
                if num == game_num:
                    num = 0
                    ROLLING_EVENT.clear()
                    # worker stops rolling, wait for update
                    if agent.index != 0 and THREAD_NUM > 1:
                        Waiting_Counter += 1
                        if Waiting_Counter == THREAD_NUM - 1:  # wait for all the workers stop
                            UPDATE_EVENT.set()
                        ROLLING_EVENT.wait()

                    # update!
                    else:
                        if THREAD_NUM > 1:
                            UPDATE_EVENT.wait()

                        Synchronizer.wait(
                        )  # wait for other processes to update

                        agent.update_network(Result_List)
                        Result_List.clear()
                        agent.global_buffer.reset()

                        Synchronizer.wait()

                        Update_Counter += 1

                        # finish update
                        UPDATE_EVENT.clear()
                        Waiting_Counter = 0
                        ROLLING_EVENT.set()

            if FLAGS.save_replay:
                env.save_replay(FLAGS.replay_dir)

            agent.reset()
Ejemplo n.º 22
0
def Parameter_Server(Synchronizer, cluster, log_path, model_path, procs):
    config = tf.ConfigProto(
        allow_soft_placement=True,
        log_device_placement=False,
    )
    config.gpu_options.allow_growth = True
    server = tf.train.Server(cluster,
                             job_name="ps",
                             task_index=0,
                             config=config)
    sess = tf.Session(target=server.target, config=config)
    summary_writer = tf.summary.FileWriter(log_path)
    Net = MiniNetwork(sess=sess,
                      summary_writer=summary_writer,
                      rl_training=FLAGS.training,
                      cluster=cluster,
                      index=0,
                      device=DEVICE[0 % len(DEVICE)],
                      ppo_load_path=FLAGS.restore_model_path,
                      ppo_save_path=model_path)
    Sec_Net = SecondNetwork(sess=sess,
                            rl_training=False,
                            reuse=True,
                            cluster=None,
                            index=0,
                            load_model=True,
                            net_path_name=net_path_name)

    agent = mini_source_agent.MiniSourceAgent(
        index=-1,
        net=Net,
        sec_net=Sec_Net,
        restore_model=FLAGS.restore_model,
        rl_training=FLAGS.training)

    print("Parameter server: waiting for cluster connection...")
    sess.run(tf.report_uninitialized_variables())
    print("Parameter server: cluster ready!")

    print("Parameter server: initializing variables...")
    agent.init_network()
    print("Parameter server: variables initialized")

    update_counter = 0
    max_win_rate = 0.
    while update_counter < TRAIN_ITERS:
        agent.reset_old_network()

        # wait for update
        Synchronizer.wait()
        logging("Update Network!")
        # TODO count the time , compare cpu and gpu
        time.sleep(1)

        # update finish
        Synchronizer.wait()
        logging("Update Network finished!")

        steps, win_rate = agent.update_summary(update_counter)
        logging("Steps: %d, win rate: %f" % (steps, win_rate))

        update_counter += 1
        if win_rate >= max_win_rate:
            agent.save_model()
            max_win_rate = win_rate

    return max_win_rate
Ejemplo n.º 23
0
def adjust_learning_rate(optimizer, epoch):
    """Sets the learning rate to the initial LR decayed by 10 every 30 epochs"""
    lr = learning_rate * (0.1**(epoch // 50))
    for param_group in optimizer.param_groups:
        param_group['lr'] = lr
    logging('set lr=%f' % (lr))
Ejemplo n.º 24
0
 def __init__(self, _inputF):
     lg.logging('Start Initialing %s' % (self.__class__.__name__),
                'SPECIAL')
     HCB.HtbConfigBase.__init__(self, _inputF)
     self.SearchFile()
Ejemplo n.º 25
0
 def __init__(self, _inputF):
     lg.logging(
         'Start Initialing %s' % (self.__class__.__name__), 'SPECIAL'
     )
     HCB.HtbConfigBase.__init__(self, _inputF)
     self.SearchFile()
Ejemplo n.º 26
0
 def __repr__(self):
     logging('INF', 'Вывод объектов класса Person (и его наследников)')
     #return u'<{c} name={n}>'.format(c=self.__class__.__name__, n=self.name).encode('utf-8')
     #return self.__class__.__name__
     return "{} {}".format(self.firstName, self.lastName)
Ejemplo n.º 27
0
import machine
from network import WLAN
from microWebCli import MicroWebCli
from logging import logging

uart = UART(0, 115200)
os.dupterm(uart)

_SSID = "NETGEAR55"
_TIMEZONE_URL = 'http://api.timezonedb.com/v2/get-time-zone?key=1QNTARL4R9XW&by=zone&zone=Europe/Rome&format=json'

wlan = WLAN(mode=WLAN.STA)
wlan.ifconfig(config=('192.168.0.5', '255.255.255.0', '192.168.0.1',
                      '8.8.8.8'))

if not wlan.isconnected():
    wlan.connect(_SSID, auth=(WLAN.WPA2, 'phobiccoconut688'), timeout=5000)
    while not wlan.isconnected():
        machine.idle()  # save power while waiting

logging('WLAN connection succeeded!')
logging("My IP address is: {0}".format(wlan.ifconfig()[0]))

try:
    contentBytes = MicroWebCli.JSONRequest(_TIMEZONE_URL)
    tuple_data = contentBytes['timestamp']
    machine.RTC(datetime=utime.localtime(tuple_data))
    logging("Real Time Clock updated.")
except Exception as e:
    logging("Real Time Clock updating failed. Error: {0}".format(e))
Ejemplo n.º 28
0
 def countOfReader(self):
     logging('INF', 'Получение количества читателей')
     # return Reader.listOfReader.len()
     return len(self)
Ejemplo n.º 29
0
 def __str__(self):
     logging('INF', 'Печать основной информации о читателе')
     s = "{} {}, возраст: {}, номер читательского билета: {}".format(
         self.firstName, self.lastName, self.age, self.readerListNumber)
     #Reader.listOfReader.append(s)
     return s
Ejemplo n.º 30
0
 def printReaderList(self):
     logging('INF', 'Печать читательского билета')
     for i in self.readerList:
         #print(self.readerList[i])
         print('Номер книги: {}. Дата: {}'.format(i, self.readerList[i]))
Ejemplo n.º 31
0
 def __init__(self, arg_firstName, arg_lastName, arg_age):
     logging('CRE', 'Создан объект класса Person')
     self.firstName = arg_firstName
     self.lastName = arg_lastName
     self.age = arg_age
Ejemplo n.º 32
0
 def newBook(self, arg_BookNumber, arg_date):
     logging('INF', 'Добавлена новая книга в читательский билет')
     #self.readerList = {'BookNumber': arg_BookNumber ,'date': arg_date}
     #self.readerList['BookNumber'] = arg_BookNumber
     #self.readerList['date'] = arg_date
     self.readerList[arg_BookNumber] = arg_date
Ejemplo n.º 33
0
 def getDate(self, BookNumber):
     logging('INF', 'Получена дата по номеру книги')
     return (self.readerList[BookNumber])
def Parameter_Server(Synchronizer, cluster, log_path, model_path, procs):
    config = tf.ConfigProto(
        allow_soft_placement=True,
        log_device_placement=False,
    )
    config.gpu_options.allow_growth = True
    server = tf.train.Server(cluster,
                             job_name="ps",
                             task_index=0,
                             config=config)
    #config.gpu_options.per_process_gpu_memory_fraction = 0.2
    sess = tf.Session(target=server.target, config=config)
    summary_writer = tf.summary.FileWriter(log_path)
    mini_net = MiniNetwork(sess,
                           index=0,
                           summary_writer=summary_writer,
                           rl_training=True,
                           cluster=cluster,
                           ppo_load_path=FLAGS.restore_model_path,
                           ppo_save_path=model_path,
                           freeze_head=FLAGS.freeze_head,
                           use_bn=FLAGS.use_bn,
                           use_sep_net=FLAGS.use_sep_net,
                           restore_model=FLAGS.restore_model,
                           restore_from=FLAGS.restore_from,
                           restore_to=FLAGS.restore_to)

    agent = MiniAgent(agent_id=-1,
                      global_buffer=Buffer(),
                      net=mini_net,
                      restore_model=FLAGS.restore_model)

    print("Parameter server: waiting for cluster connection...")
    sess.run(tf.report_uninitialized_variables())
    print("Parameter server: cluster ready!")

    print("Parameter server: initializing variables...")
    agent.init_network()
    print("Parameter server: variables initialized")

    last_win_rate = 0.

    update_counter = 0
    while update_counter < TRAIN_ITERS:
        agent.reset_old_network()

        # wait for update
        Synchronizer.wait()
        logging("Update Network!")
        # TODO count the time , compare cpu and gpu
        time.sleep(1)

        # update finish
        Synchronizer.wait()
        logging("Update Network finished!")

        steps, win_rate = agent.update_summary(update_counter)
        logging("Steps: %d, win rate: %f" % (steps, win_rate))

        update_counter += 1
        if win_rate >= last_win_rate:
            agent.save_model()

        last_win_rate = win_rate
    for p in procs:
        print('Process terminate')
        p.terminate()