Skip to content

Commit dc5bbd7

Browse files
authored
Add .zip format for artifact upload (#93)
* add .zip format * lint and fixed bug * fix local service * fix local client load
1 parent 213089e commit dc5bbd7

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

qiskit_ibm_experiment/client/experiment_rest_adapter.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -458,5 +458,7 @@ def file_download(
458458
if result.status_code == 200:
459459
if file_name.endswith(".yaml"):
460460
return yaml.safe_load(result.content)
461-
return result.json(cls=json_decoder)
461+
elif file_name.endswith(".json"):
462+
return result.json(cls=json_decoder)
463+
return result.content
462464
return result

qiskit_ibm_experiment/client/local_client.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# pylint treats the dataframes as JsonReader for some reason
1616
# pylint: disable=no-member
1717

18+
import io
1819
import logging
1920
import os
2021
import uuid
@@ -767,9 +768,13 @@ def experiment_file_upload(
767768
self._files_list[experiment_id] = []
768769
if experiment_id not in self._files:
769770
self._files[experiment_id] = {}
771+
if isinstance(file_data, io.BytesIO):
772+
size = len(file_data.getvalue())
773+
else:
774+
size = len(file_data)
770775
new_file_element = {
771776
"Key": file_name,
772-
"Size": len(file_data),
777+
"Size": size,
773778
"LastModified": str(datetime.now()),
774779
}
775780
self._files_list[experiment_id].append(new_file_element)
@@ -798,4 +803,6 @@ def experiment_file_download(
798803
raise IBMExperimentEntryNotFound
799804
if file_name.endswith(".yaml"):
800805
return yaml.safe_load(self._files[experiment_id][file_name])
801-
return json.loads(self._files[experiment_id][file_name], cls=json_decoder)
806+
elif file_name.endswith(".json"):
807+
return json.loads(self._files[experiment_id][file_name], cls=json_decoder)
808+
return self._files[experiment_id][file_name].read()

qiskit_ibm_experiment/service/ibm_experiment_service.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -1692,19 +1692,24 @@ def file_upload(
16921692
json_encoder: Custom encoder to use to encode the experiment.
16931693
16941694
Additional info:
1695-
The filename is expected to end with ".json" (otherwise it will be added)
1695+
The filename is expected to end with ".json", ".yaml", or ".zip", otherwise
1696+
".json" will be added,
16961697
and the data itself should be either a dictionary or a JSON serialization
16971698
with the default encoder.
16981699
"""
1699-
# currently the resultdb enforces files to end with .json or .yaml
1700+
# currently resultdb enforces files to end with .json, .yaml, or .zip
17001701
# without suffix, we assume json formatting
1701-
if not (file_name.endswith(".json") or file_name.endswith(".yaml")):
1702+
if not (
1703+
file_name.endswith(".json")
1704+
or file_name.endswith(".yaml")
1705+
or file_name.endswith(".zip")
1706+
):
17021707
file_name += ".json"
17031708
if isinstance(file_data, dict):
17041709
# for now we avoid using custom encoder with yaml files
17051710
if file_name.endswith(".yaml"):
17061711
file_data = yaml.dump(file_data)
1707-
else:
1712+
elif file_name.endswith(".json"):
17081713
file_data = json.dumps(file_data, cls=json_encoder)
17091714
self._api_client.experiment_file_upload(experiment_id, file_name, file_data)
17101715

@@ -1722,10 +1727,14 @@ def file_download(
17221727
Returns:
17231728
The JSON deserialization of the data file
17241729
Additional info:
1725-
The filename is expected to end with ".json", otherwise
1726-
it will be added.
1730+
The filename is expected to end with ".json", ".yaml", or ".zip", otherwise
1731+
".json" will be added.
17271732
"""
1728-
if not (file_name.endswith(".json") or file_name.endswith(".yaml")):
1733+
if not (
1734+
file_name.endswith(".json")
1735+
or file_name.endswith(".yaml")
1736+
or file_name.endswith(".zip")
1737+
):
17291738
file_name += ".json"
17301739
# for now we avoid using custom decoder with yaml files
17311740
file_data = self._api_client.experiment_file_download(

0 commit comments

Comments
 (0)