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)
def test_end_to_end(self, freq_shift): """Test the experiment from end to end.""" qubit = 1 backend = MockIQBackend( experiment_helper=ResonatorSpectroscopyHelper( gate_name="measure", freq_offset=freq_shift), iq_cluster_centers=[((0.0, 0.0), (-1.0, 0.0))], iq_cluster_width=[0.2], ) backend._configuration.timing_constraints = {"granularity": 16} res_freq = backend.defaults().meas_freq_est[qubit] frequencies = np.linspace(res_freq - 20e6, res_freq + 20e6, 51) spec = ResonatorSpectroscopy(qubit, backend=backend, frequencies=frequencies) expdata = spec.run(backend) self.assertExperimentDone(expdata) result = expdata.analysis_results(1) self.assertRoundTripSerializable(result.value, check_func=self.ufloat_equiv) self.assertAlmostEqual(result.value.n, res_freq + freq_shift, delta=0.1e6) self.assertEqual(str(result.device_components[0]), f"R{qubit}")
def test_spectroscopy12_end2end_classified(self): """End to end test of the spectroscopy experiment with an x pulse.""" backend = MockIQBackend( experiment_helper=SpectroscopyHelper(line_width=2e6), 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) # Note that the backend is not sophisticated enough to simulate an e-f # transition so we run the test with g-e. spec = EFSpectroscopy(qubit, frequencies) spec.backend = backend 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(freq01 - 2e6 < result.value.n < freq01 + 2e6) self.assertEqual(result.quality, "good") # Test the circuits circ = spec.circuits()[0] self.assertEqual(circ.data[0][0].name, "x") self.assertEqual(circ.data[1][0].name, "Spec")
def test_kerneled_expdata_serialization(self, freq_shift): """Test experiment data and analysis data JSON serialization""" qubit = 1 backend = MockIQBackend( experiment_helper=ResonatorSpectroscopyHelper( gate_name="measure", freq_offset=freq_shift), iq_cluster_centers=[((0.0, 0.0), (-1.0, 0.0))], iq_cluster_width=[0.2], ) backend._configuration.timing_constraints = {"granularity": 16} res_freq = backend.defaults().meas_freq_est[qubit] frequencies = np.linspace(res_freq - 20e6, res_freq + 20e6, 51) exp = ResonatorSpectroscopy(qubit, backend=backend, frequencies=frequencies) expdata = exp.run(backend).block_for_results() self.assertExperimentDone(expdata) # since under _experiment in kwargs there is an argument of the backend which isn't serializable. expdata._experiment = None # 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)
def test_update_calibrations(self): """Test that we can properly update an instance of Calibrations.""" freq01 = FakeArmonk().defaults().qubit_freq_est[0] backend = MockIQBackend( experiment_helper=SpectroscopyHelper(freq_offset=5e6, line_width=2e6), 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} backend.defaults().qubit_freq_est = [freq01, freq01] library = FixedFrequencyTransmon(basis_gates=["x", "sx"]) cals = Calibrations.from_backend(FakeArmonk(), libraries=[library]) prev_freq = cals.get_parameter_value(cals.__drive_freq_parameter__, (0,)) self.assertEqual(prev_freq, freq01) frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21) expdata = RoughFrequencyCal(0, cals, frequencies).run(backend) self.assertExperimentDone(expdata) # Check the updated frequency which should be shifted by 5MHz. post_freq = cals.get_parameter_value(cals.__drive_freq_parameter__, (0,)) self.assertTrue(abs(post_freq - freq01 - 5e6) < 1e6)
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")
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)