def test_to_real(self): """Test scaling and conversion to real part.""" processor = DataProcessor("memory", [ToReal(scale=1e-3)]) exp_data = ExperimentData(FakeExperiment()) exp_data.add_data(self.result_lvl1) new_data = processor(exp_data.data[0]) expected_old = { "memory": [ [[1103260.0, -11378508.0], [2959012.0, -16488753.0]], [[442170.0, -19283206.0], [-5279410.0, -15339630.0]], [[3016514.0, -14548009.0], [-3404756.0, -16743348.0]], ], "metadata": { "experiment_type": "fake_test_experiment", "x_values": 0.0 }, } expected_new = np.array([[1103.26, 2959.012], [442.17, -5279.41], [3016.514, -3404.7560]]) self.assertEqual(exp_data.data[0], expected_old) self.assertTrue(np.allclose(new_data, expected_new)) # Test that we can call with history. new_data, history = processor.call_with_history(exp_data.data[0]) self.assertEqual(exp_data.data[0], expected_old) self.assertTrue(np.allclose(new_data, expected_new)) self.assertEqual(history[0][0], "ToReal") self.assertTrue(np.allclose(history[0][1], expected_new))
def test_averaging_and_svd(self): """Test averaging followed by a SVD.""" processor = DataProcessor("memory", [AverageData(axis=1), SVD()]) # Test training using the calibration points self.assertFalse(processor.is_trained) processor.train([self.data.data(idx) for idx in [0, 1]]) self.assertTrue(processor.is_trained) # Test the excited state processed, error = processor(self.data.data(0)) self.assertTrue(np.allclose(processed, self._sig_es)) # Test the ground state processed, error = processor(self.data.data(1)) self.assertTrue(np.allclose(processed, self._sig_gs)) # Test the x90p rotation processed, error = processor(self.data.data(2)) self.assertTrue(np.allclose(processed, self._sig_x90)) self.assertTrue(np.allclose(error, np.array([0.25, 0.25]))) # Test the x45p rotation processed, error = processor(self.data.data(3)) expected_std = np.array([np.std([1, 1, 1, -1]) / np.sqrt(4.0) / 2] * 2) self.assertTrue(np.allclose(processed, self._sig_x45)) self.assertTrue(np.allclose(error, expected_std))
def test_process_all_data(self): """Test that we can process all data at once.""" processor = DataProcessor("memory", [AverageData(axis=1), SVD()]) # Test training using the calibration points self.assertFalse(processor.is_trained) processor.train([self.data.data(idx) for idx in [0, 1]]) self.assertTrue(processor.is_trained) all_expected = np.vstack(( self._sig_es.reshape(1, 2), self._sig_gs.reshape(1, 2), self._sig_x90.reshape(1, 2), self._sig_x45.reshape(1, 2), )) # Test processing of all data processed = processor(self.data.data()) np.testing.assert_array_almost_equal( unp.nominal_values(processed), all_expected, ) # Test processing of each datum individually for idx, expected in enumerate( [self._sig_es, self._sig_gs, self._sig_x90, self._sig_x45]): processed = processor(self.data.data(idx)) np.testing.assert_array_almost_equal( unp.nominal_values(processed), expected, )
def test_to_real(self): """Test scaling and conversion to real part.""" processor = DataProcessor("memory", [ToReal(scale=1e-3)]) exp_data = ExperimentData(FakeExperiment()) exp_data.add_data(self.result_lvl1) # Test to real on a single datum new_data = processor(exp_data.data(0)) expected_old = { "memory": [ [[1103260.0, -11378508.0], [2959012.0, -16488753.0]], [[442170.0, -19283206.0], [-5279410.0, -15339630.0]], [[3016514.0, -14548009.0], [-3404756.0, -16743348.0]], ], "metadata": {"experiment_type": "fake_test_experiment"}, "job_id": "job-123", "meas_level": 1, "shots": 3, } expected_new = np.array([[1103.26, 2959.012], [442.17, -5279.41], [3016.514, -3404.7560]]) self.assertEqual(exp_data.data(0), expected_old) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), expected_new, ) self.assertTrue(np.isnan(unp.std_devs(new_data)).all()) # Test that we can call with history. new_data, history = processor.call_with_history(exp_data.data(0)) self.assertEqual(exp_data.data(0), expected_old) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), expected_new, ) self.assertEqual(history[0][0], "ToReal") np.testing.assert_array_almost_equal( unp.nominal_values(history[0][1]), expected_new, ) # Test to real on more than one datum new_data = processor(exp_data.data()) expected_new = np.array( [ [[1103.26, 2959.012], [442.17, -5279.41], [3016.514, -3404.7560]], [[5131.962, 4438.87], [3415.985, 2942.458], [5199.964, 4030.843]], ] ) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), expected_new, )
def test_to_imag(self): """Test that we can average the data.""" processor = DataProcessor("memory") processor.append(ToImag(scale=1e-3)) exp_data = ExperimentData(FakeExperiment()) exp_data.add_data(self.result_lvl1) new_data, error = processor(exp_data.data(0)) expected_old = { "memory": [ [[1103260.0, -11378508.0], [2959012.0, -16488753.0]], [[442170.0, -19283206.0], [-5279410.0, -15339630.0]], [[3016514.0, -14548009.0], [-3404756.0, -16743348.0]], ], "metadata": { "experiment_type": "fake_test_experiment" }, "job_id": "job-123", "meas_level": 1, "shots": 3, } expected_new = np.array([ [-11378.508, -16488.753], [-19283.206000000002, -15339.630000000001], [-14548.009, -16743.348], ]) self.assertEqual(exp_data.data(0), expected_old) self.assertTrue(np.allclose(new_data, expected_new)) self.assertIsNone(error) # Test that we can call with history. new_data, error, history = processor.call_with_history( exp_data.data(0)) self.assertEqual(exp_data.data(0), expected_old) self.assertTrue(np.allclose(new_data, expected_new)) self.assertEqual(history[0][0], "ToImag") self.assertTrue(np.allclose(history[0][1], expected_new)) # Test to imaginary on more than one datum new_data, error = processor(exp_data.data()) expected_new = np.array([ [[-11378.508, -16488.753], [-19283.206, -15339.630], [-14548.009, -16743.348]], [[-16630.257, -13752.518], [-16031.913, -15840.465], [-14955.998, -14538.923]], ]) self.assertTrue(np.allclose(new_data, expected_new))
def test_validation(self): """Test the validation mechanism.""" for validate, error in [(False, AttributeError), (True, DataProcessorError)]: processor = DataProcessor("counts") processor.append(Probability("00", validate=validate)) with self.assertRaises(error): processor({"counts": [0, 1, 2]})
def test_empty_processor(self): """Check that a DataProcessor without steps does nothing.""" data_processor = DataProcessor("counts") datum = data_processor(self.exp_data_lvl2.data(0)) self.assertEqual(datum, {"00": 4, "10": 6}) datum, history = data_processor.call_with_history(self.exp_data_lvl2.data(0)) self.assertEqual(datum, {"00": 4, "10": 6}) self.assertEqual(history, [])
def test_populations(self): """Test that counts are properly converted to a population.""" processor = DataProcessor("counts") processor.append(Probability("00")) new_data = processor(self.exp_data_lvl2.data[0]) self.assertEqual(new_data[0], 0.4) self.assertEqual(new_data[1], 0.4 * (1 - 0.4) / 10)
def test_avg_and_single(self): """Test that the different nodes process the data correctly.""" to_real = DataProcessor("memory", [ToReal(scale=1)]) to_imag = DataProcessor("memory", [ToImag(scale=1)]) # Test the real single shot node new_data = to_real(self.exp_data_single.data(0)) expected = np.array( [ [-56470872.0, -53407256.0], [-34623272.0, -36650644.0], [42658720.0, 29689970.0], [-47387248.0, -62149124.0], [-51465408.0, 23157112.0], [51426688.0, 34330920.0], ] ) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), expected, ) self.assertTrue(np.isnan(unp.std_devs(new_data)).all()) # Test the imaginary single shot node new_data = to_imag(self.exp_data_single.data(0)) expected = np.array( [ [-136691568.0, -176278624.0], [-151247824.0, -170559312.0], [-153054640.0, -174671824.0], [-177826640.0, -165909728.0], [-148338000.0, -165826736.0], [-142703104.0, -185572592.0], ] ) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), expected, ) # Test the real average node new_data = to_real(self.exp_data_avg.data(0)) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), np.array([-539698.0, 5541283.0]), ) # Test the imaginary average node new_data = to_imag(self.exp_data_avg.data(0)) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), np.array([-153030784.0, -160369600.0]), )
def test_normalize(self): """Test that by adding a normalization node we get a signal between 1 and 1.""" processor = DataProcessor("memory", [SVD(), MinMaxNormalize()]) self.assertFalse(processor.is_trained) processor.train([self.data.data(idx) for idx in [0, 1]]) self.assertTrue(processor.is_trained) all_expected = np.array([[0.0, 1.0, 0.5, 0.75], [1.0, 0.0, 0.5, 0.25]]) # Test processing of all data processed = processor(self.data.data())[0] self.assertTrue(np.allclose(processed, all_expected))
def test_populations(self): """Test that counts are properly converted to a population.""" processor = DataProcessor("counts") processor.append(Probability("00")) # Test on a single datum. new_data, error = processor(self.exp_data_lvl2.data(0)) self.assertEqual(new_data, 0.4) self.assertEqual(error, np.sqrt(0.4 * (1 - 0.4) / 10)) # Test on all the data new_data, error = processor(self.exp_data_lvl2.data()) self.assertTrue(np.allclose(new_data, np.array([0.4, 0.2])))
def test_normalize(self): """Test that by adding a normalization node we get a signal between 1 and 1.""" processor = DataProcessor("memory", [SVD(), MinMaxNormalize()]) self.assertFalse(processor.is_trained) processor.train([self.data.data(idx) for idx in [0, 1]]) self.assertTrue(processor.is_trained) # Test processing of all data processed = processor(self.data.data()) np.testing.assert_array_almost_equal( unp.nominal_values(processed), np.array([[0.0, 1.0], [1.0, 0.0], [0.5, 0.5], [0.75, 0.25]]), )
def test_averaging(self): """Test that averaging of the datums produces the expected IQ points.""" processor = DataProcessor("memory", [AverageData(axis=1)]) # Test that we get the expected outcome for the excited state processed = processor(self.data.data(0)) np.testing.assert_array_almost_equal( unp.nominal_values(processed), np.array([[1.0, 1.0], [-1.0, 1.0]]), ) np.testing.assert_array_almost_equal( unp.std_devs(processed), np.array([[0.15811388300841894, 0.1], [0.15811388300841894, 0.0]]) / 2.0, ) # Test that we get the expected outcome for the ground state processed = processor(self.data.data(1)) np.testing.assert_array_almost_equal( unp.nominal_values(processed), np.array([[-1.0, -1.0], [1.0, -1.0]]), ) np.testing.assert_array_almost_equal( unp.std_devs(processed), np.array([[0.15811388300841894, 0.1], [0.15811388300841894, 0.0]]) / 2.0, )
def test_distorted_iq_data(self): """Test if uncertainty can consider correlation. SVD projects IQ data onto I-axis, and input different data sets that have the same mean and same variance but squeezed along different axis. """ svd_node = SVD() svd_node._scales = [1.0] svd_node._main_axes = [np.array([1, 0])] svd_node._means = [(0.0, 0.0)] processor = DataProcessor("memory", [AverageData(axis=1), svd_node]) dist_i_axis = { "memory": [[[-1, 0]], [[-0.5, 0]], [[0.0, 0]], [[0.5, 0]], [[1, 0]]] } dist_q_axis = { "memory": [[[0, -1]], [[0, -0.5]], [[0, 0.0]], [[0, 0.5]], [[0, 1]]] } out_i = processor(dist_i_axis) self.assertAlmostEqual(out_i[0].nominal_value, 0.0) self.assertAlmostEqual(out_i[0].std_dev, 0.31622776601683794) out_q = processor(dist_q_axis) self.assertAlmostEqual(out_q[0].nominal_value, 0.0) self.assertAlmostEqual(out_q[0].std_dev, 0.0)
def test_data_prep_level1_memory_average(self): """Format meas_level=1 meas_return=avg.""" # slots = 3, circuits = 2 data_raw = [ { "memory": [[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]], }, { "memory": [[0.7, 0.8], [0.9, 1.0], [1.1, 1.2]], }, ] formatted_data = DataProcessor("memory", [])._data_extraction(data_raw) ref_data = np.array([ [ [ufloat(0.1, np.nan), ufloat(0.2, np.nan)], [ufloat(0.3, np.nan), ufloat(0.4, np.nan)], [ufloat(0.5, np.nan), ufloat(0.6, np.nan)], ], [ [ufloat(0.7, np.nan), ufloat(0.8, np.nan)], [ufloat(0.9, np.nan), ufloat(1.0, np.nan)], [ufloat(1.1, np.nan), ufloat(1.2, np.nan)], ], ]) self.assertTupleEqual(formatted_data.shape, ref_data.shape) np.testing.assert_array_equal(unp.nominal_values(formatted_data), unp.nominal_values(ref_data)) # note that np.nan cannot be evaluated by "==" self.assertTrue(np.isnan(unp.std_devs(formatted_data)).all())
def test_json_trained(self): """Check if trained data processor is serializable and still work.""" test_data = {"memory": [[1, 1]]} node = SVD() node.set_parameters( main_axes=np.array([[1, 0]]), scales=[1.0], i_means=[0.0], q_means=[0.0] ) processor = DataProcessor("memory", data_actions=[node]) self.assertRoundTripSerializable(processor, check_func=self.json_equiv) serialized = json.dumps(processor, cls=ExperimentEncoder) loaded_processor = json.loads(serialized, cls=ExperimentDecoder) ref_out = processor(data=test_data) loaded_out = loaded_processor(data=test_data) np.testing.assert_array_almost_equal( unp.nominal_values(ref_out), unp.nominal_values(loaded_out), ) np.testing.assert_array_almost_equal( unp.std_devs(ref_out), unp.std_devs(loaded_out), )
def _get_restless_processor(self, meas_level: int = MeasLevel.CLASSIFIED ) -> DataProcessor: """Returns the restless experiments data processor. Notes: Sub-classes can override this method if they need more complex data processing. """ outcome = self.analysis.options.get("outcome", "1" * self._num_qubits) meas_return = self.analysis.options.get("meas_return", MeasReturnType.SINGLE) normalize = self.analysis.options.get("normalization", True) dimensionality_reduction = self.analysis.options.get( "dimensionality_reduction", ProjectorType.SVD) if meas_level == MeasLevel.KERNELED: return get_kerneled_processor(dimensionality_reduction, meas_return, normalize, [nodes.RestlessToIQ()]) else: return DataProcessor( "memory", [ nodes.RestlessToCounts(self._num_qubits), nodes.Probability(outcome), ], )
def get_processor( meas_level: MeasLevel = MeasLevel.CLASSIFIED, meas_return: str = "avg", normalize: bool = True, ) -> DataProcessor: """Get a DataProcessor that produces a continuous signal given the options. Args: meas_level: The measurement level of the data to process. meas_return: The measurement return (single or avg) of the data to process. normalize: Add a data normalization node to the Kerneled data processor. Returns: An instance of DataProcessor capable of dealing with the given options. Raises: DataProcessorError: if the measurement level is not supported. """ if meas_level == MeasLevel.CLASSIFIED: return DataProcessor("counts", [Probability("1")]) if meas_level == MeasLevel.KERNELED: if meas_return == "single": processor = DataProcessor("memory", [AverageData(axis=1), SVD()]) else: processor = DataProcessor("memory", [SVD()]) if normalize: processor.append(MinMaxNormalize()) return processor raise DataProcessorError(f"Unsupported measurement level {meas_level}.")
def test_averaging_and_svd(self): """Test averaging followed by a SVD.""" processor = DataProcessor("memory", [AverageData(axis=1), SVD()]) # Test training using the calibration points self.assertFalse(processor.is_trained) processor.train([self.data.data(idx) for idx in [0, 1]]) self.assertTrue(processor.is_trained) # Test the excited state processed = processor(self.data.data(0)) np.testing.assert_array_almost_equal( unp.nominal_values(processed), self._sig_es, ) # Test the ground state processed = processor(self.data.data(1)) np.testing.assert_array_almost_equal( unp.nominal_values(processed), self._sig_gs, ) # Test the x90p rotation processed = processor(self.data.data(2)) np.testing.assert_array_almost_equal( unp.nominal_values(processed), self._sig_x90, ) np.testing.assert_array_almost_equal( unp.std_devs(processed), np.array([0.25, 0.25]), ) # Test the x45p rotation processed = processor(self.data.data(3)) np.testing.assert_array_almost_equal( unp.nominal_values(processed), self._sig_x45, ) np.testing.assert_array_almost_equal( unp.std_devs(processed), np.array([np.std([1, 1, 1, -1]) / np.sqrt(4.0) / 2] * 2), )
def test_populations(self): """Test that counts are properly converted to a population.""" processor = DataProcessor("counts") processor.append(Probability("00", alpha_prior=1.0)) # Test on a single datum. new_data = processor(self.exp_data_lvl2.data(0)) self.assertAlmostEqual(float(unp.nominal_values(new_data)), 0.41666667) self.assertAlmostEqual(float(unp.std_devs(new_data)), 0.13673544235706114) # Test on all the data new_data = processor(self.exp_data_lvl2.data()) np.testing.assert_array_almost_equal( unp.nominal_values(new_data), np.array([0.41666667, 0.25]), )
def test_train_svd_processor(self): """Test that we can train a DataProcessor with an SVD.""" processor = DataProcessor("memory", [SVD()]) self.assertFalse(processor.is_trained) iq_data = [[[0.0, 0.0], [0.0, 0.0]], [[1.0, 1.0], [-1.0, 1.0]], [[-1.0, -1.0], [1.0, -1.0]]] self.create_experiment(iq_data) processor.train(self.iq_experiment.data()) self.assertTrue(processor.is_trained) # Check that we can use the SVD iq_data = [[[2, 2], [2, -2]]] self.create_experiment(iq_data) processed, _ = processor(self.iq_experiment.data(0)) expected = np.array([-2, -2]) / np.sqrt(2) self.assertTrue(np.allclose(processed, expected))
def test_to_imag(self): """Test that we can average the data.""" processor = DataProcessor("memory") processor.append(ToImag(scale=1e-3)) exp_data = ExperimentData(FakeExperiment()) exp_data.add_data(self.result_lvl1) new_data = processor(exp_data.data[0]) expected_old = { "memory": [ [[1103260.0, -11378508.0], [2959012.0, -16488753.0]], [[442170.0, -19283206.0], [-5279410.0, -15339630.0]], [[3016514.0, -14548009.0], [-3404756.0, -16743348.0]], ], "metadata": { "experiment_type": "fake_test_experiment", "x_values": 0.0 }, } expected_new = np.array([ [-11378.508, -16488.753], [-19283.206000000002, -15339.630000000001], [-14548.009, -16743.348], ]) self.assertEqual(exp_data.data[0], expected_old) self.assertTrue(np.allclose(new_data, expected_new)) # Test that we can call with history. new_data, history = processor.call_with_history(exp_data.data[0]) self.assertEqual(exp_data.data[0], expected_old) self.assertTrue(np.allclose(new_data, expected_new)) self.assertEqual(history[0][0], "ToImag") self.assertTrue(np.allclose(history[0][1], expected_new))
def test_wrong_processor(self): """Test that we can override the data processing by giving a faulty data processor.""" backend = MockIQBackend(RabiHelper()) rabi = Rabi(self.qubit, self.sched) fail_key = "fail_key" rabi.analysis.set_options(data_processor=DataProcessor(fail_key, [])) # pylint: disable=no-member rabi.set_run_options(shots=2) data = rabi.run(backend) result = data.analysis_results() self.assertEqual(data.status(), ExperimentStatus.ERROR) self.assertEqual(len(result), 0)
def test_wrong_processor(self): """Test that we can override the data processing by giving a faulty data processor.""" backend = RabiBackend() rabi = Rabi(self.qubit, self.sched) fail_key = "fail_key" rabi.analysis.set_options(data_processor=DataProcessor(fail_key, [])) rabi.set_run_options(shots=2) data = rabi.run(backend) result = data.analysis_results() self.assertEqual(len(result), 0)
def get_kerneled_processor( dimensionality_reduction: Union[ProjectorType, str], meas_return: str, normalize: bool, pre_nodes: Optional[List[DataAction]] = None, ) -> DataProcessor: """Get a DataProcessor for `meas_level=1` data that returns a one-dimensional signal. Args: dimensionality_reduction: Type of the node that will reduce the two-dimensional data to one dimension. meas_return: Type of data returned by the backend, i.e., averaged data or single-shot data. normalize: If True then normalize the output data to the interval ``[0, 1]``. pre_nodes: any nodes to be applied first in the data processing chain such as restless nodes. Returns: An instance of DataProcessor capable of processing `meas_level=MeasLevel.KERNELED` data for the corresponding job. Raises: DataProcessorError: if the wrong dimensionality reduction for kerneled data is specified. """ try: if isinstance(dimensionality_reduction, ProjectorType): projector_name = dimensionality_reduction.name else: projector_name = dimensionality_reduction projector = ProjectorType[projector_name].value except KeyError as error: raise DataProcessorError( f"Invalid dimensionality reduction: {dimensionality_reduction}." ) from error node = pre_nodes or [] if meas_return == "single": node.append(nodes.AverageData(axis=1)) node.append(projector()) if normalize: node.append(nodes.MinMaxNormalize()) return DataProcessor("memory", node)
def test_bad_analysis(self): """Test the Rabi analysis.""" experiment_data = ExperimentData() thetas = np.linspace(0.0, np.pi / 4, 31) amplitudes = np.linspace(0.0, 0.95, 31) experiment_data.add_data( self.simulate_experiment_data(thetas, amplitudes, shots=200)) data_processor = DataProcessor("counts", [Probability(outcome="1")]) experiment_data = OscillationAnalysis().run( experiment_data, data_processor=data_processor, plot=False) result = experiment_data.analysis_results() self.assertEqual(result[0].quality, "bad")
def test_good_analysis(self): """Test the Rabi analysis.""" experiment_data = ExperimentData() thetas = np.linspace(-np.pi, np.pi, 31) amplitudes = np.linspace(-0.25, 0.25, 31) expected_rate, test_tol = 2.0, 0.2 experiment_data.add_data( self.simulate_experiment_data(thetas, amplitudes, shots=400)) data_processor = DataProcessor("counts", [Probability(outcome="1")]) experiment_data = OscillationAnalysis().run( experiment_data, data_processor=data_processor, plot=False) result = experiment_data.analysis_results(0) self.assertEqual(result.quality, "good") self.assertAlmostEqual(result.value[1], expected_rate, delta=test_tol)
def test_data_prep_level2_counts(self): """Format meas_level=2.""" # slots = 2, shots=10, circuits = 2 data_raw = [ { "counts": { "00": 2, "01": 3, "10": 1, "11": 4 }, }, { "counts": { "00": 3, "01": 3, "10": 2, "11": 2 }, }, ] formatted_data = DataProcessor("counts", [])._data_extraction(data_raw) ref_data = np.array( [ { "00": 2, "01": 3, "10": 1, "11": 4 }, { "00": 3, "01": 3, "10": 2, "11": 2 }, ], dtype=object, ) np.testing.assert_array_equal(formatted_data, ref_data)
def test_averaging(self): """Test that averaging of the datums produces the expected IQ points.""" processor = DataProcessor("memory", [AverageData(axis=1)]) # Test that we get the expected outcome for the excited state processed, error = processor(self.data.data(0)) expected_avg = np.array([[1.0, 1.0], [-1.0, 1.0]]) expected_std = np.array([[0.15811388300841894, 0.1], [0.15811388300841894, 0.0]]) / 2.0 self.assertTrue(np.allclose(processed, expected_avg)) self.assertTrue(np.allclose(error, expected_std)) # Test that we get the expected outcome for the ground state processed, error = processor(self.data.data(1)) expected_avg = np.array([[-1.0, -1.0], [1.0, -1.0]]) expected_std = np.array([[0.15811388300841894, 0.1], [0.15811388300841894, 0.0]]) / 2.0 self.assertTrue(np.allclose(processed, expected_avg)) self.assertTrue(np.allclose(error, expected_std))
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)