def test_frequency(self):
        """Test calibrations update from spectroscopy."""

        qubit = 1
        peak_offset = 5.0e6
        backend = SpectroscopyBackend(line_width=2e6, freq_offset=peak_offset)
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies)
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        exp_data = spec.run(backend)
        self.assertExperimentDone(exp_data)
        result = exp_data.analysis_results(1)
        value = result.value.n

        self.assertTrue(
            freq01 + peak_offset - 2e6 < value < freq01 + peak_offset + 2e6)
        self.assertEqual(result.quality, "good")

        # Test the integration with the Calibrations
        cals = Calibrations.from_backend(FakeAthens())
        self.assertNotEqual(
            cals.get_parameter_value(cals.__drive_freq_parameter__, qubit),
            value)
        Frequency.update(cals, exp_data)
        self.assertEqual(
            cals.get_parameter_value(cals.__drive_freq_parameter__, qubit),
            value)
Пример #2
0
    def test_kerneled_expdata_serialization(self):
        """Test experiment data and analysis data JSON serialization"""
        exp_helper = SpectroscopyHelper(line_width=2e6)
        backend = MockIQBackend(
            experiment_helper=exp_helper,
            iq_cluster_centers=[((-1.0, -1.0), (1.0, 1.0))],
            iq_cluster_width=[0.2],
        )
        backend._configuration.basis_gates = ["x"]
        backend._configuration.timing_constraints = {"granularity": 16}

        qubit = 1
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)
        exp = QubitSpectroscopy(qubit, frequencies)

        exp.set_run_options(meas_level=MeasLevel.KERNELED, shots=1024)
        expdata = exp.run(backend).block_for_results()
        self.assertExperimentDone(expdata)

        # Checking serialization of the experiment data
        self.assertRoundTripSerializable(expdata, self.experiment_data_equiv)

        # Checking serialization of the analysis
        self.assertRoundTripSerializable(expdata.analysis_results(1), self.analysis_result_equiv)
Пример #3
0
    def test_frequency(self):
        """Test calibrations update from spectroscopy."""

        qubit = 1
        peak_offset = 5.0e6
        backend = SpectroscopyBackend(line_width=2e6, freq_offset=peak_offset)
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21) / 1e6

        spec = QubitSpectroscopy(qubit, frequencies, unit="MHz")
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        exp_data = spec.run(backend)
        exp_data.block_for_results()
        result = exp_data.analysis_results(1)
        value = result.value.value

        self.assertTrue(
            freq01 + peak_offset - 2e6 < value < freq01 + peak_offset + 2e6)
        self.assertEqual(result.quality, "good")

        # Test the integration with the BackendCalibrations
        cals = BackendCalibrations(FakeAthens())
        self.assertNotEqual(cals.get_qubit_frequencies()[qubit], value)
        Frequency.update(cals, exp_data)
        self.assertEqual(cals.get_qubit_frequencies()[qubit], value)
Пример #4
0
    def test_spectroscopy_end2end_classified(self):
        """End to end test of the spectroscopy experiment."""

        backend = SpectroscopyBackend(line_width=2e6)
        qubit = 1
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies)
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(4.999e9 < result.value.n < 5.001e9)
        self.assertEqual(result.quality, "good")
        self.assertEqual(str(result.device_components[0]), f"Q{qubit}")

        # Test if we find still find the peak when it is shifted by 5 MHz.
        backend = SpectroscopyBackend(line_width=2e6, freq_offset=5.0e6)

        spec = QubitSpectroscopy(qubit, frequencies)
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(5.0049e9 < result.value.n < 5.0051e9)
        self.assertEqual(result.quality, "good")
