def time_evolution_circuit_improved(g_list, t, kickback_phase, k, n_trotter_step=1): n_qubits = 3 a_idx = 2 phi = -(t / n_trotter_step) * g_list # print(phi) circuit = QuantumCircuit(n_qubits) circuit.add_H_gate(a_idx) # Apply kickback phase rotation to ancilla bit circuit.add_RZ_gate(a_idx, -np.pi * kickback_phase / 2) for _ in range(n_trotter_step): for _ in range(2**k): # CU(Z0) circuit.add_RZ_gate(0, -phi[0]) circuit.add_CNOT_gate(a_idx, 0) circuit.add_RZ_gate(0, phi[0]) circuit.add_CNOT_gate(a_idx, 0) # CU(Y0 Y1) circuit.add_S_gate(0) circuit.add_S_gate(1) circuit.add_H_gate(0) circuit.add_H_gate(1) circuit.add_CNOT_gate(1, 0) circuit.add_RZ_gate(0, -phi[1]) circuit.add_CNOT_gate(a_idx, 0) circuit.add_RZ_gate(0, phi[1]) circuit.add_CNOT_gate(a_idx, 0) circuit.add_CNOT_gate(1, 0) circuit.add_H_gate(0) circuit.add_H_gate(1) circuit.add_Sdag_gate(0) circuit.add_Sdag_gate(1) # CU(Z1) circuit.add_RZ_gate(1, -phi[2]) circuit.add_CNOT_gate(a_idx, 1) circuit.add_RZ_gate(1, phi[2]) circuit.add_CNOT_gate(a_idx, 1) # CU(X0 X1) circuit.add_H_gate(0) circuit.add_H_gate(1) circuit.add_CNOT_gate(1, 0) circuit.add_RZ_gate(0, -phi[3]) circuit.add_CNOT_gate(a_idx, 0) circuit.add_RZ_gate(0, phi[3]) circuit.add_CNOT_gate(a_idx, 0) circuit.add_CNOT_gate(1, 0) circuit.add_H_gate(0) circuit.add_H_gate(1) circuit.add_H_gate(a_idx) return circuit
def test_CU_Y0Y1(self): n_qubits = 3 a_idx = 2 theta = np.pi/4 state = QuantumState(n_qubits) input_states_bin = [0b001, 0b010, 0b101, 0b110] input_states = [] output_states = [] circuit = QuantumCircuit(n_qubits) # change basis from Z to Y circuit.add_S_gate(0) circuit.add_S_gate(1) circuit.add_H_gate(0) circuit.add_H_gate(1) circuit.add_CNOT_gate(1, 0) # RZ circuit.add_RZ_gate(0, -0.5*theta) circuit.add_CNOT_gate(a_idx, 0) circuit.add_RZ_gate(0, 0.5*theta) circuit.add_CNOT_gate(a_idx, 0) circuit.add_CNOT_gate(1, 0) # change basis from Z to Y circuit.add_H_gate(0) circuit.add_H_gate(1) circuit.add_Sdag_gate(0) circuit.add_Sdag_gate(1) for b in input_states_bin: psi = state.copy() psi.set_computational_basis(b) input_states += [psi] psi_out = psi.copy() circuit.update_quantum_state(psi_out) output_states += [psi_out] p_list = [] for in_state in input_states: for out_state in output_states: prod = inner_product(in_state, out_state) p_list += [prod] # |001> exp_list = [1.0, 0.0, 0.0, 0.0] # |010> exp_list += [0.0, 1.0, 0.0, 0.0] # |101> exp_list += [0.0, 0.0, np.cos(theta/2), complex(0, -np.sin(theta/2))] # |110> exp_list += [0.0, 0.0, complex(0, -np.sin(theta/2)), np.cos(theta/2)] for result, expected in zip(p_list, exp_list): self.assertAlmostEqual(result, expected, places=6)