From 165464a62726c3003020b9ca898f1a459d9b8090 Mon Sep 17 00:00:00 2001 From: ItamarGoldman Date: Mon, 16 Oct 2023 14:59:15 +0300 Subject: [PATCH 1/5] Added to the string ".svg" if it didn't have it --- qiskit_experiments/framework/experiment_data.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qiskit_experiments/framework/experiment_data.py b/qiskit_experiments/framework/experiment_data.py index 20fab44cc8..2044bb3aa8 100644 --- a/qiskit_experiments/framework/experiment_data.py +++ b/qiskit_experiments/framework/experiment_data.py @@ -1311,6 +1311,12 @@ def figure( raise ExperimentEntryNotFound(f"Figure {figure_key} not found.") figure_key = self._figures.keys()[figure_key] + # All figures must have '.svg' in their names when added, as the extension is added to the key + # name in the `add_figures()` method of this class. + if isinstance(figure_key, str): + if ".svg" not in figure_key: + figure_key += ".svg" + figure_data = self._figures.get(figure_key, None) if figure_data is None and self.service: figure = self.service.figure(experiment_id=self.experiment_id, figure_name=figure_key) From c40320b6ef7405a6025f00df8e62b05bd03229c8 Mon Sep 17 00:00:00 2001 From: ItamarGoldman Date: Mon, 23 Oct 2023 10:10:39 +0300 Subject: [PATCH 2/5] used the same function as in add figure for extension check --- qiskit_experiments/framework/experiment_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit_experiments/framework/experiment_data.py b/qiskit_experiments/framework/experiment_data.py index 2044bb3aa8..3428875086 100644 --- a/qiskit_experiments/framework/experiment_data.py +++ b/qiskit_experiments/framework/experiment_data.py @@ -1314,7 +1314,7 @@ def figure( # All figures must have '.svg' in their names when added, as the extension is added to the key # name in the `add_figures()` method of this class. if isinstance(figure_key, str): - if ".svg" not in figure_key: + if not figure_key.endswith(".svg"): figure_key += ".svg" figure_data = self._figures.get(figure_key, None) From 0e32e917ca4b105c7b9878cda7ce647f44c992e6 Mon Sep 17 00:00:00 2001 From: ItamarGoldman Date: Mon, 23 Oct 2023 10:11:30 +0300 Subject: [PATCH 3/5] added tests for figure fetching without extension --- test/database_service/test_db_experiment_data.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/database_service/test_db_experiment_data.py b/test/database_service/test_db_experiment_data.py index 3cbfa52928..3d83fa8512 100644 --- a/test/database_service/test_db_experiment_data.py +++ b/test/database_service/test_db_experiment_data.py @@ -409,6 +409,8 @@ def test_get_figure(self): exp_data = ExperimentData(experiment_type="qiskit_test") figure_template = "hello world {}" name_template = "figure_{}.svg" + name_template_wo_ext = "figure_{}" + for idx in range(3): exp_data.add_figures( str.encode(figure_template.format(idx)), figure_names=name_template.format(idx) @@ -418,6 +420,11 @@ def test_get_figure(self): self.assertEqual(expected_figure, exp_data.figure(name_template.format(idx)).figure) self.assertEqual(expected_figure, exp_data.figure(idx).figure) + # Check that figure will be returned without file extension in name + expected_figure = str.encode(figure_template.format(idx)) + self.assertEqual(expected_figure, exp_data.figure(name_template_wo_ext.format(idx)).figure) + self.assertEqual(expected_figure, exp_data.figure(idx).figure) + file_name = uuid.uuid4().hex self.addCleanup(os.remove, file_name) exp_data.figure(idx, file_name) From f96a30b2e6688c4026d094865d968b20644c9d47 Mon Sep 17 00:00:00 2001 From: ItamarGoldman Date: Mon, 23 Oct 2023 10:29:43 +0300 Subject: [PATCH 4/5] added releasenotes --- .../access_figure_without_extension-5b7438c19e223d6b.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml diff --git a/releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml b/releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml new file mode 100644 index 0000000000..85ed98ac70 --- /dev/null +++ b/releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml @@ -0,0 +1,4 @@ +--- +upgrade: + - | + Figures in `ExperimentData` objects can now be access without '.svg' extension. \ No newline at end of file From e7fe5404dbab7738e6657b995f90121e45e7677c Mon Sep 17 00:00:00 2001 From: ItamarGoldman <51112651+ItamarGoldman@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:08:03 +0300 Subject: [PATCH 5/5] Update releasenotes Co-authored-by: Yael Ben-Haim --- .../notes/access_figure_without_extension-5b7438c19e223d6b.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml b/releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml index 85ed98ac70..bb7d34a29d 100644 --- a/releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml +++ b/releasenotes/notes/access_figure_without_extension-5b7438c19e223d6b.yaml @@ -1,4 +1,4 @@ --- upgrade: - | - Figures in `ExperimentData` objects can now be access without '.svg' extension. \ No newline at end of file + Figures in `ExperimentData` objects can now be accessed without '.svg' extension. \ No newline at end of file