Пример #5
0
    def test_spectroscopy_end2end_classified(self):
        """End to end test of the spectroscopy experiment."""

        backend = SpectroscopyBackend(line_width=2e6)
        qubit = 1
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies, unit="Hz")
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        expdata = spec.run(backend)
        expdata.block_for_results()
        result = expdata.analysis_results(1)
        value = result.value.value

        self.assertTrue(4.999e9 < value < 5.001e9)
        self.assertEqual(result.quality, "good")

        # Test if we find still find the peak when it is shifted by 5 MHz.
        backend = SpectroscopyBackend(line_width=2e6, freq_offset=5.0e6)

        spec = QubitSpectroscopy(qubit, frequencies, unit="Hz")
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        expdata = spec.run(backend)
        expdata.block_for_results()
        result = expdata.analysis_results(1)
        value = result.value.value

        self.assertTrue(5.0049e9 < value < 5.0051e9)
        self.assertEqual(result.quality, "good")
    def test_spectroscopy_end2end_kerneled(self):
        """End to end test of the spectroscopy experiment on IQ data."""

        backend = SpectroscopyBackend(line_width=2e6)
        qubit = 0
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies)
        expdata = spec.run(backend)
        result = expdata.analysis_results(1)
        value = result.value.value

        self.assertTrue(freq01 - 2e6 < value < freq01 + 2e6)
        self.assertEqual(result.quality, "good")

        # Test if we find still find the peak when it is shifted by 5 MHz.
        backend = SpectroscopyBackend(line_width=2e6, freq_offset=5.0e6)

        spec = QubitSpectroscopy(qubit, frequencies)
        expdata = spec.run(backend)
        result = expdata.analysis_results(1)
        value = result.value.value

        self.assertTrue(freq01 + 3e6 < value < freq01 + 8e6)
        self.assertEqual(result.quality, "good")

        spec.set_run_options(meas_return="avg")
        expdata = spec.run(backend)
        result = expdata.analysis_results(1)
        value = result.value.value

        self.assertTrue(freq01 + 3e6 < value < freq01 + 8e6)
        self.assertEqual(result.quality, "good")
    def test_spectroscopy_end2end_kerneled(self):
        """End to end test of the spectroscopy experiment on IQ data."""

        exp_helper = SpectroscopyHelper(line_width=2e6)
        backend = MockIQBackend(
            experiment_helper=exp_helper,
            iq_cluster_centers=[((-1.0, -1.0), (1.0, 1.0))],
            iq_cluster_width=[0.2],
        )
        backend._configuration.basis_gates = ["x"]
        backend._configuration.timing_constraints = {"granularity": 16}

        qubit = 0
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(freq01 - 2e6 < result.value.n < freq01 + 2e6)
        self.assertEqual(result.quality, "good")

        exp_helper.freq_offset = 5.0e6
        backend._iq_cluster_centers = [((1.0, 1.0), (-1.0, -1.0))]

        spec = QubitSpectroscopy(qubit, frequencies)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(freq01 + 3e6 < result.value.n < freq01 + 8e6)
        self.assertEqual(result.quality, "good")

        spec.set_run_options(meas_return="avg")
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(freq01 + 3e6 < result.value.n < freq01 + 8e6)
        self.assertEqual(result.quality, "good")
    def test_spectroscopy_end2end_classified(self):
        """End to end test of the spectroscopy experiment."""

        exp_helper = SpectroscopyHelper(line_width=2e6)
        backend = MockIQBackend(
            experiment_helper=exp_helper,
            iq_cluster_centers=[((-1.0, -1.0), (1.0, 1.0))],
            iq_cluster_width=[0.2],
        )
        backend._configuration.basis_gates = ["x"]
        backend._configuration.timing_constraints = {"granularity": 16}

        qubit = 1
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies)
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(4.999e9 < result.value.n < 5.001e9)
        self.assertEqual(result.quality, "good")
        self.assertEqual(str(result.device_components[0]), f"Q{qubit}")

        # Test if we find still find the peak when it is shifted by 5 MHz.
        exp_helper.freq_offset = 5.0e6
        spec = QubitSpectroscopy(qubit, frequencies)
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(5.0049e9 < result.value.n < 5.0051e9)
        self.assertEqual(result.quality, "good")
Пример #9
0
    def test_spectroscopy_end2end_kerneled(self):
        """End to end test of the spectroscopy experiment on IQ data."""

        backend = SpectroscopyBackend(line_width=2e6,
                                      iq_cluster_centers=(-1, -1, 1, 1))
        qubit = 0
        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(freq01 - 2e6 < result.value.n < freq01 + 2e6)
        self.assertEqual(result.quality, "good")

        # Test if we find still find the peak when it is shifted by 5 MHz.
        backend = SpectroscopyBackend(line_width=2e6,
                                      freq_offset=5.0e6,
                                      iq_cluster_centers=(-1, -1, 1, 1))

        spec = QubitSpectroscopy(qubit, frequencies)
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(freq01 + 3e6 < result.value.n < freq01 + 8e6)
        self.assertEqual(result.quality, "good")

        spec.set_run_options(meas_return="avg")
        expdata = spec.run(backend)
        self.assertExperimentDone(expdata)
        result = expdata.analysis_results(1)
        self.assertRoundTripSerializable(result.value,
                                         check_func=self.ufloat_equiv)

        self.assertTrue(freq01 + 3e6 < result.value.n < freq01 + 8e6)
        self.assertEqual(result.quality, "good")
    def test_frequency(self):
        """Test calibrations update from spectroscopy."""

        qubit = 1
        peak_offset = 5.0e6
        backend = MockIQBackend(
            experiment_helper=SpectroscopyHelper(freq_offset=peak_offset),
            iq_cluster_centers=[((-1.0, -1.0), (1.0, 1.0))],
            iq_cluster_width=[0.2],
        )
        backend._configuration.basis_gates = ["x"]
        backend._configuration.timing_constraints = {"granularity": 16}

        freq01 = backend.defaults().qubit_freq_est[qubit]
        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        spec = QubitSpectroscopy(qubit, frequencies)
        spec.set_run_options(meas_level=MeasLevel.CLASSIFIED)
        exp_data = spec.run(backend)
        self.assertExperimentDone(exp_data)
        result = exp_data.analysis_results(1)
        value = result.value.n

        self.assertTrue(
            freq01 + peak_offset - 2e6 < value < freq01 + peak_offset + 2e6)
        self.assertEqual(result.quality, "good")

        # Test the integration with the Calibrations
        cals = Calibrations.from_backend(FakeAthens())
        self.assertNotEqual(
            cals.get_parameter_value(cals.__drive_freq_parameter__, qubit),
            value)
        Frequency.update(cals, exp_data)
        self.assertEqual(
            cals.get_parameter_value(cals.__drive_freq_parameter__, qubit),
            value)
Пример #11
0
 def test_roundtrip_serializable(self):
     """Test round trip JSON serialization"""
     exp = QubitSpectroscopy(1, np.linspace(int(100e6), int(150e6), int(20e6)))
     # Checking serialization of the experiment
     self.assertRoundTripSerializable(exp, self.json_equiv)
Пример #12
0
 def test_experiment_config(self):
     """Test converting to and from config works"""
     exp = QubitSpectroscopy(1, np.linspace(100, 150, 20) * 1e6)
     loaded_exp = QubitSpectroscopy.from_config(exp.config())
     self.assertNotEqual(exp, loaded_exp)
     self.assertTrue(self.json_equiv(exp, loaded_exp))