pylarc.print_naive_by_matID(F_3) ################################# # create FFT matrices in python # ################################# print("\nCreate a vector\n") A_arr = list(map(str, [1, 0, 0, 0, 0, 1, 0, 0])) rowLevel = 3 colLevel = 0 dimWhole = 1 << colLevel A_mID = pylarc.row_major_list_to_store_matrixID(A_arr, rowLevel, colLevel, dimWhole) pylarc.print_naive_by_matID(A_mID) print("Now multiply FFT matrix by the vector to get the result\n") B_mID = pylarc.matrix_mult_matrixID(F_3, A_mID) pylarc.print_naive_by_matID(B_mID) ################################# # precision test # ################################# k = 3 print("\nCalculating the principal 2^%d-th root of unity:" % k) root_matID = pylarc.principal_pow2_root_unity(k) print("\nPrinting 2^%d-th root of unity:" % k) pylarc.print_naive_by_matID(root_matID) exp2Root_mID = pylarc.matrix_mult_matrixID(root_matID, root_matID)
print("testing scalar_mult:") samp2_matrixID = pylarc.scalar_mult_matrixID(scalarM1_matrixID, samp_matrixID) pylarc.print_naive_by_matID(samp2_matrixID) print("testing addition:") samp3_matrixID = pylarc.matrix_add_matrixID(samp_matrixID, samp2_matrixID) pylarc.print_naive_by_matID(samp3_matrixID) print("testing adjoint:") samp3_matrixID = pylarc.matrix_adjoint_matrixID(samp_matrixID) pylarc.print_naive_by_matID(samp3_matrixID) print("testing non-square matrix mult:") samp4_matrixID = pylarc.matrix_mult_matrixID(samp3_matrixID, samp_matrixID) pylarc.print_naive_by_matID(samp4_matrixID) print("") samp4_matrixID = pylarc.matrix_mult_matrixID(samp_matrixID, samp3_matrixID) pylarc.print_naive_by_matID(samp4_matrixID) print("testing kron product:") samp4_matrixID = pylarc.kronecker_product_matrixID(samp_matrixID, samp_matrixID) pylarc.print_naive_by_matID(samp4_matrixID) print("testing join:") samp4_matrixID = pylarc.join_matrixID(samp_matrixID, samp_matrixID) pylarc.print_naive_by_matID(samp4_matrixID) print("testing stack:") samp4_matrixID = pylarc.stack_matrixID(samp_matrixID, samp_matrixID) pylarc.print_naive_by_matID(samp4_matrixID)
arr_prod1 = list(map(str, [.16, 0, 0, .09])) prod1_mID = pylarc.row_major_list_to_store_matrixID( arr_prod1, level, level, dim_whole) arr_e = list(map(str, [1, -1, -1, 1])) e_mID = pylarc.row_major_list_to_store_matrixID(arr_e, level, level, dim_whole) print("\nmatrix e:") pylarc.print_naive_by_matID(e_mID) arr_prod2 = list(map(str, [.4, -.4, -.3, .3])) prod2_mID = pylarc.row_major_list_to_store_matrixID( arr_prod2, level, level, dim_whole) print("\nThe matrixIDs of prod1, e, and prod2 are %d %d %d\n" % (prod1_mID, e_mID, prod2_mID)) m_mID = pylarc.matrix_mult_matrixID(a_mID, a_mID) n_mID = pylarc.matrix_mult_matrixID(a_mID, e_mID) print("The matrixIDs of m and n are %d %d\n" % (m_mID, n_mID)) print("Matrix id of a * a: %d, should be that of prod1: %d \n" % (m_mID, prod1_mID)) if (m_mID == prod1_mID): print("a * a PASSED:") pylarc.print_naive_by_matID(m_mID) else: print("FAILED: [.4,0,0,.3] * [.4,0,0,.3] = [.16, 0, 0, .09]\n") print("\nMatrix id of a * e: %d, should be that of prod2: %d \n" % (n_mID, prod2_mID)) if (n_mID == prod2_mID): print("a * e PASSED:") pylarc.print_naive_by_matID(n_mID)
n_array[k] = pylarc.k_th_power_of_n_th_root_of_unity_matID( k, n, call_verbose) print("\nHere is the array of the %dth roots of unity:" % n) print(n_array) if (verbose > 1): print("\nThe stored values of these roots are:") print("") for k in range(n): pylarc.print_naive_by_matID(n_array[k]) print("") print("\nNow we can look to see if multiplication is closed, by looking") print("at the matrixIDs of products of pairs of these roots.") success = 1 for k in range(n): for j in range(k + 1): my_matrixID = pylarc.matrix_mult_matrixID(n_array[j], n_array[k]) flag = 0 # initialize as though there was a closure failure for i in range(n): if (my_matrixID == n_array[i]): flag = 1 # we found the matrixID of product in the preloaded roots if (flag == 0): success = 0 print( "\nMatrix multiplication of the %d-th roots of unity is not closed" % n) print("since the product of the %d-th power and %d-th power" % ( j, k, )) m = (j + k) % n
# build a Toffoli (base unit for reversible computing) print("\nThe 3 bit reversible AND (Toffoli) matrix with target 3rd.\n") # get_matID_from_four_subMatIDs is under construction TOFFOLI_matrixID= pylarc.get_matID_from_four_subMatIDs(I2_matrixID,Z2_matrixID,Z2_matrixID,CNOT_matrixID,3,3) pylarc.print_naive_by_matID(TOFFOLI_matrixID) filename = "../dat/out/toffoli.%s.naive" %scalarTypeStr pylarc.write_naive_by_matID(TOFFOLI_matrixID,os.path.join(os.path.dirname(__file__),filename)) # use Toffoli to build a NAND print("\nHere is the 3 bit reversible NAND matrix with target 3rd.\n") # build 8x8 matrix I tensor I tensor X NOT_matrixID = pylarc.cvar.matID_NOT; I1_matrixID = pylarc.get_identity_matrixID(1); not3_matrixID = pylarc.kronecker_product_matrixID(I1_matrixID,pylarc.kronecker_product_matrixID(I1_matrixID, NOT_matrixID)); nand_from_Toff_matrixID = pylarc.matrix_mult_matrixID(not3_matrixID,TOFFOLI_matrixID); pylarc.print_naive_by_matID(nand_from_Toff_matrixID) filename = "../dat/out/nandfromtoff.%s.naive" %scalarTypeStr pylarc.write_naive_by_matID(nand_from_Toff_matrixID,os.path.join(os.path.dirname(__file__),filename)) # build from panels print("\nHere is the 3 bit reversible NAND matrix with target 3rd, constructed a different way.\n") Z1_matrixID = pylarc.get_zero_matrixID(1,1); topleft_matrixID = pylarc.get_matID_from_four_subMatIDs(NOT_matrixID,Z1_matrixID,Z1_matrixID,NOT_matrixID,2,2); botright_matrixID = pylarc.get_matID_from_four_subMatIDs(NOT_matrixID,Z1_matrixID,Z1_matrixID,I1_matrixID,2,2); nand_from_panels_matrixID = pylarc.get_matID_from_four_subMatIDs(topleft_matrixID,Z2_matrixID,Z2_matrixID,botright_matrixID,3,3); pylarc.print_naive_by_matID(nand_from_panels_matrixID) filename = "../dat/out/nandfrompanels.%s.naive" %scalarTypeStr pylarc.write_naive_by_matID(nand_from_panels_matrixID,os.path.join(os.path.dirname(__file__),filename)) # compare with other nands if (nand_from_Toff_matrixID != nand_matrixID): print("problem with building NAND from Toffoli")
################################# # create FFT matrices in python # ################################# print("\nF_1 matrix is:") F_1 = pylarc.create_fft_matrix_matrixID(1) pylarc.print_naive_by_matID(F_1) print("\nF_2 matrix is:") F_2 = pylarc.create_fft_matrix_matrixID(2) pylarc.print_naive_by_matID(F_2) print("\nF_3 matrix is:") F_3 = pylarc.create_fft_matrix_matrixID(3) pylarc.print_naive_by_matID(F_3) ################################# # create FFT matrices in python # ################################# print("\nCreate a vector\n") A_arr = list(map(str, [1, 0, 0, 0, 0, 1, 0, 0])) rowLevel = 3 colLevel = 0 dimWhole = 1 << colLevel A_mID = pylarc.row_major_list_to_store_matrixID(A_arr, rowLevel, colLevel, dimWhole) pylarc.print_naive_by_matID(A_mID) print("Now multiply FFT matrix by the vector to get the result\n") B_mID = pylarc.matrix_mult_matrixID(F_3, A_mID) pylarc.print_naive_by_matID(B_mID)
pylarc.print_naive_by_matID(I2_mID) # build a Toffoli (base unit for reversible computing) print("\nThe 3 bit reversible AND (Toffoli) matrix with target 3rd.\n") # get_matID_from_four_subMatIDs is under construction TOFFOLI_mID= pylarc.get_matID_from_four_subMatIDs(I2_mID,Z2_mID,Z2_mID,CNOT_mID,3,3) pylarc.print_naive_by_matID(TOFFOLI_mID) filename = "../dat/out/toffoli.%s.naive" %scalarTypeStr pylarc.write_naive_by_matID(TOFFOLI_mID,os.path.join(os.path.dirname(__file__),filename)) # use Toffoli to build an NAND print("\nHere is the 3 bit reversible NAND matrix with target 3rd.\n") NOT_matrixID = pylarc.cvar.matID_NOT; I1_matrixID = pylarc.get_identity_matrixID(1); not3_matrixID = pylarc.kronecker_product_matrixID(I1_matrixID,pylarc.kronecker_product_matrixID(I1_matrixID, NOT_matrixID)); nand_from_Toff_matrixID = pylarc.matrix_mult_matrixID(not3_matrixID,TOFFOLI_mID); pylarc.print_naive_by_matID(nand_from_Toff_matrixID) filename = "../dat/out/nandfromtoff.%s.naive" %scalarTypeStr pylarc.write_naive_by_matID(nand_from_Toff_matrixID,os.path.join(os.path.dirname(__file__),filename)) # PLAYING WITH PREWRITTEN NONSQUARE MATRIX filename = "../dat/in/sample.1.2.%s.json" %scalarTypeStr print("About to test read %s\n" %filename) samp_mID = pylarc.read_larcMatrix_file_return_matID(os.path.join(os.path.dirname(__file__),filename)) print("We read in the LARCMatrix file\n") pylarc.print_naive_by_matID(samp_mID) print("does scalarM1_val print?") scalarM1_val = '-1' scalarM1_mID = pylarc.get_valID_from_valString(scalarM1_val) pylarc.print_naive_by_matID(scalarM1_mID)
arr = pylarc.map_to_str(alist, scalarTypeStr) # print 'arr:', pylarc.str_scalarTypeArray(arr, len(alist)) # creating or finding the matrix associated with the array top_ID = pylarc.row_major_list_to_store_matrixID(arr, level, level, dim_whole) # filename_json = "../dat/out/toeplitz.lev%d.%s.json" %(level,scalarTypeStr) # pylarc.print_naive_by_matID(serial) # print("\n") # pylarc.write_larcMatrix_file_by_matID(serial,os.path.join(os.path.dirname(__file__),filename_json)) ## END OF CODE STOLEN FROM toeplitz.py # some operations to put in the store A_ID = pylarc.matrix_add_matrixID(top_ID, top_ID) B_ID = pylarc.matrix_mult_matrixID(A_ID, top_ID) # ############################# # # test reporting # ############################# # pylarc.matrix_store_report("../dat/out/temp.mat_report") # pylarc.op_store_report("../dat/out/temp.op_report") # pylarc.rusage_report(0,"../dat/out/temp.rusage0_report") # pylarc.rusage_report(1,"../dat/out/temp.rusage1_report") print("\n") pylarc.matrix_store_report("stdout") print("\n") pylarc.op_store_report("stdout") print("\n") pylarc.rusage_report(0, "stdout")