Best Python code snippet using molecule_python
CodeWriter.py
Source:CodeWriter.py
1from Parser import Parser2import os3import glob4class CodeWriter:5 def __init__(self, path):6 self.write_file = None7 self.parser = None8 files = []9 if os.path.isfile(path):10 write_file_path = path[:path.index('.')] + '.asm'11 self.write_file = open(write_file_path, 'w')12 files = [path]13 else:14 temp = path.split('/')15 write_file_name = temp[len(temp)-2]16 write_file_path = path + write_file_name + '.asm'17 self.write_file = open(write_file_path, 'w')18 files = glob.glob(path + '*.vm')19 20 self.current_file_name = ''21 self.current_line_asm_file = 022 self.init_written = False23 for file_path in files:24 current_file_name = os.path.basename(file_path)25 self.current_file_name = current_file_name[:current_file_name.index('.')]26 self.parser = Parser(file_path)27 self.start_writing()28 29 self.write_file.close()30 def start_writing(self):31 if not self.init_written:32 self.write_init()33 self.init_written = True34 while self.parser.has_more_commands():35 self.current_line_asm_file += 136 self.parser.advance()37 code_type = self.parser.code_type()38 if code_type in ['push', 'pull']:39 self.write_push_pop()40 elif code_type == 'arithmetic':41 self.write_arithmetic()42 elif code_type == 'function':43 self.write_function()44 elif code_type == 'label':45 self.write_label()46 elif code_type == 'goto':47 self.write_goto()48 elif code_type == 'ifgoto':49 self.write_ifgoto()50 elif code_type == 'return':51 self.write_return()52 elif code_type == 'call':53 self.write_call()54 def write_function(self):55 function = self.parser.arg1()56 count = self.parser.arg2()57 self.write_file.write('(%s)\n' % function)58 self.write_file.write('@%s\n' % count)59 self.write_file.write('D=A\n')60 self.write_file.write('@13\n')61 self.write_file.write('M=D\n')62 self.write_file.write('(loop.%s)\n' % function)63 self.write_file.write('@13\n')64 self.write_file.write('D=M\n')65 self.write_file.write('@break.%s\n' % function)66 self.write_file.write('D;JEQ\n')67 self.write_file.write('@SP\n')68 self.write_file.write('A=M\n')69 self.write_file.write('M=0\n')70 self.write_file.write('@SP\n')71 self.write_file.write('M=M+1\n')72 self.write_file.write('@13\n')73 self.write_file.write('M=M-1\n')74 self.write_file.write('@loop.%s\n' % function)75 self.write_file.write('0;JMP\n')76 self.write_file.write('(break.%s)\n' % function)77 def write_label(self):78 self.write_file.write('(%s)\n' % self.parser.arg1())79 def write_goto(self):80 self.write_file.write('@%s\n' % self.parser.arg1())81 def write_ifgoto(self):82 self.write_file.write('@SP\n')83 self.write_file.write('A=M-1\n')84 self.write_file.write('D=M\n')85 self.write_file.write('@SP\n')86 self.write_file.write('M=M-1\n')87 self.write_file.write('@%s\n' % self.parser.arg1())88 self.write_file.write('D;JNE\n')89 def write_return(self):90 self.write_file.write('@LCL\n')91 self.write_file.write('D=M\n')92 self.write_file.write('@13\n')93 self.write_file.write('M=D\n')94 self.write_file.write('@13\n')95 self.write_file.write('D=M\n')96 self.write_file.write('@5\n')97 self.write_file.write('D=D-A\n')98 self.write_file.write('A=D\n')99 self.write_file.write('D=M\n')100 self.write_file.write('@14\n')101 self.write_file.write('M=D\n')102 self.write_file.write('@SP\n')103 self.write_file.write('A=M-1\n')104 self.write_file.write('D=M\n')105 self.write_file.write('@ARG\n')106 self.write_file.write('A=M\n')107 self.write_file.write('M=D\n')108 self.write_file.write('@SP\n')109 self.write_file.write('M=M-1\n')110 self.write_file.write('@ARG\n')111 self.write_file.write('D=M+1\n')112 self.write_file.write('@SP\n')113 self.write_file.write('M=D\n')114 self.write_file.write('@13\n')115 self.write_file.write('A=M-1\n')116 self.write_file.write('D=M\n')117 self.write_file.write('@THAT\n')118 self.write_file.write('M=D\n')119 self.write_file.write('@13\n')120 self.write_file.write('D=M\n')121 self.write_file.write('@2\n')122 self.write_file.write('A=D-A\n')123 self.write_file.write('D=M\n')124 self.write_file.write('@THIS\n')125 self.write_file.write('M=D\n')126 self.write_file.write('@13\n')127 self.write_file.write('D=M\n')128 self.write_file.write('@3\n')129 self.write_file.write('A=D-A\n')130 self.write_file.write('D=M\n')131 self.write_file.write('@ARG\n')132 self.write_file.write('M=D\n')133 self.write_file.write('@13\n')134 self.write_file.write('D=M\n')135 self.write_file.write('@4\n')136 self.write_file.write('A=D-A\n')137 self.write_file.write('D=M\n')138 self.write_file.write('@LCL\n')139 self.write_file.write('M=D\n')140 self.write_file.write('@14\n')141 self.write_file.write('A=M\n')142 self.write_file.write('0;JMP\n')143 def write_call(self):144 function = self.parser.arg1()145 num_args = self.parser.arg2()146 return_label = 'return.' + str(self.current_line_asm_file)147 self.write_file.write('@%s\n' % return_label)148 self.write_file.write('D=A\n')149 self.write_file.write('@SP\n')150 self.write_file.write('A=M\n')151 self.write_file.write('M=D\n')152 self.write_file.write('@SP\n')153 self.write_file.write('M=M+1\n')154 self.write_file.write('@LCL\n')155 self.write_file.write('D=M\n')156 self.write_file.write('@SP\n')157 self.write_file.write('A=M\n')158 self.write_file.write('M=D\n')159 self.write_file.write('@SP\n')160 self.write_file.write('M=M+1\n')161 self.write_file.write('@ARG\n')162 self.write_file.write('D=M\n')163 self.write_file.write('@SP\n')164 self.write_file.write('A=M\n')165 self.write_file.write('M=D\n')166 self.write_file.write('@SP\n')167 self.write_file.write('M=M+1\n')168 self.write_file.write('D=M\n')169 self.write_file.write('@SP\n')170 self.write_file.write('A=M\n')171 self.write_file.write('M=D\n')172 self.write_file.write('@SP\n')173 self.write_file.write('M=M+1\n')174 self.write_file.write('@SP\n')175 self.write_file.write('D=M\n')176 self.write_file.write('@%s\n' % num_args)177 self.write_file.write('D=D-A\n')178 self.write_file.write('@5\n')179 self.write_file.write('D=D-A\n')180 self.write_file.write('@ARG\n')181 self.write_file.write('M=D\n')182 self.write_file.write('@SP\n')183 self.write_file.write('D=M\n')184 self.write_file.write('@LCL\n')185 self.write_file.write('M=D\n')186 self.write_file.write('@%s\n' % function)187 self.write_file.write('0;JMP\n')188 self.write_file.write('(%s)\n' % return_label)189 190 def write_init(self):191 self.write_file.write('@256\n')192 self.write_file.write('D=A\n')193 self.write_file.write('@SP\n')194 self.write_file.write('M=D\n')195 self.write_file.write('@300\n')196 self.write_file.write('D=A\n')197 self.write_file.write('@LCL\n')198 self.write_file.write('M=D\n')199 self.write_file.write('@400\n')200 self.write_file.write('D=A\n')201 self.write_file.write('@ARG\n')202 self.write_file.write('M=D\n')203 self.write_file.write('@3000\n')204 self.write_file.write('D=A\n')205 self.write_file.write('@THIS\n')206 self.write_file.write('M=D\n')207 self.write_file.write('@3010\n')208 self.write_file.write('D=A\n')209 self.write_file.write('@THAT\n')210 self.write_file.write('M=D\n')211 def write_arithmetic(self):212 arg = self.parser.arg1()213 if arg == 'add':214 self.write_file.write('@SP\n')215 self.write_file.write('A=M-1\n')216 self.write_file.write('D=M\n')217 self.write_file.write('A=A-1\n')218 self.write_file.write('D=D+M\n')219 self.write_file.write('M=D\n')220 self.write_file.write('@SP\n')221 self.write_file.write('M=M-1\n')222 elif arg == 'sub':223 self.write_file.write('@SP\n')224 self.write_file.write('A=M-1\n')225 self.write_file.write('D=M\n')226 self.write_file.write('A=A-1\n')227 self.write_file.write('D=M-D\n')228 self.write_file.write('M=D\n')229 self.write_file.write('@SP\n')230 self.write_file.write('M=M-1\n')231 elif arg == 'neg':232 self.write_file.write('@SP\n')233 self.write_file.write('A=M-1\n')234 self.write_file.write('M=-M\n')235 elif arg == 'eq':236 self.write_file.write('@SP\n')237 self.write_file.write('A=M-1\n')238 self.write_file.write('D=M\n')239 self.write_file.write('A=A-1\n')240 self.write_file.write('D=M-D\n')241 self.write_file.write('@true.%s\n' % self.parser.current_index)242 self.write_file.write('D;JEQ\n')243 self.write_file.write('@SP\n')244 self.write_file.write('A=M-1\n')245 self.write_file.write('A=A-1\n')246 self.write_file.write('M=0\n')247 self.write_file.write('@break.%s\n' % self.parser.current_index)248 self.write_file.write('0;JMP\n')249 self.write_file.write('(true.%s)\n' % self.parser.current_index)250 self.write_file.write('@SP\n')251 self.write_file.write('A=M-1\n')252 self.write_file.write('A=A-1\n')253 self.write_file.write('M=-1\n')254 elif arg == 'gt':255 self.write_file.write('@SP\n')256 self.write_file.write('A=M-1\n')257 self.write_file.write('D=M\n')258 self.write_file.write('A=A-1\n')259 self.write_file.write('D=M-D\n')260 self.write_file.write('@true.%s\n' % self.parser.current_index)261 self.write_file.write('D;JGT\n')262 self.write_file.write('@SP\n')263 self.write_file.write('A=M-1\n')264 self.write_file.write('A=A-1\n')265 self.write_file.write('M=0\n')266 self.write_file.write('@break.%s\n' % self.parser.current_index)267 self.write_file.write('0;JMP\n')268 self.write_file.write('(true.%s)\n' % self.parser.current_index)269 self.write_file.write('@SP\n')270 self.write_file.write('A=M-1\n')271 self.write_file.write('A=A-1\n')272 self.write_file.write('M=-1\n')273 self.write_file.write('(break.%s)\n' % self.parser.current_index)274 self.write_file.write('@SP\n')275 self.write_file.write('M=M-1\n')276 elif arg == 'lt':277 self.write_file.write('@SP\n')278 self.write_file.write('A=M-1\n')279 self.write_file.write('D=M\n')280 self.write_file.write('A=A-1\n')281 self.write_file.write('D=M-D\n')282 self.write_file.write('M=0\n')283 self.write_file.write('@break.%s\n' % self.parser.current_index)284 self.write_file.write('0;JMP\n')285 self.write_file.write('(true.%s)\n' % self.parser.current_index)286 self.write_file.write('@SP\n')287 self.write_file.write('A=M-1\n')288 self.write_file.write('A=A-1\n')289 self.write_file.write('M=-1\n')290 self.write_file.write('(break.%s)\n' % self.parser.current_index)291 self.write_file.write('@SP\n')292 self.write_file.write('M=M-1\n')293 elif arg == 'and':294 self.write_file.write('@SP\n')295 self.write_file.write('A=M-1\n')296 self.write_file.write('D=M\n')297 self.write_file.write('A=A-1\n')298 self.write_file.write('M=D&M\n')299 self.write_file.write('@SP\n')300 self.write_file.write('M=M-1\n')301 elif arg == 'or':302 self.write_file.write('@SP\n')303 self.write_file.write('A=M-1\n')304 self.write_file.write('D=M\n')305 self.write_file.write('A=M-1\n')306 self.write_file.write('M=-M\n')307 elif arg == 'not':308 self.write_file.write('@SP\n')309 self.write_file.write('A=M-1\n')310 self.write_file.write('M=!M\n')311 def write_push_pop(self):312 arg1 = self.parser.arg1()313 arg2 = self.parser.arg2()314 if self.parser.code_type() == 'push':315 if arg1 == 'constant':316 self.write_file.write('@%s\n' % arg2)317 self.write_file.write('D=A\n')318 self.write_file.write('@SP\n')319 self.write_file.write('A=M\n')320 self.write_file.write('M=D\n')321 if arg1 == 'temp':322 self.write_file.write('@%s\n' % arg2)323 self.write_file.write('D=A\n')324 self.write_file.write('@5\n')325 self.write_file.write('A=D+A\n')326 self.write_file.write('D=M\n')327 self.write_file.write('@SP\n')328 self.write_file.write('A=M\n')329 self.write_file.write('M=D\n')330 if arg1 == 'pointer':331 self.write_file.write('@%s\n' % arg2)332 self.write_file.write('D=A\n')333 self.write_file.write('@3\n')334 self.write_file.write('A=D+A\n')335 self.write_file.write('D=M\n')336 self.write_file.write('@SP\n')337 self.write_file.write('A=M\n')338 self.write_file.write('M=D\n')339 if arg1 == 'local':340 self.write_file.write('@%s\n' % arg2)341 self.write_file.write('D=A\n')342 self.write_file.write('@LCL\n')343 self.write_file.write('A=D+M\n')344 self.write_file.write('D=M\n')345 self.write_file.write('@SP\n')346 self.write_file.write('A=M\n')347 self.write_file.write('M=D\n')348 if arg1 == 'argument':349 self.write_file.write('@%s\n' % arg2)350 self.write_file.write('D=A\n')351 self.write_file.write('@ARG\n')352 self.write_file.write('A=D+M\n')353 self.write_file.write('D=M\n')354 self.write_file.write('@SP\n')355 self.write_file.write('A=M\n')356 self.write_file.write('M=D\n')357 if arg1 == 'this':358 self.write_file.write('@%s\n' % arg2)359 self.write_file.write('D=A\n')360 self.write_file.write('@THIS\n')361 self.write_file.write('A=D+M\n')362 self.write_file.write('D=M\n')363 self.write_file.write('@SP\n')364 self.write_file.write('A=M\n')365 self.write_file.write('M=D\n')366 if arg1 == 'that':367 self.write_file.write('@%s\n' % arg2)368 self.write_file.write('D=A\n')369 self.write_file.write('@THAT\n')370 self.write_file.write('A=D+M\n')371 self.write_file.write('D=M\n')372 self.write_file.write('@SP\n')373 self.write_file.write('A=M\n')374 self.write_file.write('M=D\n')375 if arg1 == 'static':376 self.write_file.write('@%s.%s\n' % (self.current_file_name, arg2))377 self.write_file.write('D=M\n')378 self.write_file.write('@SP\n')379 self.write_file.write('A=M\n')380 self.write_file.write('M=D\n')381 self.write_file.write('@SP\n')382 self.write_file.write('M=M+1\n')383 if self.parser.code_type() == 'pop':384 self.write_file.write('@%s\n' % arg2)385 self.write_file.write('D=A\n')386 if arg1 == 'local':387 self.write_file.write('@LCL\n')388 self.write_file.write('D=D+M\n')389 self.write_file.write('@13\n')390 self.write_file.write('M=D\n')391 self.write_file.write('@SP\n')392 self.write_file.write('A=M-1\n')393 self.write_file.write('D=M\n')394 self.write_file.write('@13\n')395 self.write_file.write('A=M\n')396 self.write_file.write('M=D\n')397 self.write_file.write('@SP\n')398 self.write_file.write('M=M-1\n')399 elif arg1 == 'argument':400 self.write_file.write('@ARG\n')401 self.write_file.write('D=D+M\n')402 self.write_file.write('@13\n')403 self.write_file.write('M=D\n')404 self.write_file.write('@SP\n')405 self.write_file.write('A=M-1\n')406 self.write_file.write('D=M\n')407 self.write_file.write('@13\n')408 self.write_file.write('A=M\n')409 self.write_file.write('M=D\n')410 self.write_file.write('@SP\n')411 self.write_file.write('M=M-1\n')412 elif arg1 == 'this':413 self.write_file.write('@THIS\n')414 self.write_file.write('D=D+M\n')415 self.write_file.write('@13\n')416 self.write_file.write('M=D\n')417 self.write_file.write('@SP\n')418 self.write_file.write('A=M-1\n')419 self.write_file.write('D=M\n')420 self.write_file.write('@13\n')421 self.write_file.write('A=M\n')422 self.write_file.write('M=D\n')423 self.write_file.write('@SP\n')424 self.write_file.write('M=M-1\n')425 elif arg1 == 'that':426 self.write_file.write('@THAT\n')427 self.write_file.write('D=D+M\n')428 self.write_file.write('@13\n')429 self.write_file.write('M=D\n')430 self.write_file.write('@SP\n')431 self.write_file.write('A=M-1\n')432 self.write_file.write('D=M\n')433 self.write_file.write('@13\n')434 self.write_file.write('A=M\n')435 self.write_file.write('M=D\n')436 self.write_file.write('@SP\n')437 self.write_file.write('M=M-1\n')438 elif arg1 == 'temp':439 self.write_file.write('@5\n')440 self.write_file.write('D=D+A\n')441 self.write_file.write('@13\n')442 self.write_file.write('M=D\n')443 self.write_file.write('@SP\n')444 self.write_file.write('A=M-1\n')445 self.write_file.write('D=M\n')446 self.write_file.write('@13\n')447 self.write_file.write('A=M\n')448 self.write_file.write('M=D\n')449 self.write_file.write('@SP\n')450 self.write_file.write('M=M-1\n')451 elif arg1 == 'pointer':452 self.write_file.write('@3\n')453 self.write_file.write('D=D+A\n')454 self.write_file.write('@13\n')455 self.write_file.write('M=D\n')456 self.write_file.write('@SP\n')457 self.write_file.write('A=M-1\n')458 self.write_file.write('D=M\n')459 self.write_file.write('@13\n')460 self.write_file.write('A=M\n')461 self.write_file.write('M=D\n')462 self.write_file.write('@SP\n')463 self.write_file.write('M=M-1\n')464 elif arg1 == 'static':465 self.write_file.write('@SP\n')466 self.write_file.write('A=M-1\n')467 self.write_file.write('D=M\n')468 self.write_file.write('@%s.%s\n' % (self.current_file_name, arg2))469 self.write_file.write('M=D\n')470 self.write_file.write('@SP\n')471 self.write_file.write('M=M-1\n')472 else:473 pass474 475if __name__ == '__main__':476 dirs = ['/home/arush/Desktop/project78/project78/07/MemoryAccess/BasicTest/',477 '/home/arush/Desktop/project78/project78/07/MemoryAccess/PointerTest/',478 '/home/arush/Desktop/project78/project78/07/MemoryAccess/StaticTest/',479 '/home/arush/Desktop/project78/project78/07/StackArithmetic/SimpleAdd/',480 '/home/arush/Desktop/project78/project78/07/StackArithmetic/StackTest/',481 '/home/arush/Desktop/project78/project78/08/FunctionCalls/FibonacciElement/',482 '/home/arush/Desktop/project78/project78/08/FunctionCalls/NestedCall/',483 '/home/arush/Desktop/project78/project78/08/FunctionCalls/SimpleFunction/',484 '/home/arush/Desktop/project78/project78/08/FunctionCalls/StaticsTest/',485 '/home/arush/Desktop/project78/project78/08/ProgramFlow/BasicLoop/',486 '/home/arush/Desktop/project78/project78/08/ProgramFlow/FibonacciSeries/'487 ]488 for path in dirs:...
reference.py
Source:reference.py
1import numpy as np2import datetime3# Physical Constants4me = 9.10938188e-31 # electron mass [kg]5mp = 1.67262158e-27 # proton mass [kg]6e = 1.60217646e-19 # elementary charge [C]7eps0 = 8.854187e-12 # [F/m]8mu0 = 4.0e-7 * np.pi # [H/m]9c = 1.0 / np.sqrt(eps0 * mu0) # speed of light [m/s]10class Reference:11 def __init__(self, triplet, mass_fraction):12 # triplet values13 self.n = triplet[0] # density [particles/m^3]14 self.T = triplet[1] # proton temperature [eV]15 self.TeTi = triplet[2] # temperature ratio [Te/Ti]16 # self.omp_p_tau = triplet[0]17 # self.ref_omp_c = triplet[1]18 # Length scale (actual triplet[2]):19 self.Ld = np.sqrt(eps0 * self.T * self.TeTi / (self.n * e)) # electron Debye length [m]20 # electron mass fraction (fraction of true mass)21 self.mass_fraction = mass_fraction22 # inferred values23 self.p = e * self.n * self.T # pressure [Pa]24 self.B = np.sqrt(self.p * mu0) # magnetic field [T]25 self.vth = np.sqrt(e * self.T / mp) # reference proton thermal velocity [m/s]26 self.v = self.B / np.sqrt(mu0 * mp * self.n) # reference Alfven velocity [m/s]27 # print(self.vth)28 # print(self.v)29 # quit()30 self.tau = self.Ld / self.v # ion Debye length transit time31 # dimensionless parameters32 self.omp_p_tau = self.tau * np.sqrt(e * e * self.n / (eps0 * mp)) # proton frequency33 self.omp_e_tau = self.tau * np.sqrt(e * e * self.n / (eps0 * me * self.mass_fraction)) # electron freq.34 self.omc_p_tau = self.tau * e * self.B / mp # proton magnetic frequency35 self.omc_e_tau = self.tau * e * self.B / (me * self.mass_fraction) # electron magnetic frequency36 self.dp = c * self.tau / self.omp_p_tau # skin depth (proton)37 # problem parameters38 self.ze = -1.0 # electron charge ratio39 self.zi = +1.0 # proton charge ratio40 self.ae = self.mass_fraction * me / mp # electron mass ratio41 self.ai = +1.0 # proton mass ratio42 # thermal properties43 self.Ti = self.T # ion temperature [eV]44 self.Te = self.TeTi * self.T # electron temperature [eV]45 self.vt_i = np.sqrt(e * self.Ti / mp) / self.v # normalized ion therm. vel.46 self.vt_e = np.sqrt(e * self.Te / (me * self.mass_fraction)) / self.v # electron therm. vel.47 # self.vt_e = 1.048 self.cs = np.sqrt(e * (self.Te + self.Ti) / mp) / self.v # sound speed49 self.deb_norm = (self.vt_e * self.v) / (self.omp_e_tau / self.tau) # debye length normalized50 self.length = self.deb_norm # problem length scale51 # acceleration parameters52 self.electron_acceleration_multiplier = (self.ze / self.ae) * (self.length / self.dp)53 self.ion_acceleration_multiplier = (self.zi / self.ai) * (self.length / self.dp)54 self.charge_density_multiplier = -self.omp_p_tau ** 2.0 * (self.dp / self.length)55 # Create run file56 def info_file(self, info_name, geometry_info, time_info):57 # Unpack geometry info: space58 x_min = geometry_info[0, 0]59 x_max = geometry_info[0, 1]60 resolution_x = geometry_info[0, 2]61 order_x = geometry_info[0, 3]62 # Unpack geometry info: velocity u63 u_min = geometry_info[1, 0]64 u_max = geometry_info[1, 1]65 resolution_u = geometry_info[1, 2]66 order_u = geometry_info[1, 3]67 # Unpack geometry info: velocity v68 v_min = geometry_info[2, 0]69 v_max = geometry_info[2, 1]70 resolution_v = geometry_info[2, 2]71 order_v = geometry_info[2, 3]72 # Unpack time info73 final_time = time_info[0]74 write_time = time_info[1]75 courant_number = time_info[2]76 order_t = time_info[3]77 # Create run parameters file78 write_file = open(info_name, 'w')79 write_file.write('######################################')80 write_file.write('\n### V-high-order Run File ############')81 write_file.write('\n######################################')82 write_file.write('\nRun performed ' + datetime.datetime.today().strftime('%Y-%m-%d'))83 write_file.write('\n\nBasis Triplet:')84 write_file.write('\nRef density: ' + "{:.2E}".format(self.n) + ' [m^-3]')85 write_file.write('\nRef temperature: ' + "{:.2E}".format(self.T) + ' [eV]')86 write_file.write('\nRef length (Debye): ' + "{:.2E}".format(self.length) + ' [m]')87 write_file.write('\n\nValues Inferred from Triplet:')88 write_file.write('\nRef velocity: ' + "{:.2E}".format(self.v) + ' [m/s]')89 write_file.write('\nRef time: ' + "{:.2E}".format(self.tau) + ' [s]')90 write_file.write('\nRef proton plasma frequency: ' +91 "{:.2E}".format(self.omp_p_tau / self.tau) + ' [Hz]')92 write_file.write('\nRef electron plasma frequency: ' +93 "{:.2E}".format(self.omp_e_tau / self.tau) + ' [Hz]')94 write_file.write('\nRef proton thermal velocity: ' + "{:.2E}".format(self.v) + ' [m/s]')95 write_file.write('\nRef proton skin depth: ' + "{:.2E}".format(self.dp) + ' [m]')96 write_file.write('\n\nNormalized Run Values (Dimensionless):')97 write_file.write('\nRun density ' + "{:.2f}".format(self.n / self.n))98 write_file.write('\nRun omptau ' + "{:.2f}".format(self.omp_p_tau))99 write_file.write('\nRun proton thermal velocity ' + "{:.2f}".format(self.vt_i))100 write_file.write('\nRun proton temperature ' + "{:.2f}".format(self.Ti / self.T))101 write_file.write('\nRun electron-ion temperature ratio ' + "{:.2f}".format(self.TeTi))102 write_file.write('\nRun ometau ' + "{:.2f}".format(self.omp_e_tau))103 write_file.write('\nRun electron thermal velocity ' + "{:.2f}".format(self.vt_e))104 write_file.write('\nRun electron temperature ' + "{:.2f}".format(self.Te / self.T))105 write_file.write('\nRun Debye length ' + "{:.2f}".format(self.Ld))106 write_file.write('\nRun skin depth ' + "{:.2f}".format(self.dp / self.length))107 write_file.write('\nElectron acceleration coefficient ' +108 "{:.2E}".format(self.electron_acceleration_multiplier))109 write_file.write('\nProton acceleration coefficient ' +110 "{:.2E}".format(self.ion_acceleration_multiplier))111 write_file.write('\nPoisson equation coefficient ' + "{:.2E}".format(self.charge_density_multiplier))112 write_file.write('\n\nGrid and time-stepping parameters')113 write_file.write('\nX elements: ' + str(resolution_x))114 write_file.write('\nU elements: ' + str(resolution_u))115 write_file.write('\nV elements: ' + str(resolution_v))116 write_file.write('\nX domain minimum: ' + "{:.2E}".format(x_min))117 write_file.write('\nX domain maximum: ' + "{:.2E}".format(x_max))118 write_file.write('\nElectron u-velocity minimum ' + "{:.2E}".format(u_min))119 write_file.write('\nElectron u-velocity maximum ' + "{:.2E}".format(u_max))120 write_file.write('\nElectron v-velocity minimum ' + "{:.2E}".format(v_min))121 write_file.write('\nElectron v-velocity maximum ' + "{:.2E}".format(v_max))122 write_file.write('\nTime to run: ' + "{:.2f}".format(final_time))123 write_file.write('\nTime per data write-out ' + "{:.2f}".format(write_time))124 write_file.write('\nCFL number: ' + "{:.2f}".format(courant_number))125 write_file.write('\nSpatial element order: ' + str(order_x))126 write_file.write('\nVelocity-u element order: ' + str(order_u))127 write_file.write('\nVelocity-v element order: ' + str(order_v))128 write_file.write('\nTemporal stepping order: ' + str(order_t))...
make_feature.py
Source:make_feature.py
1import codecs2print "Enter input file"3files=raw_input()4#files='/home/jyoti/Desktop/CRF++-0.58/train_file_english'5print "Enter output file"6write_file_name=raw_input()7#write_file_name='/home/jyoti/Desktop/train_file_english_cl1.txt'8write_file=codecs.open(write_file_name,'w',encoding="utf8")9File=codecs.open(files,'r',encoding="utf8")10flag=011num=012for line in File:13 print line14# if line=="</Sentence>\n":15# flag=016# continue17# if line=="<Sentence id=''''>\n":18# flag=119# continue20# if flag==1:21 num=num+122 l=line.split()23 string=l[0]24 length=len(string)25 if len(l) <=1:26 continue27 if len(string)>=8:28 write_file.write(l[0])29 write_file.write('\t')30 write_file.write(string[0])31 write_file.write('\t')32 write_file.write(string[0:2])33 write_file.write('\t')34 write_file.write(string[0:3])35 write_file.write('\t')36 write_file.write(string[0:4])37 write_file.write('\t')38 write_file.write(string[(length-4):length])39 write_file.write('\t')40 write_file.write(string[(length-3):length])41 write_file.write('\t')42 write_file.write(string[(length-2):length])43 write_file.write('\t')44 write_file.write(string[(length-1):length])45 write_file.write('\t')46 write_file.write(l[1])47 write_file.write('\n')48 49 elif len(string)==4:50 write_file.write(l[0])51 write_file.write('\t')52 write_file.write(string[0])53 write_file.write('\t')54 write_file.write(string[0:2])55 write_file.write('\t')56 write_file.write(string[0:3])57 write_file.write('\t')58 write_file.write(string[0:4])59 write_file.write('\t')60 write_file.write(string[0:4])61 write_file.write('\t')62 write_file.write(string[0:4])63 write_file.write('\t')64 write_file.write(string[0:4])65 write_file.write('\t')66 write_file.write(string[0:4])67 write_file.write('\t')68 write_file.write(l[1])69 write_file.write('\n')70 elif len(string)<4:71 write_file.write(l[0])72 write_file.write('\t')73 count=074 for i in range(0,8):75 if(count>=1):76 write_file.write('\t')77 if(i==length):78 left=8-count79 break80 else:81 write_file.write(string[0:i+1])82 count=count+183 if(left!=0):84 for i in (range(0,left-1)):85 write_file.write(l[0])86 write_file.write('\t')87 write_file.write(l[0])88 write_file.write('\t')89 write_file.write(l[1])90 write_file.write('\n')91 elif len(string)>4:92 print string93 write_file.write(l[0])94 write_file.write('\t')95 for i in range(0,4):96 write_file.write(string[0:i+1])97 write_file.write('\t')98 start=length-399 for i in range(start,length):100 write_file.write(string[i-1:length])101 write_file.write('\t')102 write_file.write(string[length-1:length])103 write_file.write('\t')104 write_file.write(l[1])105 write_file.write('\n')...
data_extract.py
Source:data_extract.py
1import sqlite32with open('data.csv','w+') as write_file:3 conn=sqlite3.connect('db.sqlite3')4 cursor=conn.cursor()5 write_file.write("trans id")6 write_file.write(",")7 write_file.write("quantity")8 write_file.write(",")9 write_file.write("time")10 write_file.write(",")11 write_file.write("item id")12 write_file.write(",")13 write_file.write("client id")14 write_file.write("\n")15 for row in cursor.execute('SELECT * FROM Inventory_transaction'):16 trans_id=row[0]17 quantity=row[1]18 time=row[2]19 client_id=row[3]20 item_id=row[4]21 write_file.write("%d"%trans_id)22 write_file.write(",")23 write_file.write("%d"%quantity)24 write_file.write(",")25 write_file.write(time)26 write_file.write(",")27 write_file.write("%d"%item_id)28 write_file.write(",")29 write_file.write("%d"%client_id)30 write_file.write("\n")31 ...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!