def validate_account_stake(snapshot, balances, args):
    step('Verifying user account stake')
    invalid_stake = 0
    print_count = 0
    total_accounts = len(balances)

    for account in balances:

        total = asset2int(balances[account][CSV_EOS_BALANCE])

        liquid, net, cpu = get_account_stake(snapshot, account,
                                             args.core_symbol)

        # TODO: validate F(stake) ?
        if total != liquid + cpu + net:
            print_count = print_some(
                print_count,
                '{0} => TOTAL: [{1}] L:[{2}] C:[{3}] N:[{4}]'.format(
                    account, total, liquid, cpu, net))
            invalid_stake += 1

    if invalid_stake > 0:
        print "> %d accounts with invalid stake" % (invalid_stake)
    else:
        success()

    return True
Beispiel #2
0
def validate_system_accounts(snapshot):

    step('Verifying system accounts')

    found = []
    for name, account in snapshot['accounts'].iteritems():
        tick()
        if name in system_accounts:

            if account['privileged'] != system_accounts[name]['privileged']:
                fail()
                print "> %s account wrong privileged setting" % (name)
                return False

            # Verify resignement
            if name != "eosio.null" and name != "eosio.prods":
                actor = system_accounts[name]['actor']
                permission = system_accounts[name]['permission']
                if authority_controlled_by_one_actor(account['permissions']["owner"], actor, permission) != True or \
                   authority_controlled_by_one_actor(account['permissions']["owner"], actor, permission) != True:
                    fail()
                    print "> %s account NOT PROPERLY RESIGNED" % (name)
                    return False

            found.append(name)

    not_found = set(system_accounts.keys()) - set(found)
    if len(not_found):
        fail()
        print "> missing system accounts %s" % (','.join(not_found))
        return False

    success()
    return True
def monitor_progress(software):
    """Until all nodes are complete, monitor and print the status of the upgrade"""

    step("Watch the progress")

    errors = 0
    with LiveMultilineOutput() as output:
        while True:
            try:
                software.get(fields="state,status_details,elapsed_duration,estimated_duration")
                if not software.state == "in_progress":
                    break
                errors = 0
                new_list = []
                for detail in software.status_details:
                    new_list.append(
                        "[%s]: %s - %s"
                        % (detail.node.name, detail.name, detail.issue.message)
                    )
                percent_complete = (
                    software.elapsed_duration / software.estimated_duration
                ) * 100
                new_list.append("%.2f%% complete (estimate)" % percent_complete)
                output.change(new_list)
            except Exception:  # pylint: disable=broad-except
                errors += 1
                if errors > 10:
                    break
            finally:
                time.sleep(30)
    if errors > 10:
        raise RuntimeError("ERROR: No longer could communicate with the server. Is it down?")
def validate_EOS_token(snapshot, args):

    step('Verifying EOS token')

    symbol = args.core_symbol
    key = name_to_string(symbol2int(symbol), False)
    sym = str(symbol2int(symbol))

    eos_token = snapshot['tables']['eosio.token'][key]['stat'][sym]['data']

    ok = True
    if asset2int(eos_token['max_supply']) != 100000000000000:
        if ok:
            warning()
            ok = False
        print "> EOS max supply != 10000M (%s)" % eos_token['max_supply']

    tokens = 0
    code = snapshot['tables']['eosio.token']
    for s in code:
        if 'stat' in code[s]: tokens += 1

    if tokens != 1:
        if ok:
            warning()
            ok = False
        print "> more than one token found in eosio.token"

    if ok:
        success()

    return True
def visualize(seq, env, env_path, v_t, policy, T, task, goal):
    for t in range(T):
        # basic info
        pos = env.agent_pos
        vec = dir2num(env.dir_vec)
        front_cell = env.front_pos  # Get the cell in front of the agent
        print("time:{t}, state: {p},{v}".format(t=t, p=pos, v=vec))
        if task == 'Key':
            # the key is in front of the agent
            if what(front_cell, env) == 'Key':
                seq.append(PK)
                cost, done = step(env, PK)
                print("----get Key----")
                return seq

        if task == 'Door':
            # the door is in front of the agent
            if what(front_cell, env) == 'Door':
                seq.append(UD)
                cost, done = step(env, UD)
                seq.append(MF)
                cost, done = step(env, MF)
                print("----unlock the door----")
                return seq

        # read the corresponding policy given current position
        control = policy[pos[0], pos[1], vec, t]
        print("next move: {c}".format(c=c_dict[control]))
        seq.append(control)
        cost, done = step(env, control)

        if done:
            print("Reached Goal")
            return seq
