Beispiel #1
0
 def test_experiment_config(self):
     """Test converting to and from config works"""
     exp = RoughXSXAmplitudeCal(0, self.cals)
     config = exp.config()
     loaded_exp = RoughXSXAmplitudeCal.from_config(config)
     self.assertNotEqual(exp, loaded_exp)
     self.assertEqual(config, loaded_exp.config())
    def test_update(self):
        """Test that the calibrations update properly."""

        self.assertTrue(np.allclose(self.cals.get_parameter_value("amp", 0, "x"), 0.5))
        self.assertTrue(np.allclose(self.cals.get_parameter_value("amp", 0, "sx"), 0.25))

        rabi_ef = RoughXSXAmplitudeCal(0, self.cals)
        expdata = rabi_ef.run(RabiBackend(amplitude_to_angle=np.pi * 1.5))
        self.assertExperimentDone(expdata)

        tol = 0.002
        self.assertTrue(abs(self.cals.get_parameter_value("amp", 0, "x") - 0.333) < tol)
        self.assertTrue(abs(self.cals.get_parameter_value("amp", 0, "sx") - 0.333 / 2) < tol)
    def test_circuits(self):
        """Test the quantum circuits."""
        test_amps = [-0.5, 0, 0.5]
        rabi = RoughXSXAmplitudeCal(0, self.cals, amplitudes=test_amps)

        circs = transpile(rabi.circuits(), self.backend, inst_map=rabi.transpile_options.inst_map)

        for circ, amp in zip(circs, test_amps):
            self.assertEqual(circ.count_ops()["Rabi"], 1)

            d0 = pulse.DriveChannel(0)
            with pulse.build(name="x") as expected_x:
                pulse.play(pulse.Drag(160, amp, 40, 0), d0)

            self.assertEqual(circ.calibrations["Rabi"][((0,), (amp,))], expected_x)