コード例 #1
0
    def test_xp(self):
        """Test a circuit with the x gate."""

        amp_cal = FineXAmplitude(0)
        circs = amp_cal.circuits()

        self.assertTrue(circs[0].data[0][0].name == "x")

        for idx, circ in enumerate(circs[1:]):
            self.assertTrue(circ.data[0][0].name == "sx")
            self.assertEqual(circ.count_ops().get("x", 0), idx)
コード例 #2
0
    def test_enable_restless(self):
        """Test the enable_restless method."""

        error = -np.pi * 0.01
        backend = MockRestlessFineAmp(error, np.pi, "x")

        amp_exp = FineXAmplitude(0, backend)
        amp_exp.enable_restless(rep_delay=2e-6)

        self.assertTrue(
            amp_exp.run_options,
            Options(meas_level=2,
                    rep_delay=2e-6,
                    init_qubits=False,
                    memory=True,
                    use_measure_esp=False),
        )
コード例 #3
0
    def test_end_to_end_over_rotation(self, pi_ratio):
        """Test the experiment end to end."""

        amp_exp = FineXAmplitude(0)
        amp_exp.set_transpile_options(basis_gates=["x", "sx"])

        error = np.pi * pi_ratio
        backend = MockIQBackend(FineAmpHelper(error, np.pi, "x"))
        expdata = amp_exp.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        d_theta = result.value.n

        tol = 0.04

        self.assertAlmostEqual(d_theta, error, delta=tol)
        self.assertEqual(result.quality, "good")
コード例 #4
0
    def test_fine_x_amp(self):
        """Test the fine X amplitude."""

        exp = FineXAmplitude(0)

        self.assertTrue(exp.experiment_options.add_sx)
        self.assertTrue(exp.experiment_options.add_xp_circuit)
        self.assertEqual(exp.analysis.options.angle_per_gate, np.pi)
        self.assertEqual(exp.analysis.options.phase_offset, np.pi / 2)
        self.assertEqual(exp.experiment_options.gate, XGate())
コード例 #5
0
    def test_end_to_end_restless(self, pi_ratio):
        """Test the restless experiment end to end."""

        error = -np.pi * pi_ratio
        backend = MockRestlessFineAmp(error, np.pi, "x")

        amp_exp = FineXAmplitude(0, backend)
        amp_exp.enable_restless(rep_delay=1e-6)

        expdata = amp_exp.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        d_theta = result.value.n

        self.assertAlmostEqual(d_theta, error, delta=0.01)
        self.assertEqual(result.quality, "good")

        # check that the fit amplitude is almost 1 as expected.
        amp_fit = expdata.analysis_results(0).value[0]
        self.assertAlmostEqual(amp_fit, 1.0, delta=0.02)
コード例 #6
0
    def test_fine_x_amp(self):
        """Test the fine X amplitude."""

        exp = FineXAmplitude(0)

        self.assertTrue(exp.experiment_options.add_cal_circuits)
        self.assertDictEqual(
            exp.analysis.options.fixed_parameters,
            {"angle_per_gate": np.pi, "phase_offset": np.pi / 2},
        )
        self.assertEqual(exp.experiment_options.gate, XGate())
コード例 #7
0
    def test_end_to_end_restless_standard_processor(self, pi_ratio):
        """Test the restless experiment with a standard processor end to end."""

        error = -np.pi * pi_ratio
        backend = MockRestlessFineAmp(error, np.pi, "x")

        amp_exp = FineXAmplitude(0, backend)
        # standard data processor.
        standard_processor = DataProcessor("counts", [Probability("01")])
        amp_exp.analysis.set_options(data_processor=standard_processor)
        # enable a restless measurement setting.
        amp_exp.enable_restless(rep_delay=1e-6,
                                override_processor_by_restless=False)

        expdata = amp_exp.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        d_theta = result.value.n

        self.assertTrue(abs(d_theta - error) > 0.01)

        # check that the fit amplitude is much smaller than 1.
        amp_fit = expdata.analysis_results(0).value[0]
        self.assertTrue(amp_fit < 0.05)
コード例 #8
0
 def test_x_roundtrip_serializable(self):
     """Test round trip JSON serialization"""
     exp = FineXAmplitude(0)
     self.assertRoundTripSerializable(exp, self.json_equiv)