Beispiel #6
0
def validate_genesis(snapshot, genesis):
    step('Validating genesis')
    ddiff = DictDiffer(snapshot['genesis_state'], genesis)
    added = ddiff.added()
    removed = ddiff.removed()
    changed = ddiff.changed()

    if len(added) != 0 or len(removed) != 0 or len(changed) != 0:
        fail()
        if len(added) != 0:
            print "> Snapshot has '%s' and your genesis dont" % (
                ','.join(added))
        if len(removed) != 0:
            print "> Your genesis has %s and snapshot dont" % (
                ','.join(removed))
        if len(changed) != 0:
            print "> Your genesis and snapshot have different '%s'" % (
                ','.join(changed))

        print "# Snapshot genesis"
        print json.dumps(snapshot['genesis_state'], indent=2, sort_keys=True)
        print
        print "# Your genesis"
        print json.dumps(genesis, indent=2, sort_keys=True)
        return False

    success()
    return True
Beispiel #7
0
    def import_timetable(self):
        print()

        for unit in self.units:
            if not self.import_timetable_for_unit(unit):
                return False
            else:
                utils.step("Przetwarzam plan lekcji klasy {}".format(unit),
                           state=" OK ")

        return True
def load_erc20_snapshot(args):
    step('Loading ETH snapshot')
    with open(args.csv_balance, 'rb') as csvfile:
        balances = {}
        for row in csv.reader(csvfile, delimiter=','):
            tick()
            row = [unicode(i) for i in row]
            row[CSV_EOS_BALANCE] = '{0} {1}'.format(row[CSV_EOS_BALANCE],
                                                    args.core_symbol)
            balances[row[CSV_EOS_ACCOUNT]] = row
    success()
    return balances
def show_current_cluster_image():
    """Verify our current software status"""

    step("Show the packages")
    substep("Show the current cluster image")
    software = Software()
    software.get()
    print("Current software package:", software)

    substep("Show the available software packages")
    print("Available software packages:", list(SoftwarePackage.get_collection()))
    return software
    def run(self):
        """
        Run the network simulation by evaluating model equations at every time
        step.
        """
        # integration constant
        rho_a = 1./(self.stim_len)

        # simulation time
        time = np.arange(0, self.t_max)

        for t in time[1:]:
            # stop simulation if target found or max guesses
            if self._terminate_condition(t):
                break

            #  ----- Semantic Layer -----
            # winning/active units
            self.z[t-1] = step(self.w[t-1], self.theta_w)

            # unit activities
            self.a[t] = self.a[t-1] + rho_a*(mult(self.W,
                                                  self.z[t-1],
                                                  self.a[t-1]) +
                                             self.I[t-1])
            # ----- WTA Layer -----
            eta = np.random.random(self.N) - self.noise_offset

            # normalise activities to 0-1
            divisor = np.max([1., self.a[t-1].max()])

            self.w[t] = self.w[t-1] + self.rho_w * \
                (self.c1*self.z[t-1] +
                 self.c2*self.a[t-1]/divisor -
                 self.c3*self.y[t-1] -
                 self.c4*self.r[t-1] +
                 self.c5*eta)

            self.y[t] = self.z[t-1].sum()

            # ----- Inhibitory Layer -----
            # -2 added because of discreete update lags
            self.r[t] = (self.r[t-1] +
                         step(self.z[t-self.stim_len:t].sum(axis=0),
                              self.stim_len-2)).clip(max=1)

            # several winners are not allowed
            if self.y[t] > 1:
                raise Exception('Multiple winners')

            # rectify WTA activities to 0 (if needed)
            self.w[t] = self.w[t].clip(min=0)
Beispiel #11
0
    def run(self):
        """
        Run the network simulation by evaluating model equations at every time
        step.
        """
        # integration constant
        rho_a = 1. / (self.stim_len)

        # simulation time
        time = np.arange(0, self.t_max)

        for t in time[1:]:
            # stop simulation if target found or max guesses
            if self._terminate_condition(t):
                break

            #  ----- Semantic Layer -----
            # winning/active units
            self.z[t - 1] = step(self.w[t - 1], self.theta_w)

            # unit activities
            self.a[t] = self.a[t - 1] + rho_a * (
                mult(self.W, self.z[t - 1], self.a[t - 1]) + self.I[t - 1])
            # ----- WTA Layer -----
            eta = np.random.random(self.N) - self.noise_offset

            # normalise activities to 0-1
            divisor = np.max([1., self.a[t - 1].max()])

            self.w[t] = self.w[t-1] + self.rho_w * \
                (self.c1*self.z[t-1] +
                 self.c2*self.a[t-1]/divisor -
                 self.c3*self.y[t-1] -
                 self.c4*self.r[t-1] +
                 self.c5*eta)

            self.y[t] = self.z[t - 1].sum()

            # ----- Inhibitory Layer -----
            # -2 added because of discreete update lags
            self.r[t] = (self.r[t - 1] +
                         step(self.z[t - self.stim_len:t].sum(axis=0),
                              self.stim_len - 2)).clip(max=1)

            # several winners are not allowed
            if self.y[t] > 1:
                raise Exception('Multiple winners')

            # rectify WTA activities to 0 (if needed)
            self.w[t] = self.w[t].clip(min=0)
def validate_memory(snapshot):

    step('Verifying 64Gb max ram size')

    table = snapshot['tables']['eosio']['eosio']['global']
    params = table[table.keys()[0]]['data']

    max_ram_size = int(params["max_ram_size"]) >> 30
    if max_ram_size != 64:
        warning()
        print "> Max ram size != 64Gb : (%d)" % max_ram_size
    else:
        success()

    return True
def update_cluster_image(software, new_package):
    """Set the new version of the software on the cluster"""

    step("Update the cluster to the new image")
    software.version = new_package.version
    try:
        if Node.count_collection() > 1:
            # make sure cluster HA is enabled
            cli = CLI()
            cli.execute("cluster ha modify", body={"configured": "true"})
        software.patch(poll_timeout=1200, poll_interval=30, skip_warnings="true")
    except NetAppRestError:
        print("Current cluster software status:")
        software.get()
        pprint(software)
def validate_no_privileged_accounts(snapshot):
    step('Verifying privileged accounts')

    privileged_accounts = []
    for sa in system_accounts:
        if system_accounts[sa]['privileged']:
            privileged_accounts.append(sa)

    for name in snapshot['accounts']:
        if snapshot['accounts'][name][
                'privileged'] and name not in privileged_accounts:
            warning()
            print "> Invalid privileged account found : %s" % name
    else:
        success()
    return True
Beispiel #15
0
def validate_account_permissions(snapshot, balances):

    step('Verifying user account permission')
    accounts = snapshot['accounts']
    invalid_perm = 0
    for account in balances:
        perms = snapshot['accounts'][account]['permissions']
        if authority_controlled_by_one_key(perms["active"], balances[account][CSV_EOS_ADDR]) != True or \
           authority_controlled_by_one_key(perms["owner"], balances[account][CSV_EOS_ADDR]) != True:
            invalid_perm += 1

    if invalid_perm > 0:
        warning()
        print "> %d accounts with invalid permission" % (with_code)
    else:
        success()
