Example #1
0
 def _trace_distance_bound_(self) -> Optional[float]:
     if self._is_parameterized_():
         return None
     u = protocols.unitary(self.sub_gate, default=None)
     if u is None:
         return NotImplemented
     angle_list = np.append(np.angle(np.linalg.eigvals(u)), 0)
     return protocols.trace_distance_from_angle_list(angle_list)
Example #2
0
def cost_fn_google(theta, l, expected_unitary):
    from cirq.protocols import trace_distance_from_angle_list
    n = int(np.log2(len(expected_unitary)))
    response_unitary = ansatz_U(n,
                                l,
                                theta,
                                output_gradient=False,
                                return_as_matrix=True)
    u = response_unitary @ expected_unitary.conj().T
    return trace_distance_from_angle_list(np.angle(np.linalg.eigvals(u)))
Example #3
0
 def _trace_distance_bound_(self) -> Optional[float]:
     if protocols.is_parameterized(self._exponent):
         return None
     angles = np.pi * (np.array(self._eigen_shifts()) * self._exponent % 2)
     return protocols.trace_distance_from_angle_list(angles)
Example #4
0
def cost_fn(theta, l, expected_unitary):
    n = int(np.log2(len(expected_unitary)))
    response_unitary = U_from_theta(theta, n, l)
    u = response_unitary @ expected_unitary.conj().T
    return trace_distance_from_angle_list(np.angle(np.linalg.eigvals(u)))