How to use for_ method in Selene

Best Python code snippet using selene_python

value_iteration_6D.py

Source:value_iteration_6D.py Github

copy

Full Screen

...9# ptsEachDim: the number of grid points in each dimension of the state space10# useNN: a mode flag (0: use linear interpolation, 1: use nearest neighbour)11def updateVopt(obj, i, j, k, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN):12 p = hcl.scalar(0, "p")13 with hcl.for_(0, actions.shape[0], name="a") as a:14 # set iVals equal to (i,j,k,l,m,n) and sVals equal to the corresponding state values (si,sj,sk,sl,sm,sn)15 updateStateVals(i, j, k, l, m, n, iVals, sVals, bounds, ptsEachDim)16 # call the transition function to obtain the outcome(s) of action a from state (si,sj,sk,sl,sm,sn)17 obj.transition(sVals, actions[a], bounds, trans, goal)18 # initialize the value of the action Q value with the immediate reward of taking that action19 intermeds[a] = obj.reward(sVals, actions[a], bounds, goal, trans)20 # add the value of each possible successor state to the Q value21 with hcl.for_(0, trans.shape[0], name="si") as si:22 p[0] = trans[si,0]23 sVals[0] = trans[si,1]24 sVals[1] = trans[si,2]25 sVals[2] = trans[si,3]26 sVals[3] = trans[si,4]27 sVals[4] = trans[si,5]28 sVals[5] = trans[si,6]29 # Nearest neighbour30 with hcl.if_(useNN[0] == 1):31 # convert the state values of the successor state (si,sj,sk,sl,sm,sn) into indeces (ia,ja,ka,la,ma,na)32 stateToIndex(sVals, iVals, bounds, ptsEachDim)33 # if (ia,ja,ka,la,ma,na) is within the state space, add its discounted value to the Q value34 with hcl.if_(hcl.and_(iVals[0] < Vopt.shape[0], iVals[1] < Vopt.shape[1], iVals[2] < Vopt.shape[2])):35 with hcl.if_(hcl.and_(iVals[3] < Vopt.shape[3], iVals[4] < Vopt.shape[4], iVals[5] < Vopt.shape[5])):36 with hcl.if_(hcl.and_(iVals[0] >= 0, iVals[1] >= 0, iVals[2] >= 0, iVals[3] >= 0, iVals[4] >= 0, iVals[5] >= 0)):37 intermeds[a] += (gamma[0] * (p[0] * Vopt[iVals[0], iVals[1], iVals[2], iVals[3], iVals[4], iVals[5]]))38 # maximize over each Q value to obtain the optimal value39 Vopt[i,j,k,l,m,n] = -100000040 with hcl.for_(0, intermeds.shape[0], name="r") as r:41 with hcl.if_(Vopt[i,j,k,l,m,n] < intermeds[r]):42 Vopt[i,j,k,l,m,n] = intermeds[r]43# Returns 0 if convergence has been reached44def evaluateConvergence(newV, oldV, epsilon, reSweep):45 delta = hcl.scalar(0, "delta")46 # Calculate the difference, if it's negative, make it positive47 delta[0] = newV[0] - oldV[0]48 with hcl.if_(delta[0] < 0):49 delta[0] = delta[0] * -150 with hcl.if_(delta[0] > epsilon[0]):51 reSweep[0] = 152# Converts state values into indeces using nearest neighbour rounding53def stateToIndex(sVals, iVals, bounds, ptsEachDim):54 iVals[0] = ((sVals[0] - bounds[0,0]) / (bounds[0,1] - bounds[0,0])) * (ptsEachDim[0] - 1)55 iVals[1] = ((sVals[1] - bounds[1,0]) / (bounds[1,1] - bounds[1,0])) * (ptsEachDim[1] - 1)56 iVals[2] = ((sVals[2] - bounds[2,0]) / (bounds[2,1] - bounds[2,0])) * (ptsEachDim[2] - 1)57 iVals[3] = ((sVals[3] - bounds[3,0]) / (bounds[3,1] - bounds[3,0])) * (ptsEachDim[3] - 1)58 iVals[4] = ((sVals[4] - bounds[4,0]) / (bounds[4,1] - bounds[4,0])) * (ptsEachDim[4] - 1)59 iVals[5] = ((sVals[5] - bounds[5,0]) / (bounds[5,1] - bounds[5,0])) * (ptsEachDim[5] - 1)60 # NOTE: add 0.5 to simulate rounding61 iVals[0] = hcl.cast(hcl.Int(), iVals[0] + 0.5)62 iVals[1] = hcl.cast(hcl.Int(), iVals[1] + 0.5)63 iVals[2] = hcl.cast(hcl.Int(), iVals[2] + 0.5)64 iVals[3] = hcl.cast(hcl.Int(), iVals[3] + 0.5)65 iVals[4] = hcl.cast(hcl.Int(), iVals[4] + 0.5)66 iVals[5] = hcl.cast(hcl.Int(), iVals[5] + 0.5)67# Convert indices into state values68def indexToState(iVals, sVals, bounds, ptsEachDim):69 sVals[0] = bounds[0,0] + ( (bounds[0,1] - bounds[0,0]) * (iVals[0] / (ptsEachDim[0]-1)) ) 70 sVals[1] = bounds[1,0] + ( (bounds[1,1] - bounds[1,0]) * (iVals[1] / (ptsEachDim[1]-1)) ) 71 sVals[2] = bounds[2,0] + ( (bounds[2,1] - bounds[2,0]) * (iVals[2] / (ptsEachDim[2]-1)) ) 72 sVals[3] = bounds[3,0] + ( (bounds[3,1] - bounds[3,0]) * (iVals[3] / (ptsEachDim[3]-1)) ) 73 sVals[4] = bounds[4,0] + ( (bounds[4,1] - bounds[4,0]) * (iVals[4] / (ptsEachDim[4]-1)) ) 74 sVals[5] = bounds[5,0] + ( (bounds[5,1] - bounds[5,0]) * (iVals[5] / (ptsEachDim[5]-1)) ) 75# Sets iVals equal to (i,j,k,l,m,n) and sVals equal to the corresponding state values76def updateStateVals(i, j, k, l, m, n, iVals, sVals, bounds, ptsEachDim):77 iVals[0] = i78 iVals[1] = j79 iVals[2] = k80 iVals[3] = l81 iVals[4] = m82 iVals[5] = n83 indexToState(iVals, sVals, bounds, ptsEachDim)84######################################### VALUE ITERATION ##########################################85# Main value iteration algorithm86# reSweep: a convergence flag (1: continue iterating, 0: convergence reached)87# epsilon: convergence criteria88# maxIters: maximum number of iterations that can occur without convergence being reached89# count: the number of iterations that have been performed90def value_iteration_6D(MDP_obj):91 def solve_Vopt(Vopt, actions, intermeds, trans, interpV, gamma, epsilon, iVals, sVals, bounds, goal, ptsEachDim, count, maxIters, useNN):92 reSweep = hcl.scalar(1, "reSweep")93 oldV = hcl.scalar(0, "oldV")94 newV = hcl.scalar(0, "newV")95 with hcl.while_(hcl.and_(reSweep[0] == 1, count[0] < maxIters[0])):96 reSweep[0] = 097 # Perform value iteration by sweeping in direction 198 with hcl.Stage("Sweep_1"):99 with hcl.for_(0, Vopt.shape[0], name="i") as i:100 with hcl.for_(0, Vopt.shape[1], name="j") as j:101 with hcl.for_(0, Vopt.shape[2], name="k") as k:102 with hcl.for_(0, Vopt.shape[3], name="l") as l:103 with hcl.for_(0, Vopt.shape[4], name="m") as m:104 with hcl.for_(0, Vopt.shape[5], name="n") as n:105 oldV[0] = Vopt[i,j,k,l,m,n]106 updateVopt(MDP_obj, i, j, k, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)107 newV[0] = Vopt[i,j,k,l,m,n]108 evaluateConvergence(newV, oldV, epsilon, reSweep)109 count[0] += 1110 # Perform value iteration by sweeping in direction 2111 with hcl.Stage("Sweep_2"):112 with hcl.if_(useNN[0] == 1):113 with hcl.for_(1, Vopt.shape[0] + 1, name="i") as i:114 with hcl.for_(1, Vopt.shape[1] + 1, name="j") as j:115 with hcl.for_(1, Vopt.shape[2] + 1, name="k") as k:116 with hcl.for_(0, Vopt.shape[3], name="l") as l:117 with hcl.for_(0, Vopt.shape[4], name="m") as m:118 with hcl.for_(0, Vopt.shape[5], name="n") as n:119 i2 = Vopt.shape[0] - i120 j2 = Vopt.shape[1] - j121 k2 = Vopt.shape[2] - k122 oldV[0] = Vopt[i2,j2,k2,l,m,n]123 updateVopt(MDP_obj, i2, j2, k2, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)124 newV[0] = Vopt[i2,j2,k2,l,m,n]125 evaluateConvergence(newV, oldV, epsilon, reSweep)126 count[0] += 1127 # Perform value iteration by sweeping in direction 3128 with hcl.Stage("Sweep_3"):129 with hcl.if_(useNN[0] == 1):130 with hcl.for_(1, Vopt.shape[0] + 1, name="i") as i:131 with hcl.for_(0, Vopt.shape[1], name="j") as j:132 with hcl.for_(0, Vopt.shape[2], name="k") as k:133 with hcl.for_(0, Vopt.shape[3], name="l") as l:134 with hcl.for_(0, Vopt.shape[4], name="m") as m:135 with hcl.for_(0, Vopt.shape[5], name="n") as n:136 i2 = Vopt.shape[0] - i137 oldV[0] = Vopt[i2,j,k,l,m,n]138 updateVopt(MDP_obj, i2, j, k, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)139 newV[0] = Vopt[i2,j,k,l,m,n]140 evaluateConvergence(newV, oldV, epsilon, reSweep)141 count[0] += 1142 # Perform value iteration by sweeping in direction 4143 with hcl.Stage("Sweep_4"):144 with hcl.if_(useNN[0] == 1):145 with hcl.for_(0, Vopt.shape[0], name="i") as i:146 with hcl.for_(1, Vopt.shape[1] + 1, name="j") as j:147 with hcl.for_(0, Vopt.shape[2], name="k") as k:148 with hcl.for_(0, Vopt.shape[3], name="l") as l:149 with hcl.for_(0, Vopt.shape[4], name="m") as m:150 with hcl.for_(0, Vopt.shape[5], name="n") as n:151 j2 = Vopt.shape[1] - j152 oldV[0] = Vopt[i,j2,k,l,m,n]153 updateVopt(MDP_obj, i, j2, k, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)154 newV[0] = Vopt[i,j2,k,l,m,n]155 evaluateConvergence(newV, oldV, epsilon, reSweep)156 count[0] += 1157 # Perform value iteration by sweeping in direction 5158 with hcl.Stage("Sweep_5"):159 with hcl.if_(useNN[0] == 1):160 with hcl.for_(0, Vopt.shape[0], name="i") as i:161 with hcl.for_(0, Vopt.shape[1], name="j") as j:162 with hcl.for_(1, Vopt.shape[2] + 1, name="k") as k:163 with hcl.for_(0, Vopt.shape[3], name="l") as l:164 with hcl.for_(0, Vopt.shape[4], name="m") as m:165 with hcl.for_(0, Vopt.shape[5], name="n") as n:166 k2 = Vopt.shape[2] - k167 oldV[0] = Vopt[i,j,k2,l,m,n]168 updateVopt(MDP_obj, i, j, k2, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)169 newV[0] = Vopt[i,j,k2,l,m,n]170 evaluateConvergence(newV, oldV, epsilon, reSweep)171 count[0] += 1172 # Perform value iteration by sweeping in direction 6173 with hcl.Stage("Sweep_6"):174 with hcl.if_(useNN[0] == 1):175 with hcl.for_(1, Vopt.shape[0] + 1, name="i") as i:176 with hcl.for_(1, Vopt.shape[1] + 1, name="j") as j:177 with hcl.for_(0, Vopt.shape[2], name="k") as k:178 with hcl.for_(0, Vopt.shape[3], name="l") as l:179 with hcl.for_(0, Vopt.shape[4], name="m") as m:180 with hcl.for_(0, Vopt.shape[5], name="n") as n:181 i2 = Vopt.shape[0] - i182 j2 = Vopt.shape[1] - j183 oldV[0] = Vopt[i2,j2,k,l,m,n]184 updateVopt(MDP_obj, i2, j2, k, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)185 newV[0] = Vopt[i2,j2,k,l,m,n]186 evaluateConvergence(newV, oldV, epsilon, reSweep)187 count[0] += 1188 # Perform value iteration by sweeping in direction 7189 with hcl.Stage("Sweep_7"):190 with hcl.if_(useNN[0] == 1):191 with hcl.for_(1, Vopt.shape[0] + 1, name="i") as i:192 with hcl.for_(0, Vopt.shape[1], name="j") as j:193 with hcl.for_(1, Vopt.shape[2] + 1, name="k") as k:194 with hcl.for_(0, Vopt.shape[3], name="l") as l:195 with hcl.for_(0, Vopt.shape[4], name="m") as m:196 with hcl.for_(0, Vopt.shape[5], name="n") as n:197 i2 = Vopt.shape[0] - i198 k2 = Vopt.shape[2] - k199 oldV[0] = Vopt[i2,j,k2,l,m,n]200 updateVopt(MDP_obj, i2, j, k2, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)201 newV[0] = Vopt[i2,j,k2,l,m,n]202 evaluateConvergence(newV, oldV, epsilon, reSweep)203 count[0] += 1204 # Perform value iteration by sweeping in direction 8205 with hcl.Stage("Sweep_8"):206 with hcl.if_(useNN[0] == 1):207 with hcl.for_(0, Vopt.shape[0], name="i") as i:208 with hcl.for_(1, Vopt.shape[1] + 1, name="j") as j:209 with hcl.for_(1, Vopt.shape[2] + 1, name="k") as k:210 with hcl.for_(0, Vopt.shape[3], name="l") as l:211 with hcl.for_(0, Vopt.shape[4], name="m") as m:212 with hcl.for_(0, Vopt.shape[5], name="n") as n:213 j2 = Vopt.shape[1] - j214 k2 = Vopt.shape[2] - k215 oldV[0] = Vopt[i,j2,k2,l,m,n]216 updateVopt(MDP_obj, i, j2, k2, l, m, n, iVals, sVals, actions, Vopt, intermeds, trans, interpV, gamma, bounds, goal, ptsEachDim, useNN)217 newV[0] = Vopt[i,j2,k2,l,m,n]218 evaluateConvergence(newV, oldV, epsilon, reSweep)219 count[0] += 1220 ###################################### SETUP PLACEHOLDERS ######################################221 222 # Initialize the HCL environment223 hcl.init()224 hcl.config.init_dtype = hcl.Float()225 # NOTE: trans is a tensor with size = maximum number of transitions226 # NOTE: intermeds must have size [# possible actions]...