Beispiel #16
0
 def MCTS_search(self, state: str, history: list, last_action: tuple):
     """
     以state为根节点进行MCTS搜索,搜索历史保存在histoty之中
     :param state: 一个字符串代表的当前状态,根节点
     :param history: 包含当前状态的一个列表
     :param last_action: 上一次的落子位置
     :return:
     """
     while True:
         board = utils.state_to_board(state, self.config.board_size)
         game_over, v = utils.is_game_over(board, self.goal)  # 落子前检查game over
         if game_over:
             self.update_tree(v, history=history)
             break
         if state not in self.tree:
             # 未出现过的state,则评估然后展开
             v = self.evaluate_and_expand(state, board, last_action)  # 落子前进行评估
             self.update_tree(v, history=history)
             break
         sel_action = self.select_action_q_and_u(state)  # 根据state选择一个action
         history.append(sel_action)  # 放进action
         board = utils.step(board, sel_action)
         state = utils.board_to_state(board)
         history.append(state)
         last_action = sel_action
Beispiel #17
0
    def run(self, e=0.25):
        """
        对弈一局,获得一条数据,即从初始到游戏结束的一条数据
        :return:
        """
        state = self.get_init_state()
        game_over = False
        data = []  # 收集(状态,动作)二元组
        value = 0
        last_action = None
        while not game_over:
            policy, action = self.get_action(state, e, last_action)
            data.append((state, policy, last_action))  # 装初始局面不装最终局面,装的是动作执行之前的局面
            board = utils.step(utils.state_to_board(state, self.config.board_size), action)
            state = utils.board_to_state(board)
            # self.pruning_tree(board, state)  # 走完一步以后,对其他分支进行剪枝,以节约内存;注释掉,以节约时间
            game_over, value = utils.is_game_over(board, self.goal)
            # assert value != 1.0
            last_action = action

        self.reset()  # 把树重启
        turns = len(data)
        if turns % 2 == 1:
            value = -value
        weights = utils.construct_weights(turns, gamma=self.config.gamma)
        final_data = []
        for i in range(turns):
            final_data.append((*data[i], value, weights[i]))  # (状态,policy,last_action, value, weight)
            value = -value
        return final_data
Beispiel #18
0
def validate_no_code_in_accounts(snapshot, balances):
    step('Verifying user account code')
    with_code = 0
    for account in balances:
        tick()
        acnt = snapshot['accounts'][account]
        if int('0x'+acnt['code_version'],16) != 0 or \
           acnt['abi'] != "" or \
           acnt['vm_type'] != 0 or \
           acnt['vm_version'] != 0:
            with_code += 1
    if with_code > 0:
        warning()
        print "> %d accounts with code set" % (with_code)
    else:
        success()
Beispiel #19
0
def validate_EOS_token(snapshot, balances, args):

    step('Verifying EOS token')

    symbol = args.core_symbol
    key = name_to_string(symbol2int(symbol), False)
    sym = str(symbol2int(symbol))

    eos_token = snapshot['tables']['eosio.token'][key]['stat'][sym]['data']

    ok = True
    if asset2int(eos_token['max_supply']) != 100000000000000:
        if ok:
            warning()
            ok = False
        print "> EOS max supply != 10000M (%s)" % eos_token['max_supply']

    # Calc supply:
    def EOS_for_N_buys_of_8k_ram(N):
        return int(round(10000.0 * float((10**6) * N / ((2**23) - N))))

    # 163928 number of registered accounts in final snapshot
    expected_supply = 10000000000000 + EOS_for_N_buys_of_8k_ram(163928)

    if abs(asset2int(eos_token['supply']) - expected_supply) > 20000:
        if ok:
            warning()
            ok = False
        print "> EOS supply %s != %s" % (eos_token['max_supply'],
                                         int2asset(expected_supply, "EOS"))

    tokens = 0
    code = snapshot['tables']['eosio.token']
    for s in code:
        if 'stat' in code[s]: tokens += 1

    if tokens != 1:
        if ok:
            warning()
            ok = False
        print "> more than one token found in eosio.token"

    if ok:
        success()

    return True
