def test_display_format_inf(self): """Test conversion of inf for display value""" self.assertEqual(DbAnalysisResult._display_format(np.inf), "Infinity") self.assertEqual(DbAnalysisResult._display_format(-np.inf), "-Infinity") self.assertEqual(DbAnalysisResult._display_format(np.nan), "NaN") self.assertEqual(DbAnalysisResult._display_format(math.inf), "Infinity") self.assertEqual(DbAnalysisResult._display_format(-math.inf), "-Infinity") self.assertEqual(DbAnalysisResult._display_format(math.nan), "NaN") self.assertEqual( DbAnalysisResult._display_format( uncertainties.ufloat(math.nan, math.nan).nominal_value), "NaN", ) self.assertEqual( DbAnalysisResult._display_format( uncertainties.ufloat(math.nan, math.nan).std_dev), "NaN", ) self.assertEqual( DbAnalysisResult._display_format( uncertainties.ufloat(math.inf, -math.inf).nominal_value), "Infinity", ) self.assertEqual( DbAnalysisResult._display_format( uncertainties.ufloat(math.inf, -math.inf).std_dev), "-Infinity", )
def _format_analysis_result(self, data, experiment_id, experiment_components=None): """Format run analysis result to DbAnalysisResult""" device_components = [] if data.device_components: device_components = data.device_components elif experiment_components: device_components = experiment_components if isinstance(data, DbAnalysisResultV1): # Update device components and experiment id data.device_components = device_components data._experiment_id = experiment_id return data return DbAnalysisResultV1( name=data.name, value=data.value, device_components=device_components, experiment_id=experiment_id, chisq=data.chisq, quality=data.quality, extra=data.extra, )
def test_display_format_inf(self): """Test conversion of inf for display value""" self.assertEqual(DbAnalysisResult._display_format(np.inf), "Infinity") self.assertEqual(DbAnalysisResult._display_format(-np.inf), "-Infinity") self.assertEqual(DbAnalysisResult._display_format(np.nan), "NaN") self.assertEqual(DbAnalysisResult._display_format(math.inf), "Infinity") self.assertEqual(DbAnalysisResult._display_format(-math.inf), "-Infinity") self.assertEqual(DbAnalysisResult._display_format(math.nan), "NaN")
def test_add_analysis_results(self): """Test adding an analysis result.""" exp_data = self._create_experiment_data() result_data = {"complex": 2 + 3j, "numpy": np.zeros(2)} aresult = AnalysisResult(name='qiskit_test', value=result_data, device_components=self.device_components, experiment_id=exp_data.experiment_id, quality=ResultQuality.GOOD, verified=True, tags=["foo", "bar"], service=self.experiment) exp_data.add_analysis_results(aresult) exp_data.save() rresult = AnalysisResult.load(aresult.result_id, self.experiment) self.assertEqual(exp_data.experiment_id, rresult.experiment_id) self._verify_analysis_result(aresult, rresult)
def _format_analysis_result(self, data, experiment_id, experiment_components=None): """Format run analysis result to DbAnalysisResult""" device_components = [] if data.device_components: device_components = data.device_components elif experiment_components: device_components = experiment_components return DbAnalysisResultV1( name=data.name, value=data.value, device_components=device_components, experiment_id=experiment_id, chisq=data.chisq, quality=data.quality, extra=data.extra, )
def test_display_format_array(self): """Test conversion of db displays""" value = DbAnalysisResult._display_format(np.arange(5)) self.assertEqual(value, "(ndarray)")
def test_display_format_list(self): """Test conversion of db displays""" value = DbAnalysisResult._display_format(list(range(5))) self.assertEqual(value, "(list)")
def test_display_format_complex(self): """Test conversion of db displays""" value = DbAnalysisResult._display_format(1e-10j) self.assertIsInstance(value, str)