def reboot(self, reboot_cmd="halt", sync=False, stop_at_bootloader=False): """ Reboot the system. This method will reboot the system, kicking it with a HW reset if the serial class was asked to do so at instanciation time. By default the method will issue a reboot command and then return immediately. @param reboot_cmd: actual command to trigger the reboot. Defaults to "halt" since most of our systems are self-resetting :) @param sync: Wait for the reboot to happen; return only after the device rebooted and a login is available. Defaults to False. @param stop_at_bootloader: Reboot, then wait for boot loader messages on the serial line, then interrupt the boot loader. This function returns after we got a boot loader prompt. @return: All the console messages from when the reboot has been issued up to the point the method stopped reading. May be the empty string if an asynchronous reboot has been requested. """ self._logger.info("Rebooting %s" % ("and stopping at bootloader" if stop_at_bootloader else "synchronously" if sync else ".")) self.login() self.write(reboot_cmd + "\n") buf = "" if self._needs_hw_reset: buf += self.readline_until("Detaching DM devices") power.power(0) time.sleep(1) power.power(1) if stop_at_bootloader: buf += self.read_until("U-Boot") buf += self.read_until(self._boot_prompt, ".\n", 0.001) elif sync: buf += self.readline_until("login:"******"OK") return buf
def init( ): """ Initialise the device handle, boot to NAND flash. @returns: a device handle, i.e. a class Device instance. """ print " Initialising the device." print " (Device will be powercycled in 60 secs if unresponsive)" power.power(1) t = threading.Timer( 60, powercycle ) t.start() dev = Device( devtype = "hidav" ) wait_networking( dev ) t.cancel() # set currently used partitions to the first partitions, # so upgrade (detecting this) will use the other partitions dev.bootconfig = { "kernel" : 2, "rootfs" : 4 } print " Firmware version: %s" % dev.firmware_version print " Boot config (current):" print " Kernel: /dev/mtd%s" % dev.bootconfig["kernel"] print " rootfs: /dev/romblock%s" % dev.bootconfig["rootfs"] print " epoch : #%s" % dev.bootconfig["epoch"] print " Booting into NAND..." dev.reboot( to_nand = True ) wait_networking( dev ) return dev
def reboot( self, reboot_cmd="halt", sync=False, stop_at_bootloader=False ): """ Reboot the system. This method will reboot the system, kicking it with a HW reset if the serial class was asked to do so at instanciation time. By default the method will issue a reboot command and then return immediately. @param reboot_cmd: actual command to trigger the reboot. Defaults to "halt" since most of our systems are self-resetting :) @param sync: Wait for the reboot to happen; return only after the device rebooted and a login is available. Defaults to False. @param stop_at_bootloader: Reboot, then wait for boot loader messages on the serial line, then interrupt the boot loader. This function returns after we got a boot loader prompt. @return: All the console messages from when the reboot has been issued up to the point the method stopped reading. May be the empty string if an asynchronous reboot has been requested. """ self._logger.info( "Rebooting %s" % ("and stopping at bootloader" if stop_at_bootloader else "synchronously" if sync else ".") ) self.login() self.write( reboot_cmd + "\n" ) buf = "" if self._needs_hw_reset: buf += self.readline_until( "Detaching DM devices" ) power.power(0) time.sleep(1) power.power(1) if stop_at_bootloader: buf += self.read_until("U-Boot") buf += self.read_until(self._boot_prompt, ".\n", 0.001) elif sync: buf += self.readline_until("login:"******"OK") return buf
def die_of_timeout( dev ): print "\nTIMEOUT while waiting for device to come up." print "Aborting test." print "Refer to the log file %s for details." % logger.filename print "Switching off the device." power.power(0) print "Terminating test." os._exit(1)
def karat(a, b): ''' Implementation of the :param a: (int) or list reverse order :param b: (int) or list reverse order :return: a reversed list of the product a * b ''' if (type(a) == int): a, b = create_reverse_lists(a, b) if len(a) == 1 and len(b) == 1: d, e = create_reverse_lists(a[0] * b[0], 0) return d if (len(a) > len(b)): b = b + [0] * (len(a) - len(b)) if (len(b) > len(a)): a = a + [0] * (len(b) - len(a)) k = len(a) // 2 A2 = a[:k] A1 = a[k:] B2 = b[:k] B1 = b[k:] a1b1 = karat(A1, B1) a12b12 = karat((add(A1, A2)), (add(B1, B2))) a2b2 = karat(A2, B2) # print(a12b12) # print('k: ' + str(k) + '\n') # print ('a1b1: ' + str(a1b1)) stepone = power(a1b1, 2 * k) # print('stepone: ' + str(stepone) + '\n') # stepone = (a1b1 * (10 ** (2 * k))) # print ('a12b12: ' + str(a12b12)) steptwo = subtract(a12b12, a1b1) # print('steptwo: ' + str(steptwo) + '\n') # steptwo = (a12b12) - a1b1 # print ('a2b2: ' + str(a2b2)) stepthree = subtract(steptwo, a2b2) # print('stepthree: ' + str(stepthree) + '\n') # stepthree = steptwo - a2b2 stepfour = power(stepthree, k) # print('stepfour: ' + str(stepfour)) # stepfour = (10 ** k) stepfive = add(stepone, stepfour) # print('stepfive: ' + str(stepfive)) stepsix = add(stepfive, a2b2) # print('stepsix: ' + str(stepsix)) return stepsix
def test_if_recursive(self): # Python 3 will raise RecursionError, Python 2 will raise RuntimeError. # Instead of asserting it raises either of those, assert it raises an # error and check the message, which is the same across the Py versions. with self.assertRaises(Exception) as context: power(100000, 5) self.assertIn( 'maximum recursion depth exceeded', context.exception.message, msg='You must use recursion when implementing replicate_recur.' )
def test_non_digit_argument(self): with self.assertRaises(TypeError) as context: base, exp = 'base', 'exp' res = power(base, exp) self.assertEqual('Argument must be interfer or float', context.exception.message, 'Only digits are allowed as input')
def dispatch(s): resolve = s.split() operation = resolve[1] try: resolve[0] = int(resolve[0]) resolve[2] = int(resolve[2]) except: pass if operation == "+": return add.add(resolve[0], resolve[2]) elif operation == "-": return minus.minus(resolve[0], resolve[2]) elif operation == "*": return multiply.multiply(resolve[0], resolve[2]) elif operation == "/": return divide.divide(resolve[0], resolve[2]) elif operation == "!": return factorial.factorial(resolve[0]) elif operation == "to_hex": return dec_to_hex.dec_to_hex(resolve[0]) elif operation == "to_bin": pass elif operation == "inv": return inverse.inverse(resolve[0]) elif operation == "**": return power.power(resolve[0], resolve[2])
def job(alist, nlist): assert len(alist) == len(nlist) result = [0] * len(alist) for i in range(len(alist)): result[i] = power(alist[i], nlist[i])
def main(): page = st.sidebar.selectbox('Pages', pages) if page == 'Home': st.title('Mo-Better') st.subheader('Understanding Statistical Tests and Sampling') st.write('(the more data the better)') st.write() st.markdown(""" I wanted to create a better way of visualizing and explaining different statistical concepts. Navigate to different pages in the sidebar to check it out! :) """) if page == 'Confidence Intervals': confidence_interval() if page == 'Power': power()
def test_power(self): """Testing power with base numbers 2-7 and exponents 2-7. (20p)""" base_numbers = [2,3,4,5,6,7] exponents = [2,3,4,5,6,7] for base in base_numbers: for exponent in exponents: your_answer = power(base, exponent) correct_answer = math.pow(base, exponent) self.assertEqual(correct_answer, your_answer, """With base: {} and exponent {} your function returned {}. \nCorrect answer is {}""".format(base, exponent, your_answer, correct_answer))
def test_001_t(self): # set up fg src_data1 = (2, 3, 4, 1, 4) src_data2 = (3, 3, 2, 4, -1) expected_data = (8, 27, 16, 1, 0.25) src1 = gr.vector_source_f(src_data1) src2 = gr.vector_source_f(src_data2) sqr = power() dst = gr.vector_sink_f() self.tb.connect(src1, (sqr, 0)) self.tb.connect(src2, (sqr, 1)) self.tb.connect(sqr, dst) self.tb.run() result_data = dst.data() print result_data self.assertFloatTuplesAlmostEqual(result_data, expected_data, 6)
def test_001_t (self): # set up fg src_data1 = (2,3,4,1,4) src_data2 = (3,3,2,4,-1) expected_data = (8,27,16,1,0.25) src1 = gr.vector_source_f(src_data1) src2 = gr.vector_source_f(src_data2) sqr = power() dst = gr.vector_sink_f() self.tb.connect(src1,(sqr,0)) self.tb.connect(src2,(sqr,1)) self.tb.connect(sqr,dst) self.tb.run () result_data = dst.data() print result_data self.assertFloatTuplesAlmostEqual(result_data,expected_data,6)
def shor(self, n): if miller_robin.miller_robin(n): return (1, n) else: tmp = power.power(n) if tmp != -1: return (tmp, n // tmp) else: if (n % 2 == 0): return (2, n // 2) while True: # Parrel computing for some random x xlist = random.sample(range(3, n - 1), self.Thread_Num) g = [gcd.gcd(x, n) for x in xlist] for idx, g in enumerate(g): if (g != 1): # ======= For debug =========== # while gcd.gcd(xlist[idx], n) != 1: # newx = random.randint(3, n - 1) # xlist[idx] = newx # ======= In Real Quantum Computer ========= return (g, n // g) print("======== Order Finding Started ========") threadPool = ThreadPool(processes=self.Thread_Num) results = [] for x in xlist: results.append( threadPool.apply_async(self.order_finding, args=(x, n))) threadPool.close() threadPool.join() results = [r.get() for r in results] for r in results: if r == -1: continue if (r % 2 == 0): s = fastPow.fastPow(x, r // 2, n) if (s != 1 and s != n - 1): g1 = gcd.gcd(s + 1, n) g2 = gcd.gcd(s - 1, n) if (g1 != 1): return (g1, n // g1) elif (g2 != 1): return (g2, n // g2)
def job(a_list, n_list): ''' La fonction job compte le nombre d'éléments de la liste ``a_list`` qui vérifient la condition suivante : power(a_list[i], n_list[i]) > 1000 ''' # faire la moyenne ne permet pas de tester une construction d'une nouvelle liste ... car # on va directement calculer la somme au fur et à mesure # joli exo mais un peu con ... on n'a jamais tellement travaillé le benchmarking ... results = [0] * len(a_list) for i in range(len(a_list)): results[i] = power(a_list[i], n_list[i]) return results
def test_b(): assert power(2, 2) == 4
def test_power_negative_base_even(): result = power(BigInteger("-2"), BigInteger("4")) assert_equals(result, BigInteger("16"))
def test_l(): assert power(3, 10) == 59049
def test_n(): assert power(1.1414, 2) == 1.30279
def test_h(): assert power(2, 8) == 256
def test_j(): assert power(3, 1) == 3
def test_e(): assert power(2, 5) == 32
def test_power_negative_base_odd(): result = power(BigInteger("-3"), BigInteger("3")) assert_equals(result, BigInteger("-27"))
def test_power_even_exponent(): result = power(BigInteger("3"), BigInteger("2")) assert_equals(result, BigInteger("9"))
""" import math #math library in python to do basic math from math import pow from math import pow as p #as lets you import variable in a different name #import django-admin -- third party module import power # ** = math.pow(x,y) print (math.pow(2,3)) # output 8.0, is a float print (math.ceil(5.4)) # output 6, next biggest integer, (rounds) print(power.power(3,4)) #output 81 ex. of imported module print(pow(2,3)) # output 8.0 print(p(2,3)) # output 8.0 # itertools, collections, cmath, math """ Functions - blocks of code that do stuff sectioned, scoped, takes input, may or may not return values ex. print, input, pow, int, str, format, center, ljust, rjust... def * ** """ #Function Examples:
def test_power_zero_base(): result = power(BigInteger("0"), BigInteger("3")) assert_equals(result, BigInteger("0"))
def test_power_zero_exponent(): result = power(BigInteger("2"), BigInteger("0")) assert_equals(result, BigInteger("1"))
def test_power_one_exponent(): result = power(BigInteger("3"), BigInteger("1")) assert_equals(result, BigInteger("3"))
def test_c(): assert power(2, 1) == 2
def test_g(): assert power(2, 7) == 128
def test_d(): assert power(2, 4) == 16
def test_power_negative_exponent(): assert_equals(power(BigInteger("3"), BigInteger("-2")), BigInteger("0"))
def test_f(): assert power(2, 6) == 64
def powercycle( ): print "Powercycling the device" power.power(0) time.sleep(1) power.power(1)
def test_a(): assert power(2, 3) == 8
def Wrapper(run_parameters): # Those are hardwier inside the Docker run_parameters['run directory'] = '/home/user/run/input/' run_parameters['saving directory'] = '/home/user/run/output/' ## check path and create it if not os.path.exists(run_parameters['run directory']): os.system('mkdir %s' % run_parameters['run directory']) ## copy the inputs os.system('cp /home/user/SSC/initial_files/*.in '\ '/home/user/SSC/initial_files/*.th.nc '\ '/home/user/SSC/initial_files/*.gr3 '\ '/home/user/SSC/initial_files/*.ll '\ '/home/user/SSC/initial_files/*.prop '\ ' %s' %(run_parameters['run directory'])) os.system('rm -rf %s/input_files/' % run_parameters['run directory']) ## Copy but don't replace the hotstart file os.system('cp -n /home/user/SSC/initial_files/hotstart.nc %s' % (run_parameters['run directory'])) sc = schismIO( run_parameters['run directory']) # this will combine he file as it run pw = power(sc) # this wil get the power after 1 tidal cycle pw.max_cycle = run_parameters.get('maximum cycle', 20) # set maximum number of tidal cycle if not os.path.exists(run_parameters['saving directory']): os.system('mkdir %s' % run_parameters['saving directory']) else: os.system('rm %s/schout_*.nc' % run_parameters['saving directory']) ## make an outputs directory for schism if not os.path.exists( os.path.join(run_parameters['run directory'], 'outputs')): os.system('mkdir %s' % os.path.join(run_parameters['run directory'], 'outputs')) else: # delete all the output os.system('rm %s' % os.path.join(run_parameters['run directory'], 'outputs/*')) ## create the parameter file set_params(run_parameters, os.path.join(run_parameters['run directory'], 'param.in')) ## create the GR3 with polygons and add the farms inside PW include_farm(run_parameters, pw) ## run SCHISM proc = run_schism('run', nproc=run_parameters.get('nproc', 3), schism='schism', proc=None, dirout=run_parameters['run directory']) print 'schism running in the background' sys.stdout.flush() ## Main loop in search of a steady state pw,n,nTC=search_steady_state(run_parameters['run directory'],\ pw,\ sc,\ run_parameters['params']['X']) ## save to saving directory pw.export_nc(n - 1, nTC, outdir=run_parameters['saving directory']) print 'schism data exported to %s' % run_parameters['saving directory'] ## kill schism run_schism('kill', proc=proc) print 'schism is killed' sys.stdout.flush()
def test_i(): assert power(2, 0) == 1
def formula(num1, num2): res = div.division(pow.power(num1)+sqrt.root(pow.power(pow.power(num2)-mod.module(num1)+5*num1*num2)),sqrt.root(pow.powe(pow.power(num1)-mod.module(num2)+5*num2*num1))-5) return res
def test_k(): assert power(3, 2) == 9
from param import param import subprocess import signal import time from schismIO import schismIO from power import power, get_areas import numpy as np from export_nc import export_nc from polygons import * import timeit from SSC import include_farm root = '//home/remy/Buisness/0336_SSC_tides/ross/working/multiple_turbine_test/in//' # My root directory ya = '/home/remy/Buisness/0336_SSC_tides/ross/working/multiple_turbine_test/in/multiple_turbine_test.yml' sc = schismIO(root) # this will combine he file as it run pw = power(sc) # this wil get the power after 1 tidal cycle with open(ya, 'r') as f: run_parameters = yaml.load(f) run_parameters[ 'run directory'] = '/home/remy/Buisness/0336_SSC_tides/ross/working/multiple_turbine_test/in/' include_farm(run_parameters, pw) pw.get_power(13) pw.export_nc( 13, 5, outdir= '//home/remy/Buisness/0336_SSC_tides/ross/working/multiple_turbine_test/out/', params=run_parameters['params'])
def test_m(): assert power(3, 0) == 1
def compute_results(i): print(a_list[i], n_list[i], power(a_list[i], n_list[i])) return power(a_list[i], n_list[i])
def test_o(): assert power(1.5, 10) == 57.665
def menu(): print("1-Addition \t\t 2-Subtration \t\t 3-Multiply \t\t 4-Division") print("5-Sin() \t\t 6-Cos() \t\t 7-Tan() \t\t 8-Sec()") print("9-Cosec() \t\t 10-Cot() \t\t 11-Square \t\t 12-Square Root \t\t") print("13-Power \t\t 14-Root \t\t 15-Expontial(e^x)") print("16-Factorial \t\t 17-log()\t\t 18-ln() \t\t 19-Quadratic Eq Solver") print( "20-Inverse(x^-1) \t 21-Sin inverse \t 22-Cos Inverse \t 23.Tan Inverse" ) print("24-Permutation \t\t 25-Combination \t 26-Percentage") print("27-Multiple Basic Operators At a time \t\t 28-Close") while True: try: choice = int(input("Enter your choice(press number):")) break except ValueError: print("Input must be a number!") if choice == 1: while True: Sum.Sum() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 2: while True: Sub.sub() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 3: while True: Mul.multiply() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 4: while True: divide.divide() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 5: while True: sin.sin() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 6: while True: cos.cos() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 7: while True: tan.tan() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 8: while True: sec.sec() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 9: while True: cosec.cosec() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 10: while True: cot.cot() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 11: while True: square.square() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 12: while True: sqrt.sqrt() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 13: while True: power.power() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 14: while True: root.root() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 15: while True: exponential.exponential() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 16: while True: factorial.factorial() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 17: while True: log.log() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 18: while True: ln.ln() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 19: while True: quadratic.quadratic() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 20: while True: inverse.inv() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 21: while True: asin.asin() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 22: while True: acos.acos() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 23: while True: atan.atan() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 24: while True: per.per() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 25: while True: com.com() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 26: while True: percentage.percentage() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 27: while True: combine() x = int(input("press 1 to try again,press 2 to return to menu")) if x == 1: continue if x == 2: menu() break elif choice == 28: close() else: print("Invalid Input.Try Again") menu()
# import power # print power.power(9,3) # power.power_test(); from power import power, power_test print power(9,3) power_test()
def test_power_large(): a = BigInteger("48446744073709551616") result = power(a, BigInteger("2")) assert_equals(result, BigInteger("2347087011343511560423374607431768211456"))