def delete_account():
    """Delete the User"""

    step("Delete the limited account and role")
    show_account()
    accname = input(
        "Enter the name of the Account that needs to be deleted:- ")
    try:
        account = Account.find(name=accname)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))

    substep("Delete our %s account" % accname)
    try:
        account.delete()
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Beispiel #21
0
def validate_global_params_against_genesis(snapshot, genesis):

    step('Verifying global params vs genesis')

    table = snapshot['tables']['eosio']['eosio']['global']
    params = table[table.keys()[0]]['data']

    diff = []
    for gp in genesis['initial_configuration']:
        if genesis['initial_configuration'][gp] != params[gp]:
            diff.append(gp)

    if len(diff):
        warning()
        print "Global params different from genesis : %s" % diff
    else:
        success()
    return True
def download_new_cluster_image(parsed_args: argparse.Namespace):
    """Start our HTTP server and tell ONTAP to start downloading the new image"""

    step("Download a new software package")
    substep("Start an HTTP server to serve the file")
    image_server = Thread(target=serve_image_download, args=(parsed_args,))
    image_server.start()

    substep("Have ONTAP download the package")
    local_ip = socket.gethostbyname(socket.gethostname())
    url = "http://%s:%s/%s" % (local_ip, parsed_args.port, parsed_args.image_path)
    download_package = SoftwarePackageDownload(url=url)
    download_package.post(poll_timeout=1200, poll_interval=60)
    image_server.join()

    substep("Show the new package")
    packages = list(SoftwarePackage.get_collection())
    print("Available software packages:", packages)
    return packages[0]
def update_account():
    """Module to update the account details with new role"""

    step("Update the account with new roles")
    show_account()
    accname = input(
        "Enter the name of the Account that needs to be updated with the new role:- "
    )
    try:
        account = Account.find(name=accname)
    except NetAppRestError as error:
        print("Exception caught :" + str(error))

    print("======================")
    substep("Create the new role")
    rolename = input("Enter the name of the Role to be created:- ")
    privpath = input(
        "Enter the name of the Command Directoey PATH [eg: /api/storage/volume]:- "
    )
    pathaccess = input(
        "Enter the Access for the Command Directory PATH [none/all/readonly]:- "
    )
    role = Role(
        name=rolename,
        privileges=[
            RolePrivilege(access=pathaccess, path=privpath),
        ],
    )
    try:
        role.post()
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
    print("New role created: %s" % rolename)

    substep("Assign the test account to the test role")
    account.role = role
    try:
        account.patch()
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
    print("======================")
    print("Account updated with the new role: %s" % account)
def validate_account_creation(snapshot, balances):
    found_users = {}
    print_count = 0

    step('Verifying user account creation')
    for account in balances.keys():
        tick()
        if account not in snapshot['accounts']:
            print_count = print_some(print_count, account)
            continue
        found_users[account] = balances[account]

    not_found = len(balances) - len(found_users)
    if not_found:
        print "> %d (out of %d) accounts were not found in the EOS snapshot" % (
            not_found, len(balances))
    else:
        success()

    return found_users
def load_eos_snapshot(args):
    step('Loading EOS snapshot')
    with open(args.snapshot) as file:
        snapshot = json.load(file)

        # Convert list to dictionary
        accounts = {}
        for acc in snapshot['accounts']:
            tick()
            accounts[acc['name']] = acc
        snapshot['accounts'] = accounts

        # Add permissions to account dict
        for perm in snapshot['permissions']:
            tick()
            if perm['id']['_id'] == 0: continue
            owner = perm['owner']
            if owner not in snapshot['accounts']:
                raise ValidationException(
                    "invalid snapshot: permission owner not found")
            if 'permissions' not in snapshot['accounts'][owner]:
                snapshot['accounts'][owner]['permissions'] = {}
            snapshot['accounts'][owner]['permissions'][perm['name']] = perm

        # Tables
        tables = {}
        for t in snapshot['tables']:
            tick()
            code = t['tid']['code']
            scope = t['tid']['scope']
            table = t['tid']['table']
            if code not in tables:
                tables[code] = {}
            if scope not in tables[code]:
                tables[code][scope] = {}
            tables[code][scope][table] = t['rows']
        snapshot['tables'] = tables

    success()
    return snapshot
