def test_transformation_by_pauli(self):
        n = NoiseTransformer()
        # polarization in the XY plane; we represent via Kraus operators
        X = self.ops['X']
        Y = self.ops['Y']
        Z = self.ops['Z']
        p = 0.22
        theta = numpy.pi / 5
        E0 = numpy.sqrt(1 - p) * numpy.array(numpy.eye(2))
        E1 = numpy.sqrt(p) * (numpy.cos(theta) * X + numpy.sin(theta) * Y)
        results = approximate_quantum_error((E0, E1),
                                            operator_dict={
                                                "X": X,
                                                "Y": Y,
                                                "Z": Z})
        expected_results = pauli_error(
            [('X', p * numpy.cos(theta) * numpy.cos(theta)),
             ('Y', p * numpy.sin(theta) * numpy.sin(theta)), ('Z', 0),
             ('I', 1 - p)])
        self.assertErrorsAlmostEqual(expected_results, results)

        # now try again without fidelity; should be the same
        n.use_honesty_constraint = False
        results = approximate_quantum_error((E0, E1),
                                            operator_dict={
                                                "X": X,
                                                "Y": Y,
                                                "Z": Z})
        self.assertErrorsAlmostEqual(expected_results, results)
 def test_fidelity(self):
     n = NoiseTransformer()
     expected_fidelity = {'X': 0, 'Y': 0, 'Z': 0, 'H': 0, 'S': 2}
     for key in expected_fidelity:
         self.assertAlmostEqual(expected_fidelity[key],
                                n.fidelity([self.ops[key]]),
                                msg="Wrong fidelity for {}".format(key))
 def setUp(self):
     self.ops = {
         'X': standard_gate_unitary('x'),
         'Y': standard_gate_unitary('y'),
         'Z': standard_gate_unitary('z'),
         'H': standard_gate_unitary('h'),
         'S': standard_gate_unitary('s')
     }
     self.n = NoiseTransformer()