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

Fix for Service Serialization #796

Merged
merged 12 commits into from
May 18, 2022
12 changes: 11 additions & 1 deletion qiskit_experiments/database_service/db_experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,6 @@ def __json_encode__(self):
for att in [
"_metadata",
"_source",
"_service",
ItamarGoldman marked this conversation as resolved.
Show resolved Hide resolved
"_backend",
"_id",
"_parent_id",
Expand All @@ -1860,6 +1859,17 @@ def __json_encode__(self):

# Handle non-serializable objects
json_value["_jobs"] = self._safe_serialize_jobs()
service_value = getattr(self, "_service")
if service_value:
ItamarGoldman marked this conversation as resolved.
Show resolved Hide resolved
# the attribute self._service in charge of the connection and communication with the
# experiment db. It doesn't have meaning in the json format so there is no need to serialize
# it.
LOG.warning(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining this warning raised in __json_decode__ instead of __json_encode__. I think either is ok, but if it's going to be in encode the message should be changed to be something like related to serialization like:

"Experiment service %s cannot be JSON serialized."

I also think raising a warning every time might be more annoying than useful so we could either just remove this warning entirely or change it to LOG.info or LOG.debug instead of LOG.warning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound good. I will change it accordingly.
Regarding the location of the warning, I thought that the message will appear in the encode so that the user would not find out (by surprise) that the service was not serialized.

Should we raise it in __json_decode__ or is it better to raise it in both places?

"Experiment was saved using %s service which cannot be automatically loaded. "
"Please reset service attribute if required",
str(type(service_value)),
)
json_value["_service"] = None
ItamarGoldman marked this conversation as resolved.
Show resolved Hide resolved

return json_value

Expand Down