Beispiel #26
0
def generate_episode(pi, returns, counts, epsilon, start_from=None):
    """
    generates an episode in a uniformly chosen random state and random action
    then follows policy pi
    updates returns and counts
    first visit variant
    """
    assert (np.array_equal(pi[0, :], np.zeros(n + 1)))
    assert (np.allclose(pi.sum(axis=0)[1:], np.ones(n)))

    sample_uniform_action = lambda s: np.random.choice(s) + 1  # from 1 to s
    if start_from:
        s, a = start_from
        if a == None:
            a = sample_uniform_action(s)
    else:
        s = np.random.choice(n - 1) + 1  # from 1 to n-1
        a = sample_uniform_action(s)

    def eps_greedy_sample_action(s):
        greedy = np.random.choice(2, p=[epsilon, 1 - epsilon])
        if not greedy:
            return sample_uniform_action(s)
        else:
            return np.random.choice(n + 1, p=pi[:, s])  # from greedy policy pi

    states = [s]
    actions = [a]
    rewards = [0]
    first_visited = np.ones(n + 1, dtype=int) * (-1)

    while s != n and s != 0:
        if first_visited[s] == -1:
            first_visited[s] = len(states) - 1
        s_n, r = step(s, a, p_h, n)
        states.append(s_n)
        rewards.append(r)
        if s_n != 0 and s_n != n:
            actions.append(eps_greedy_sample_action(s_n))
        else:
            actions.append(0)
        s = states[-1]
        a = actions[-1]

    for s, t in enumerate(first_visited):
        if t == -1:  # never visited
            continue
        a = actions[t]
        returns[a, s] += sum(rewards[t + 1:])
        if first_visited[s] == t:
            counts[a, s] += 1
Beispiel #27
0
    def _get_reward(self, offset=3):
        golden_standard_db = self.golden_standard_db

        data_cur = []

        if golden_standard_db[0][0] is None:
            print("THE GOLD STANDARD IS MORE LIKE SILVER...[?] HMMM")
            #print(self.current_data)
            #print(self.golden_standard_db)
            try:
                sys.exit(-1)
            except SystemExit:
                os._exit(-2)
        else:
            tmp = golden_standard_db[0][0].lower().replace(' ', '')

        golden_standard_db = [(tmp, golden_standard_db[0][1])]
        """
        data_cur.append((tup[0][0].lower().replace(' ', ''), tup[0][1]))AttributeError: 'spacy.tokens.span.Span' object has no attribute 'lower'
        """

        for tup in self.current_db:
            data_cur.append((str(tup[0][0]).lower().replace(' ',
                                                            ''), tup[0][1]))

        a = set(golden_standard_db)

        if len(a) == 0:
            print("Well josue, the world is weird")
            try:
                print("ERROR IN THE FUNCTION _get_reward()")
                sys.exit(-1)
            except SystemExit:
                os._exit(-2)

        # TODO: PA: it shouldn't be the extracted NER from the snippet in self.current_data ?
        b = set(data_cur)

        # Jaccard index - penalty
        # penalty =  e^(alpha * len(b)) * u(len(b)-offset) + min (edit_distance(A,B)) / len(A_content)
        edit_vect = np.array(utils.edit_distance(a, b))  # Range: [0, inf)

        penalty = m.pow(
            m.e, self.alpha_reward * len(b)) * utils.step(len(b) - offset)
        penalty += edit_vect.mean() / utils.len_content(a)
        reward_cur = (len(a.intersection(b)) / len(a.union(b))) - penalty

        reward = reward_cur - self.reward_prev
        self.reward_prev = reward_cur

        return reward
