Beispiel #1
0
    def test_t1_parallel(self):
        """
        Test parallel experiments of T1 using a simulator.
        """

        t1 = [25, 15]
        delays = list(range(1, 40, 3))

        exp0 = T1(0, delays)
        exp2 = T1(2, delays)
        par_exp = ParallelExperiment([exp0, exp2])
        res = par_exp.run(T1Backend([t1[0], None, t1[1]]))
        self.assertExperimentDone(res)

        for i in range(2):
            sub_res = res.child_data(i).analysis_results("T1")
            self.assertEqual(sub_res.quality, "good")
            self.assertAlmostEqual(sub_res.value.n, t1[i], delta=3)

        res.service = FakeService()
        res.save()
        loaded_data = ExperimentData.load(res.experiment_id, res.service)

        for i in range(2):
            sub_res = res.child_data(i).analysis_results("T1")
            sub_loaded = loaded_data.child_data(i).analysis_results("T1")
            self.assertEqual(repr(sub_res), repr(sub_loaded))
Beispiel #2
0
    def test_t1_parallel_different_analysis_options(self):
        """
        Test parallel experiments of T1 using a simulator, for the case where
        the sub-experiments have different analysis options
        """

        t1 = 25
        delays = list(range(1, 40, 3))

        exp0 = T1(0, delays)
        exp0.analysis.set_options(p0={"tau": 30})
        exp1 = T1(1, delays)
        exp1.analysis.set_options(p0={"tau": 1000000})

        par_exp = ParallelExperiment([exp0, exp1])
        res = par_exp.run(T1Backend([t1, t1]))
        self.assertExperimentDone(res)

        sub_res = []
        for i in range(2):
            sub_res.append(res.child_data(i).analysis_results("T1"))

        self.assertEqual(sub_res[0].quality, "good")
        self.assertAlmostEqual(sub_res[0].value.n, t1, delta=3)
        self.assertEqual(sub_res[1].quality, "bad")
Beispiel #3
0
    def test_t1_end2end(self):
        """
        Test T1 experiment using a simulator.
        """
        t1 = 25e-6
        backend = T1Backend(
            [t1],
            initial_prob1=[0.02],
            readout0to1=[0.02],
            readout1to0=[0.02],
        )

        delays = np.arange(1e-6, 40e-6, 3e-6)

        exp = T1(0, delays)
        exp.analysis.set_options(p0={"amp": 1, "tau": t1, "base": 0})
        exp_data = exp.run(backend, shots=10000)
        self.assertExperimentDone(exp_data)
        res = exp_data.analysis_results("T1")
        self.assertRoundTripSerializable(res.value,
                                         check_func=self.ufloat_equiv)
        self.assertEqual(res.quality, "good")
        self.assertAlmostEqual(res.value.n, t1, delta=3)
        self.assertEqual(res.extra["unit"], "s")

        exp_data.service = FakeService()
        exp_data.save()
        loaded_data = ExperimentData.load(exp_data.experiment_id,
                                          exp_data.service)
        exp_res = exp_data.analysis_results()
        load_res = loaded_data.analysis_results()
        repr1 = sorted([repr(res) for res in exp_res])
        repr2 = sorted([repr(res) for res in load_res])
        self.assertEqual(repr1, repr2)
Beispiel #4
0
    def test_t1_end2end(self):
        """
        Test T1 experiment using a simulator.
        """
        t1 = 25e-6
        backend = T1Backend(
            [t1],
            initial_prob1=[0.02],
            readout0to1=[0.02],
            readout1to0=[0.02],
        )

        delays = np.arange(1e-6, 40e-6, 3e-6)

        exp = T1(0, delays)
        exp.analysis.set_options(p0={"amp": 1, "tau": t1, "base": 0})
        exp_data = exp.run(backend, shots=10000)
        res = exp_data.analysis_results("T1")
        fitval = res.value
        self.assertEqual(res.quality, "good")
        self.assertAlmostEqual(fitval.value, t1, delta=3)
        self.assertEqual(fitval.unit, "s")

        exp_data.service = FakeService()
        exp_data.save()
        loaded_data = ExperimentData.load(exp_data.experiment_id,
                                          exp_data.service)
        self.assertEqual(repr(exp_data.analysis_results("T1")),
                         repr(loaded_data.analysis_results("T1")))
