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

Add .zip format for artifact upload #93

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion qiskit_ibm_experiment/client/experiment_rest_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,7 @@ def file_download(
if result.status_code == 200:
if file_name.endswith(".yaml"):
return yaml.safe_load(result.content)
return result.json(cls=json_decoder)
elif file_name.endswith(".json"):
return result.json(cls=json_decoder)
return result.content
return result
11 changes: 9 additions & 2 deletions qiskit_ibm_experiment/client/local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# pylint treats the dataframes as JsonReader for some reason
# pylint: disable=no-member

import io
import logging
import os
import uuid
Expand Down Expand Up @@ -767,9 +768,13 @@ def experiment_file_upload(
self._files_list[experiment_id] = []
if experiment_id not in self._files:
self._files[experiment_id] = {}
if isinstance(file_data, io.BytesIO):
size = len(file_data.getvalue())
else:
size = len(file_data)
new_file_element = {
"Key": file_name,
"Size": len(file_data),
"Size": size,
"LastModified": str(datetime.now()),
}
self._files_list[experiment_id].append(new_file_element)
Expand Down Expand Up @@ -798,4 +803,6 @@ def experiment_file_download(
raise IBMExperimentEntryNotFound
if file_name.endswith(".yaml"):
return yaml.safe_load(self._files[experiment_id][file_name])
return json.loads(self._files[experiment_id][file_name], cls=json_decoder)
elif file_name.endswith(".json"):
return json.loads(self._files[experiment_id][file_name], cls=json_decoder)
return self._files[experiment_id][file_name].read()
23 changes: 16 additions & 7 deletions qiskit_ibm_experiment/service/ibm_experiment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,19 +1692,24 @@ def file_upload(
json_encoder: Custom encoder to use to encode the experiment.

Additional info:
The filename is expected to end with ".json" (otherwise it will be added)
The filename is expected to end with ".json", ".yaml", or ".zip", otherwise
".json" will be added,
and the data itself should be either a dictionary or a JSON serialization
with the default encoder.
"""
# currently the resultdb enforces files to end with .json or .yaml
# currently resultdb enforces files to end with .json, .yaml, or .zip
# without suffix, we assume json formatting
if not (file_name.endswith(".json") or file_name.endswith(".yaml")):
if not (
file_name.endswith(".json")
or file_name.endswith(".yaml")
or file_name.endswith(".zip")
):
file_name += ".json"
if isinstance(file_data, dict):
# for now we avoid using custom encoder with yaml files
if file_name.endswith(".yaml"):
file_data = yaml.dump(file_data)
else:
elif file_name.endswith(".json"):
file_data = json.dumps(file_data, cls=json_encoder)
self._api_client.experiment_file_upload(experiment_id, file_name, file_data)

Expand All @@ -1722,10 +1727,14 @@ def file_download(
Returns:
The JSON deserialization of the data file
Additional info:
The filename is expected to end with ".json", otherwise
it will be added.
The filename is expected to end with ".json", ".yaml", or ".zip", otherwise
".json" will be added.
"""
if not (file_name.endswith(".json") or file_name.endswith(".yaml")):
if not (
file_name.endswith(".json")
or file_name.endswith(".yaml")
or file_name.endswith(".zip")
):
file_name += ".json"
# for now we avoid using custom decoder with yaml files
file_data = self._api_client.experiment_file_download(
Expand Down
Loading