Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error when saving metadata without a service #1278

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,9 +1611,10 @@ def _save_experiment_metadata(self, suppress_errors: bool = True) -> None:
suppress_errors: should the method catch exceptions (true) or
pass them on, potentially aborting the experiment (false)
Raises:
QiskitError: If the save to the database failed
ExperimentDataSaveFailed: If the save to the database failed.

.. note::
This method does not save analysis results nor figures.
This method does not save analysis results or figures.
Use :meth:`save` for general saving of all experiment data.

See :meth:`qiskit.providers.experiment.IBMExperimentService.create_experiment`
Expand All @@ -1625,7 +1626,10 @@ def _save_experiment_metadata(self, suppress_errors: bool = True) -> None:
"An experiment service is available, for example, "
"when using an IBM Quantum backend."
)
return
if suppress_errors:
return
else:
raise ExperimentDataSaveFailed("No service found")
try:
handle_metadata_separately = self._metadata_too_large()
if handle_metadata_separately:
Expand Down Expand Up @@ -1656,7 +1660,9 @@ def _save_experiment_metadata(self, suppress_errors: bool = True) -> None:
# Don't automatically fail the experiment just because its data cannot be saved.
LOG.error("Unable to save the experiment data: %s", traceback.format_exc())
if not suppress_errors:
raise QiskitError(f"Experiment data save failed\nError Message:\n{str(ex)}") from ex
raise ExperimentDataSaveFailed(
f"Experiment data save failed\nError Message:\n{str(ex)}"
) from ex

def _metadata_too_large(self):
"""Determines whether the metadata should be stored in a separate file"""
Expand Down Expand Up @@ -1758,12 +1764,19 @@ def save(
if isinstance(figure, pyplot.Figure):
figure = plot_to_svg_bytes(figure)
figures_to_create.append((figure, name))
self.service.create_figures(
experiment_id=self.experiment_id,
figure_list=figures_to_create,
blocking=True,
max_workers=max_workers,
)
try:
self.service.create_figures(
experiment_id=self.experiment_id,
figure_list=figures_to_create,
blocking=True,
max_workers=max_workers,
)
except Exception as ex: # pylint: disable=broad-except
LOG.error("Unable to save figures: %s", traceback.format_exc())
if not suppress_errors:
raise ExperimentDataSaveFailed(
f"Figure save failed\nError Message:\n{str(ex)}"
) from ex

for name in self._deleted_figures.copy():
with service_exception_to_warning():
Expand Down