Beispiel #5
0
    def test_t1_parallel_different_analysis_options(self):
        """
        Test parallel experiments of T1 using a simulator, for the case where
        the sub-experiments have different analysis options
        """

        t1 = 25
        delays = list(range(1, 40, 3))

        exp0 = T1(0, delays)
        exp0.set_analysis_options(t1_guess=30)
        exp1 = T1(1, delays)
        exp1.set_analysis_options(t1_guess=1000000)

        par_exp = ParallelExperiment([exp0, exp1])
        res = par_exp.run(T1Backend([t1, t1]))
        res.block_for_results()

        sub_res = []
        for i in range(2):
            sub_res.append(
                res.component_experiment_data(i).analysis_results(0))

        self.assertEqual(sub_res[0].quality, "good")
        self.assertAlmostEqual(sub_res[0].value.value, t1, delta=3)
        self.assertEqual(sub_res[1].quality, "bad")
Beispiel #6
0
    def test_t1_end2end(self):
        """
        Test T1 experiment using a simulator.
        """

        dt_factor = 2e-7

        t1 = 25e-6
        backend = T1Backend(
            [t1 / dt_factor],
            initial_prob1=[0.02],
            readout0to1=[0.02],
            readout1to0=[0.02],
            dt_factor=dt_factor,
        )

        delays = list(
            range(
                int(1e-6 / dt_factor),
                int(40e-6 / dt_factor),
                int(3e-6 / dt_factor),
            ))

        exp = T1(0, delays, unit="dt")
        exp.set_analysis_options(amplitude_guess=1,
                                 t1_guess=t1 / dt_factor,
                                 offset_guess=0)
        exp_data = exp.run(backend, shots=10000)
        exp_data.block_for_results()  # Wait for analysis to finish.
        res = exp_data.analysis_results(0)
        fitval = res.value
        self.assertEqual(res.quality, "good")
        self.assertAlmostEqual(fitval.value, t1, delta=3)
        self.assertEqual(fitval.unit, "s")
    def __init__(
        self,
        t1=None,
        t2ramsey=None,
        freq=None,
        initial_prob1=None,
        readout0to1=None,
        readout1to0=None,
    ):
        """
        Initialize the Tphi backend
        """
        self._configuration = QasmBackendConfiguration(
            backend_name="tphi_simulator",
            backend_version="0",
            n_qubits=int(1e6),
            basis_gates=["barrier", "h", "p", "delay", "measure", "x"],
            gates=[],
            local=True,
            simulator=True,
            conditional=False,
            open_pulse=False,
            memory=False,
            max_shots=int(1e6),
            coupling_map=None,
        )
        self._t1 = [t1]
        self._t2ramsey = t2ramsey
        self._freq = freq
        self._initial_prob1 = initial_prob1
        self._readout0to1 = readout0to1
        self._readout1to0 = readout1to0
        self._internal_backends = {}
        super().__init__(self._configuration)

        self._internal_backends["T1"] = T1Backend(self._t1,
                                                  self._initial_prob1,
                                                  self._readout0to1,
                                                  self._readout1to0)
        if self._initial_prob1 is None:
            self._initial_prob_plus = None
        else:
            self._initial_prob_plus = 0.5  # temporary
        self._p0 = {
            "A": [0.5],
            "T2star": [t2ramsey],
            "f": [freq],
            "phi": [0.0],
            "B": [0.5],
        }
        self._internal_backends["T2*"] = T2RamseyBackend(
            self._p0, self._initial_prob_plus, self._readout0to1,
            self._readout1to0)
Beispiel #8
0
    def test_t1_parallel(self):
        """
        Test parallel experiments of T1 using a simulator.
        """

        t1 = [25, 15]
        delays = list(range(1, 40, 3))

        exp0 = T1(0, delays)
        exp2 = T1(2, delays)
        par_exp = ParallelExperiment([exp0, exp2])
        res = par_exp.run(T1Backend([t1[0], None, t1[1]]))
        res.block_for_results()

        for i in range(2):
            sub_res = res.component_experiment_data(i).analysis_results(0)
            self.assertEqual(sub_res.quality, "good")
            self.assertAlmostEqual(sub_res.value.value, t1[i], delta=3)