Skip to content

Commit

Permalink
Merge pull request qutip#2038 from hodgestar/fix/add-back-qu-suffix-t…
Browse files Browse the repository at this point in the history
…o-saved-objects

Add back .qu suffix to saved objects
  • Loading branch information
hodgestar committed Dec 8, 2022
2 parents ae300dc + b6fa790 commit ee9c200
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/changes/2038.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add back .qu suffix to objects saved with qsave and loaded with qload.
12 changes: 6 additions & 6 deletions qutip/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def qsave(data, name='qutip_data'):
"""
# open the file for writing
file = Path(name)
file = file.with_suffix(file.suffix + ".qu")
path = Path(name)
path = path.with_suffix(path.suffix + ".qu")

with open(name, "wb") as fileObject:
with open(path, "wb") as fileObject:
# this writes the object a to the file named 'filename.qu'
pickle.dump(data, fileObject)

Expand All @@ -244,10 +244,10 @@ def qload(name):
Object retrieved from requested file.
"""
file = Path(name)
file = file.with_suffix(file.suffix + ".qu")
path = Path(name)
path = path.with_suffix(path.suffix + ".qu")

with open(name, "rb") as fileObject:
with open(path, "rb") as fileObject:
if sys.version_info >= (3, 0):
out = pickle.load(fileObject, encoding='latin1')
else:
Expand Down
3 changes: 3 additions & 0 deletions qutip/tests/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

_dimension = 10


def _random_file_name():
return "_" + str(uuid.uuid4())

Expand Down Expand Up @@ -57,3 +58,5 @@ def test_qsave_qload(use_path, suffix):
qutip.qsave(ops_in, filename)
ops_out = qutip.qload(filename)
assert ops_in == ops_out
# check that the file was saved with the correct name:
assert Path(str(filename) + ".qu").exists()

0 comments on commit ee9c200

Please sign in to comment.