Skip to content

Commit

Permalink
Fix error message when successively loading the same dataset (#4422)
Browse files Browse the repository at this point in the history
  • Loading branch information
brownj85 authored Aug 1, 2023
1 parent ff87866 commit f91811d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pennylane/data/base/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ def open(
filepath = Path(filepath).expanduser()

if mode == "copy":
f_to_copy = h5py.File(filepath, "r")
f = hdf5.create_group()
hdf5.copy_all(f_to_copy, f)
f_to_copy.close()
with h5py.File(filepath, "r") as f_to_copy:
f = hdf5.create_group()
hdf5.copy_all(f_to_copy, f)
else:
f = h5py.File(filepath, mode)

Expand Down
2 changes: 1 addition & 1 deletion pennylane/data/data_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def load( # pylint: disable=too-many-arguments
if result.exception() is not None:
raise result.exception()

return [Dataset.open(Path(dest_path), "r") for dest_path in dest_paths]
return [Dataset.open(Path(dest_path), "a") for dest_path in dest_paths]


def list_datasets() -> dict:
Expand Down

0 comments on commit f91811d

Please sign in to comment.