示例#1
0
 def test_reflections(self):
     """Check that reflection circuits behave as expected."""
     for name in reflection_options:
         coordinate = [self.rng.random() for _ in range(3)]
         reflected_coordinate, reflection_circuit, reflection_phase = apply_reflection(
             name, coordinate
         )
         original_matrix = canonical_matrix(*coordinate)
         reflected_matrix = canonical_matrix(*reflected_coordinate)
         reflect_matrix = Operator(reflection_circuit).data
         with np.printoptions(precision=3, suppress=True):
             print(name)
             print(reflect_matrix.conjugate().transpose(1, 0) @ original_matrix @ reflect_matrix)
             print(reflected_matrix * reflection_phase)
         self.assertTrue(
             np.all(
                 np.abs(
                     reflect_matrix.conjugate().transpose(1, 0)
                     @ original_matrix
                     @ reflect_matrix
                     - reflected_matrix * reflection_phase
                 )
                 < EPSILON
             )
         )
示例#2
0
 def test_rotations(self):
     """Check that rotation circuits behave as expected."""
     for permutation in permutations([0, 1, 2]):
         coordinate = [self.rng.random() for _ in range(3)]
         rotation_circuit = canonical_rotation_circuit(permutation[0], permutation[1])
         original_matrix = canonical_matrix(*coordinate)
         rotation_matrix = Operator(rotation_circuit).data
         rotated_matrix = canonical_matrix(
             coordinate[permutation[0]],
             coordinate[permutation[1]],
             coordinate[permutation[2]],
         )
         self.assertTrue(
             np.all(
                 np.abs(
                     rotation_matrix.conjugate().transpose(1, 0)
                     @ original_matrix
                     @ rotation_matrix
                     - rotated_matrix
                 )
                 < EPSILON
             )
         )