Ejemplo n.º 1
0
    def test_discrimination(self):
        """
        Test that the discriminator can be trained on the simulated data and
        that it can properly discriminate between ground and excited sates.
        """
        i0, q0, i1, q1 = 0., -1., 0., 1.
        discriminator = LinearIQDiscriminator(self.cal_results, self.qubits,
                                              ['00', '11'])

        excited_predicted = discriminator.discriminate([[i1, q1, i1, q1]])
        ground_predicted = discriminator.discriminate([[i0, q0, i0, q0]])

        self.assertEqual(excited_predicted[0], '11')
        self.assertEqual(ground_predicted[0], '00')
Ejemplo n.º 2
0
    def filter_and_discriminate(self):
        """
        Test the process of discriminating and then applying the discriminator
        using a filter.
        """
        i0, q0, i1, q1 = 0., -1., 0., 1.

        discriminator = LinearIQDiscriminator(self.cal_results, self.qubits,
                                              ['00', '11'])

        iq_filter = DiscriminationFilter(discriminator)

        new_result = iq_filter.apply(self.cal_results)

        for nr in new_result.results:
            self.assertEqual(nr.meas_level, 2)

        for state in new_result.results[0].data.counts.to_dict():
            self.assertEqual(state, '0x0')

        for state in new_result.results[1].data.counts.to_dict():
            self.assertEqual(state, '0x3')

        self.assertEqual(len(new_result.get_memory(0)), self.shots)

        self.qubits = [0]

        discriminator = LinearIQDiscriminator(self.cal_results, self.qubits,
                                              ['0', '1'])

        self.assertEqual(discriminator.discriminate([[i0, q0]])[0], '0')
        self.assertEqual(discriminator.discriminate([[i1, q1]])[0], '1')