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

Use marshal for save/load operators to improve performance #124

Merged
merged 20 commits into from
Jul 23, 2017
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0770e10
Merge pull request #1 from ProjectQ-Framework/develop
Spaceenter May 13, 2017
892f38b
Merge pull request #3 from ProjectQ-Framework/develop
Spaceenter May 17, 2017
b4e5455
Merge pull request #4 from ProjectQ-Framework/develop
Spaceenter May 22, 2017
0d97907
Merge pull request #5 from ProjectQ-Framework/develop
Spaceenter May 23, 2017
33423b7
Merge pull request #6 from ProjectQ-Framework/develop
Spaceenter May 25, 2017
305ee05
Merge pull request #7 from ProjectQ-Framework/develop
Spaceenter May 26, 2017
43e7c53
Merge pull request #8 from ProjectQ-Framework/develop
Spaceenter Jun 7, 2017
81e3d26
Merge pull request #9 from ProjectQ-Framework/develop
Spaceenter Jun 11, 2017
9175595
Merge pull request #10 from ProjectQ-Framework/develop
Spaceenter Jun 24, 2017
93b75c1
Merge pull request #11 from ProjectQ-Framework/develop
Spaceenter Jun 24, 2017
746457b
Merge pull request #12 from ProjectQ-Framework/develop
Spaceenter Jul 7, 2017
95a1666
Merge pull request #13 from ProjectQ-Framework/develop
Spaceenter Jul 10, 2017
a3e37e2
Merge pull request #14 from ProjectQ-Framework/develop
Spaceenter Jul 10, 2017
169b523
Merge pull request #15 from ProjectQ-Framework/develop
Spaceenter Jul 14, 2017
ed6bd08
Merge pull request #16 from ProjectQ-Framework/develop
Spaceenter Jul 15, 2017
10d8c1f
Merge pull request #17 from ProjectQ-Framework/develop
Spaceenter Jul 16, 2017
d7e57f2
Merge pull request #18 from ProjectQ-Framework/develop
Spaceenter Jul 22, 2017
a4bc785
Use marshal for save/load operators to improve performance
Spaceenter Jul 22, 2017
978c365
...
Spaceenter Jul 23, 2017
ba224de
make it work with python3
Spaceenter Jul 23, 2017
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
6 changes: 3 additions & 3 deletions src/fermilib/utils/_operator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from fermilib.config import *
from fermilib.ops import *
from itertools import *
from future.builtins.iterators import map, zip

from projectq.ops import QubitOperator

Expand Down Expand Up @@ -153,8 +153,8 @@ def save_operator(operator, file_name=None, data_directory=None):

tm = operator.terms
with open(file_path, 'wb') as f:
marshal.dump((operator_type, dict(izip(tm.iterkeys(),
imap(complex, tm.itervalues())))), f)
marshal.dump((operator_type, dict(zip(tm.keys(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the dictionary parts you should still be able to use iterkeys and itervalues from future.utils! i.e. iterkeys(tm).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure actually - I actually thought that Python3's d.keys() was 2's d.iterkeys(). In fact I didn't know about viewkeys at all. It looks like both should work, but I know that future.utils.iterkeys passes tests for both 2 and 3 - it would be interesting to see if there's anything different with viewkeys, though I don't think we need any of its special properties like dynamic view.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like tests for both 2 and 3 passed - should we go with this? Or do you want a change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be fine as is! If it's significantly slower I'll make another PR after this one gets through, but I doubt there'll be any issues.

map(complex, tm.values())))), f)
f.close()


Expand Down