def validate_genesis(snapshot, genesis):
    step('Validating genesis')
    ddiff = DictDiffer(snapshot['genesis_state'], genesis)
    added = ddiff.added()
    removed = ddiff.removed()
    changed = ddiff.changed()

    if len(added) != 0 or len(removed) != 0 or len(changed) != 0:
        warning()
        tmp = tempfile.mkstemp()[1]
        with open(tmp, 'w') as out:
            if len(added) != 0:
                out.write("> Snapshot has '%s' and your genesis dont\n" %
                          (','.join(added)))
            if len(removed) != 0:
                out.write("> Your genesis has %s and snapshot dont\n" %
                          (','.join(removed)))
            if len(changed) != 0:
                out.write("> Your genesis and snapshot have different '%s'\n" %
                          (','.join(changed)))

            out.write('\n')
            out.write("# Snapshot genesis\n")
            out.write(
                json.dumps(snapshot['genesis_state'], indent=2,
                           sort_keys=True))
            out.write('\n')
            out.write("# Your genesis\n")
            out.write(json.dumps(genesis, indent=2, sort_keys=True))
            out.write('\n')

        print "> please check %s for details" % tmp
    else:
        success()

    return True
def main() -> None:
    """Main function"""

    arguments = [
        Argument("-c",
                 "--cluster",
                 "API server IP:port details",
                 required=True),
        Argument(
            "-a",
            "--cert_account",
            "Account which be used for certificate authentication",
            default="admin",
        ),
        Argument(
            "-o",
            "--organization",
            "Organization name for the root certificate",
            default="MyCompany",
        )
    ]
    args = parse_args(
        "This script will enable certificate authentication on the provided account (or admin)",
        arguments,
    )
    setup_logging()
    setup_connection(args.cluster, args.api_user, args.api_pass)

    # make a temp directory for certs to live in
    dirpath = tempfile.mkdtemp()

    step("Install a root CA for %s" % args.organization)
    my_ca = install_cert(args)

    step("Sign a CSR for cert_user with our root")
    sign_domain(my_ca, dirpath, args)

    step("Install signed cert as client-ca")
    enable_cert_auth(args)

    step("Verify cert auth works for our user")
    test_cert_auth(args, dirpath)
Beispiel #30
0
def make_preds(dataset, encoder, decoder, dictionary, batch_size,
               cuda, max_length):

    # Turn on evaluation mode which disables dropout.
    encoder.eval()
    decoder.eval()

    utils.set_gradient(encoder, False)
    utils.set_gradient(decoder, False)

    pred_corpus_tokens = []
    gold_corpus_tokens = []
    start_time = time.time()

    minibatches = utils.minibatch_generator(batch_size, dataset, cuda)
    for n_batch, batch in enumerate(minibatches):

        _, pred, _ = utils.step(encoder, decoder, batch, None, False, args,
                                beam_size=args.beam_size)

        # true target
        gold = batch[1].data

        for i in xrange(pred.size(1)):
            # get tokens from the predicted iindices
            pred_tokens = [dictionary.idx2word[x] for x in pred[:, i]]
            gold_tokens = [dictionary.idx2word[x] for x in gold[:, i]]

            # filter out u'<pad>', u'<eos>'
            filter_tokens = [u'<pad>', u'<eos>']
            pred_tokens = filter(lambda x: x not in filter_tokens, pred_tokens)
            gold_tokens = filter(lambda x: x not in filter_tokens, gold_tokens)

            pred_corpus_tokens.append(pred_tokens)
            gold_corpus_tokens.append(gold_tokens)

        if n_batch % args.log_interval == 0 and n_batch > 0:
            elapsed = time.time() - start_time
            print('| {:5d}/{:5d} batches | ms/batch {:5.2f} |'.format(
                  n_batch, len(dataset[0]) // args.batch_size, 
                  elapsed * 1000 / args.log_interval))
            start_time = time.time()

    return pred_corpus_tokens, gold_corpus_tokens
Beispiel #31
0
 def GetPath(self):
     path = []
     env = deepcopy(self.env)
     i, j, dir, hasKey, is_locked = self.init_state
     done = False
     while not done:
         action = self.policyMap[i][j][dir][hasKey][is_locked]
         path.append(action)
         _, done = step(env, action)
         i, j = env.agent_pos
         vec = env.dir_vec
         if vec[0] == 0:
             dir = 1 + vec[1]
         else:
             dir = 2 - vec[0]
         hasKey = 1 if env.carrying else 0
         is_locked = 1 if env.grid.get(
             self.info['door_pos'][0],
             self.info['door_pos'][1]).is_locked else 0
     return path