Full Screen

Full Screen

TimeToReach_5D.py

Source:TimeToReach_5D.py Github

copy

Full Screen

...72 #debugger[i, j, k, l] = phiNew[0]73 phi[i, j, k, l, m] = my_min(phi[i, j, k, l, m], phiNew[0])74def EvalBoundary(phi, g):75 if 0 not in g.pDim:76 with hcl.for_(0, phi.shape[1], name="j") as j:77 with hcl.for_(0, phi.shape[2], name="k") as k:78 with hcl.for_(0, phi.shape[3], name="l") as l:79 with hcl.for_(0, phi.shape[4], name="m") as m:80 #debug2[0] = j81 tmp1 = hcl.scalar(0, "tmp1")82 tmp1[0] = 2 * phi[1, j, k, l, m] - phi[2, j, k, l, m]83 tmp1[0] = my_max(tmp1[0], phi[2, j, k, l, m])84 phi[0, j, k, l, m] = my_min(tmp1[0], phi[0, j, k, l, m])85 tmp2 = hcl.scalar(0, "tmp2")86 tmp2[0] = 2 * phi[phi.shape[0] - 2, j, k, l, m] - phi[phi.shape[0] - 3, j, k, l, m]87 tmp2[0] = my_max(tmp2[0], phi[phi.shape[0] - 3, j, k, l, m])88 phi[phi.shape[0] - 1, j, k, l, m] = my_min(tmp2[0], phi[phi.shape[0] - 1, j, k, l, m])89 if 1 not in g.pDim:90 with hcl.for_(0, phi.shape[0], name="i") as i:91 with hcl.for_(0, phi.shape[2], name="k") as k:92 with hcl.for_(0, phi.shape[3], name="l") as l:93 with hcl.for_(0, phi.shape[4], name="m") as m:94 tmp1 = hcl.scalar(0, "tmp1")95 tmp1[0] = 2 * phi[i, 1, k, l] - phi[i, 2, k, l, m]96 tmp1[0] = my_max(tmp1[0], phi[i, 2, k, l, m])97 phi[i, 0, k, l, m] = my_min(tmp1[0], phi[i, 0, k, l, m])98 tmp2 = hcl.scalar(0, "tmp2")99 tmp2[0] = 2 * phi[i, phi.shape[1] - 2, k, l, m] - phi[i, phi.shape[1] - 3, k, l, m]100 tmp2[0] = my_max(tmp2[0], phi[i, phi.shape[1] - 3, k, l, m])101 phi[i, phi.shape[1] - 1, k, l, m] = my_min(tmp2[0], phi[i, phi.shape[1] - 1, k, l, m])102 if 2 not in g.pDim:103 with hcl.for_(0, phi.shape[0], name="i") as i:104 with hcl.for_(0, phi.shape[1], name="j") as j:105 with hcl.for_(0, phi.shape[3], name="l") as l:106 with hcl.for_(0, phi.shape[4], name="m") as m:107 tmp1 = hcl.scalar(0, "tmp1")108 tmp1[0] = 2 * phi[i, j, 1, l, m] - phi[i, j, 2, l, m]109 tmp1[0] = my_max(tmp1[0], phi[i, j, 2, l, m])110 phi[i, j, 0, l, m] = my_min(tmp1[0], phi[i, j, 0, l, m])111 tmp2 = hcl.scalar(0, "tmp2")112 tmp2[0] = 2 * phi[i, j, phi.shape[2] - 2, l, m] - phi[i, j, phi.shape[2] - 3, l, m]113 tmp2[0] = my_max(tmp2[0], phi[i, j, phi.shape[2] - 3, l, m])114 phi[i, j, phi.shape[2] - 1, l, m] = my_min(tmp2[0], phi[i, j, phi.shape[2] - 1, l, m])115 if 3 not in g.pDim:116 with hcl.for_(0, phi.shape[0], name="i") as i:117 with hcl.for_(0, phi.shape[1], name="j") as j:118 with hcl.for_(0, phi.shape[2], name="k") as k:119 with hcl.for_(0, phi.shape[4], name="m") as m:120 tmp1 = hcl.scalar(0, "tmp1")121 tmp1[0] = 2 * phi[i, j, k, 1, m] - phi[i, j, k, 2, m]122 tmp1[0] = my_max(tmp1[0], phi[i, j, k, 2, m])123 phi[i, j, k, 0, m] = my_min(tmp1[0], phi[i, j, k, 0, m])124 tmp2 = hcl.scalar(0, "tmp2")125 tmp2[0] = 2 * phi[i, j, k, phi.shape[2] - 2, m] - phi[i, j, k, phi.shape[2] - 3, m]126 tmp2[0] = my_max(tmp2[0], phi[i, j, k, phi.shape[2] - 3, m])127 phi[i, j, k, phi.shape[2] - 1, m] = my_min(tmp2[0], phi[i, j, k, phi.shape[2] - 1, m])128 if 4 not in g.pDim:129 with hcl.for_(0, phi.shape[0], name="i") as i:130 with hcl.for_(0, phi.shape[1], name="j") as j:131 with hcl.for_(0, phi.shape[2], name="k") as k:132 with hcl.for_(0, phi.shape[3], name="l") as l:133 tmp1 = hcl.scalar(0, "tmp1")134 tmp1[0] = 2 * phi[i, j, k, l, 1] - phi[i, j, k, l, 2]135 tmp1[0] = my_max(tmp1[0], phi[i, j, k, l, 2])136 phi[i, j, k, l, 0] = my_min(tmp1[0], phi[i, j, k, l, 0])137 tmp2 = hcl.scalar(0, "tmp2")138 tmp2[0] = 2 * phi[i, j, k, l, phi.shape[2] - 2] - phi[i, j, k, l, phi.shape[2] - 3]139 tmp2[0] = my_max(tmp2[0], phi[i, j, k, l, phi.shape[2] - 3])140 phi[i, j, k, l, phi.shape[2] - 1] = my_min(tmp2[0], phi[i, j, k, l, phi.shape[2] - 1])141######################################### VALUE ITERATION ##########################################142def TTR_5D(my_object, g):143 def solve_phiNew(phi, x1, x2, x3, x4, x5):144 l_i = 0 if 0 in g.pDim else 1145 h_i = phi.shape[0] if 0 in g.pDim else phi.shape[0] - 1146 l_j = 0 if 1 in g.pDim else 1147 h_j = phi.shape[1] if 1 in g.pDim else phi.shape[1] - 1148 l_k = 0 if 2 in g.pDim else 1149 h_k = phi.shape[2] if 2 in g.pDim else phi.shape[2] - 1150 l_l = 0 if 3 in g.pDim else 1151 h_l = phi.shape[3] if 3 in g.pDim else phi.shape[3] - 1152 l_m = 0 if 4 in g.pDim else 1153 h_m = phi.shape[4] if 4 in g.pDim else phi.shape[4] - 1154 # Perform value iteration by sweeping in direction 1155 with hcl.Stage("Sweep_1"):156 with hcl.for_(l_i, h_i, name="i") as i:157 with hcl.for_(l_j, h_j, name="j") as j:158 with hcl.for_(l_k, h_k, name="k") as k:159 with hcl.for_(l_l, h_l, name="l") as l:160 with hcl.for_(l_m, h_m, name="m") as m:161 updatePhi(i, j, k, l, m, my_object, phi, g, x1, x2, x3, x4, x5)162 EvalBoundary(phi, g)163 # Perform value iteration by sweeping in direction 2164 with hcl.Stage("Sweep_2"):165 with hcl.for_(l_i, h_i, name="i") as i:166 with hcl.for_(l_j, h_j, name="j") as j:167 with hcl.for_(l_k, h_k, name="k") as k:168 with hcl.for_(l_l, h_l, name="l") as l:169 with hcl.for_(l_m, h_m, name="m") as m:170 i2 = phi.shape[0] - i - 1171 j2 = phi.shape[1] - j - 1172 k2 = phi.shape[2] - k - 1173 l2 = phi.shape[3] - l - 1174 m2 = phi.shape[4] - m - 1175 updatePhi(i2, j2, k2, l2, m2, my_object, phi, g, x1, x2, x3, x4, x5)176 EvalBoundary(phi, g)177 # Perform value iteration by sweeping in direction 3178 with hcl.Stage("Sweep_3"):179 with hcl.for_(l_i, h_i, name="i") as i:180 with hcl.for_(l_j, h_j, name="j") as j:181 with hcl.for_(l_k, h_k, name="k") as k:182 with hcl.for_(l_l, h_l, name="l") as l:183 with hcl.for_(l_m, h_m, name="m") as m:184 i2 = phi.shape[0] - i - 1185 j2 = phi.shape[1] - j - 1186 k2 = phi.shape[2] - k - 1187 l2 = phi.shape[3] - l - 1188 updatePhi(i2, j2, k2, l2, m, my_object, phi, g, x1, x2, x3, x4, x5)189 EvalBoundary(phi, g)190 # Perform value iteration by sweeping in direction 4191 with hcl.Stage("Sweep_4"):192 with hcl.for_(l_i, h_i, name="i") as i:193 with hcl.for_(l_j, h_j, name="j") as j:194 with hcl.for_(l_k, h_k, name="k") as k:195 with hcl.for_(l_l, h_l, name="l") as l:196 with hcl.for_(l_m, h_m, name="m") as m:197 i2 = phi.shape[0] - i - 1198 j2 = phi.shape[1] - j - 1199 k2 = phi.shape[2] - k - 1200 updatePhi(i2, j2, k2, l, m, my_object, phi, g, x1, x2, x3, x4, x5)201 EvalBoundary(phi, g)202 # Perform value iteration by sweeping in direction 5203 with hcl.Stage("Sweep_5"):204 with hcl.for_(l_i, h_i, name="i") as i:205 with hcl.for_(l_j, h_j, name="j") as j:206 with hcl.for_(l_k, h_k, name="k") as k:207 with hcl.for_(l_l, h_l, name="l") as l:208 with hcl.for_(l_m, h_m, name="m") as m:209 i2 = phi.shape[0] - i - 1210 j2 = phi.shape[1] - j - 1211 updatePhi(i2, j2, k, l, m, my_object, phi, g, x1, x2, x3, x4, x5)212 EvalBoundary(phi, g)213 # Perform value iteration by sweeping in direction 6214 with hcl.Stage("Sweep_6"):215 with hcl.for_(l_i, h_i, name="i") as i:216 with hcl.for_(l_j, h_j, name="j") as j:217 with hcl.for_(l_k, h_k, name="k") as k:218 with hcl.for_(l_l, h_l, name="l") as l:219 with hcl.for_(l_m, h_m, name="m") as m:220 i2 = phi.shape[0] - i - 1221 updatePhi(i2, j, k, l, m, my_object, phi, g, x1, x2, x3, x4, x5)222 EvalBoundary(phi, g)223 # Perform value iteration by sweeping in direction 7224 with hcl.Stage("Sweep_7"):225 with hcl.for_(l_i, h_i, name="i") as i:226 with hcl.for_(l_j, h_j, name="j") as j:227 with hcl.for_(l_k, h_k, name="k") as k:228 with hcl.for_(l_l, h_l, name="l") as l:229 with hcl.for_(l_m, h_m, name="m") as m:230 j2 = phi.shape[1] - j - 1231 updatePhi(i, j2, k, l, m, my_object, phi, g, x1, x2, x3, x4, x5)232 EvalBoundary(phi, g)233 # Perform value iteration by sweeping in direction 8234 with hcl.Stage("Sweep_8"):235 with hcl.for_(l_i, h_i, name="i") as i:236 with hcl.for_(l_j, h_j, name="j") as j:237 with hcl.for_(l_k, h_k, name="k") as k:238 with hcl.for_(l_l, h_l, name="l") as l:239 with hcl.for_(l_m, h_m, name="m") as m:240 j2 = phi.shape[1] - j - 1241 k2 = phi.shape[2] - k - 1242 updatePhi(i, j2, k2, l, m, my_object, phi, g, x1, x2, x3, x4, x5)243 EvalBoundary(phi, g)244 ###################################### SETUP PLACEHOLDERS ######################################245 # Positions vector246 x1 = hcl.placeholder((g.pts_each_dim[0],), name="x1", dtype=hcl.Float())247 x2 = hcl.placeholder((g.pts_each_dim[1],), name="x2", dtype=hcl.Float())248 x3 = hcl.placeholder((g.pts_each_dim[2],), name="x3", dtype=hcl.Float())249 x4 = hcl.placeholder((g.pts_each_dim[3],), name="x4", dtype=hcl.Float())250 x5 = hcl.placeholder((g.pts_each_dim[4],), name="x5", dtype=hcl.Float())251 phi = hcl.placeholder(tuple(g.pts_each_dim), name="phi", dtype=hcl.Float())252 debugger = hcl.placeholder(tuple(g.pts_each_dim), name="debugger", dtype=hcl.Float())253 debug2 = hcl.placeholder((0,), "debug2")...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1import asyncio2from discord.ext import commands3client = commands.Bot(command_prefix='kh!')4@client.event5async def on_ready():6 print('bot is ready')7@client.command()8@commands.has_permissions(manage_channels=True, administrator=True)9async def delete_channels(ctx, channel_name, *, exceptions='None'):10 deleted_channels = 011 if exceptions == 'None':12 guild = client.get_guild(ctx.guild.id)13 for channel in ctx.guild.text_channels:14 is_exception = False15 if channel.name == channel_name:16 await channel.delete()17 deleted_channels += 118 if deleted_channels == 0:19 await ctx.send("Couldn't find any channels with that name")20 else:21 try:22 await ctx.send(f'Found and deleted {deleted_channels} channels')23 except Exception: 24 pass25 else:26 exceptions_cont = exceptions.split(', ')27 guild = client.get_guild(ctx.guild.id)28 for channel in ctx.guild.text_channels:29 is_exception = False30 if channel.name == channel_name:31 for exception in exceptions_cont:32 if int(channel.id) == int(exception):33 is_exception = True34 if is_exception:35 pass36 else:37 await channel.delete()38 deleted_channels += 139 if deleted_channels == 0:40 await ctx.send("Couldn't find any channels with that name")41 else:42 try:43 await ctx.send(f'Found and deleted {deleted_channels} channels')44 except Exception: 45 pass46@client.command()47@commands.has_guild_permissions(manage_roles=True, administrator=True)48async def delete_roles(ctx, role_name, *, exceptions=None):49 deleted_roles = 050 if exceptions == None:51 guild = client.get_guild(ctx.guild.id)52 for role in ctx.guild.roles:53 is_exception = False54 if role.name == role_name:55 await role.delete()56 deleted_roles += 157 if deleted_roles == 0:58 await ctx.send("Couldn't find any roles with that name")59 else:60 await ctx.send(f'Found and deleted {deleted_roles} roles')61 else:62 try:63 exceptions_cont = exceptions.split(' --exc ')64 65 if len(exceptions_cont) > 1:66 role_name = role_name + ' ' + exceptions_cont[0]67 if not exceptions_cont[1] == '':68 exceptions = exceptions_cont[1].split(', ')69 else:70 exceptions = exceptions.split(', ')71 72 except Exception as e:73 exceptions = exceptions.split(', ')74 75 guild = client.get_guild(ctx.guild.id)76 for role in ctx.guild.roles:77 is_exception = False78 if role.name == '@everyone':79 continue80 if role.name == role_name:81 for exception in exceptions:82 if int(role.id) == int(exception):83 is_exception = True84 if is_exception:85 pass86 else:87 await role.delete()88 deleted_roles += 189 if deleted_roles == 0:90 await ctx.send("Couldn't find any roles with that name")91 else:92 await ctx.send(f'Found and deleted {deleted_roles} roles')93@client.command()94@commands.has_guild_permissions(manage_guild=True)95async def delete_messages(ctx, for_, *, message_):96 guild = int(ctx.guild.id)97 if str(for_).endswith('m'):98 for_ = for_[:-1]99 for_ = int(for_) * 60100 elif str(for_).endswith('s'):101 for_ = for_[:-1]102 for_ = int(for_)103 elif str(for_).endswith('h'):104 for_ = for_[:-1]105 for_ = int(for_)106 else:107 for_ = for_[:-1]108 for_ = int(for_)109 @client.listen()110 async def on_message(message):111 if message.guild.id == ctx.guild.id:112 if message.content == message_:113 await message.delete()114 await asyncio.sleep(for_)115 client.remove_listener(func=on_message)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful