def testing_d_gate(n_qbits): n = n_qbits d_gate = create_d_gate(n) print('\nd_gate\n', d_gate) # print(np.array(d_gate, dtype = float)) psi = apply_n_tensor_to(n, qubit_one) print('\ninitial psi') print_psi(psi) psi = apply_gate_to_psi(d_gate, psi) print('\napplying d_gate to psi') print_psi(psi)
def testing_controlled_n_a_gate_v1(n_qbits): n = n_qbits controlled_n_a_gate = create_controlled_n_a_gate_v1(n) print('\nc_n_a_gate version 1\n', controlled_n_a_gate) # print(np.array(controlled_n_a_gate, dtype = float)) psi = apply_tensor(qubit_one, qubit_one) psi = apply_tensor(psi, qubit_one) print('\npsi inicial') print_psi(psi) psi = apply_gate_to_psi(controlled_n_a_gate, psi) print('\napplying controlled_n_a_gate to psi') print_psi(psi)
def testing_controlled_n_a_gate_with_ancilla(n_qbits): n = n_qbits controlled_n_a_gate_with_ancilla = create_controlled_n_a_gate_with_ancilla( n + 1) print('\ncontrolled_n_a_gate_with_ancilla\n', controlled_n_a_gate_with_ancilla) # print(np.array(controlled_n_a_gate, dtype = float)) psi = apply_tensor(qubit_one, qubit_one) psi = apply_tensor(psi, qubit_one) print('\npsi inicial') print_psi(psi) psi = apply_gate_to_psi(controlled_n_a_gate_with_ancilla, apply_tensor(psi, qubit_zero)) print('\napplying controlled_n_a_gate_with_ancilla to psi') print_psi(psi)
def comparing_n_a_gate_v1_and_n_a_gate_with_ancilla(n_qbits): n = n_qbits controlled_n_a_gate = create_controlled_n_a_gate_v1(n) print('\nc_n_a_gate version 1\n', controlled_n_a_gate) # print(np.array(controlled_n_a_gate, dtype = float)) controlled_n_a_gate_with_ancilla = create_controlled_n_a_gate_with_ancilla( n + 1) print('\nc_n_a_gate with ancilla\n', controlled_n_a_gate_with_ancilla) # print(np.array(controlled_n_a_gate_with_ancilla, dtype = float)) psi = apply_tensor(qubit_one, qubit_one) psi = apply_tensor(psi, qubit_one) print('\npsi inicial') print_psi(psi) psi_temp = apply_gate_to_psi(controlled_n_a_gate, psi) print('\napply controlled_n_a_gate to psi') print_psi(psi_temp) psi_temp = apply_gate_to_psi(controlled_n_a_gate_with_ancilla, apply_tensor(psi, qubit_zero)) print('\napply controlled_n_a_gate_with_ancilla to psi') print_psi(psi_temp)
tensor_h = apply_n_tensor_to(n + 1, h) # Creating tensor Identity_Hadamard tensor_i_h = apply_tensor(tensor_i, h) # Creating projection_operator projection_operator = apply_tensor( tensor_i, np.dot(qubit_zero, np.transpose(qubit_zero))) ############################################################ ####### Circuit Execution ################################## ############################################################ # psi_0 - Creating tensor product between inputs: |000000> psi = apply_n_tensor_to(n + 1, qubit_zero) print("\npsi_0 - Creating tensor product between inputs: |000000>\n") print_psi(psi) # psi_1 - Applying tensor_h (divider) to psi_0 psi = apply_gate_to_psi(tensor_h, psi) print("\npsi_1 - Applying tensor_h (divider) to psi\n") print_psi(psi) # psi_2 - Applying oracle to psi_1 psi = apply_gate_to_psi(oracle, psi) print("\npsi_2 - Applying oracle to psi\n") print_psi(psi) # psi_3 - Applying controlled_u_1 to psi_2 psi = apply_gate_to_psi(controlled_u_1, psi) print("\npsi_3 - Applying controlled_u_1 to psi\n") print_psi(psi)
print("\nu_tau") print(u_tau.real) # Creating v gate (qwd) # On the article it is defined in equation 11 v = create_n_4_qwd_gate(n, m) print("\nv operator") print(v) # Creating controlled_0_Us (controlled_0_u_0) # On the article, in equation 15, the u_s is defined as: # u_s = 2 * |psi_0><psi_0| - identity # On the article, in equation 8, the |psi_0> is defined as: psi_0 = apply_n_tensor_to(n, qubit_zero) print("psi_0") print_psi(psi_0) psi_0 = apply_gate_to_psi(tensor_h, psi_0) print("psi_0") print_psi(psi_0) # |psi_0><psi_0| psi_0_transposed_psi_0 = np.dot(psi_0, np.transpose(psi_0)) print("psi_0_transposed_psi_0") print(psi_0_transposed_psi_0) # 2 * |psi_0><psi_0| - identity u_s = 2 * psi_0_transposed_psi_0 - tensor_i print("u_s") print(u_s) # u_s = 2 * items_to_search_projector - tensor_i