def U_c(): """Unitary matrix rotating the ground state of the ancillary qubits to |sqrt(c)> = U_c |0>.""" # Circuit mapping |00> to sqrt_c[0] |00> + sqrt_c[1] |01> + sqrt_c[2] |10> qml.RY(-2 * np.arccos(sqrt_c[0]), wires=ancilla_idx) qml.CRY(-2 * np.arctan(sqrt_c[2] / sqrt_c[1]), wires=[ancilla_idx, ancilla_idx + 1]) qml.CNOT(wires=[ancilla_idx + 1, ancilla_idx])
def QNNLayer(self, params): ''' Definition of a single ST step for layering QNN ''' ExcInts = params[0:3] ExtField = params[3:6] # Parameters for external # field evol Hx = ExtField[0] Hy = ExtField[1] Hz = ExtField[2] H = np.sqrt(Hx**2 + Hy**2 + Hz**2) # Parameter values for Qiskit PHI = np.arctan2(Hy, Hx) + 2*np.pi THETA = np.arccos(Hz/H) LAMBDA = np.pi # Cascade Spin pair interaction for idx in range(self.num_spins-1): # Convert to computational basis qml.CNOT(wires=[idx, idx+1]) qml.Hadamard(wires=idx) # Compute J3 phase qml.RZ(ExcInts[2], wires=idx+1) # Compute J1 phase qml.RZ(ExcInts[0], wires=idx) # Compute J2 Phase qml.CNOT(wires=[idx, idx+1]) qml.RZ(-ExcInts[1], wires=idx+1) qml.CNOT(wires=[idx, idx+1]) # Return to computational basis qml.Hadamard(wires=idx) qml.CNOT(wires=[idx, idx+1]) # Include external field qml.U3(-THETA, -LAMBDA, -PHI, wires=idx) qml.RZ(H, wires=idx) qml.U3(THETA, PHI, LAMBDA, wires=idx) # Include external field for last spin qml.U3(-THETA, -LAMBDA, -PHI, wires=self.num_spins-1) qml.RZ(H, wires=self.num_spins-1) qml.U3(THETA, PHI, LAMBDA, wires=self.num_spins-1)
def compute_K(generator): """Compute the K hyperparameter controlling # iterations of amplification. Args: generator: An initialized circuit generator (one of the ones above) """ np.random.seed(0) N = 50 target_prob_list = [ generator.target_prob([ np.random.uniform(low=0, high=2 * np.pi) for j in range(generator.num_qubits) ]) for _ in range(N) ] cosphi_list = [2 * p - 1 for p in target_prob_list] cosPhi, cosPhi_error = np.mean( cosphi_list), np.std(cosphi_list) / np.sqrt(N) Phi = np.arccos(cosPhi) K = int(np.pi / (2 * (np.pi - Phi))) return K
def U_c_dagger(): """Adjoint of U_c.""" qml.CNOT(wires=[ancilla_idx + 1, ancilla_idx]) qml.CRY(2 * np.arctan(sqrt_c[2] / sqrt_c[1]), wires=[ancilla_idx, ancilla_idx + 1]) qml.RY(2 * np.arccos(sqrt_c[0]), wires=ancilla_idx)