-
Notifications
You must be signed in to change notification settings - Fork 62
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
Fix and speed-up DBI tests #1245
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1245 +/- ##
=======================================
Coverage 99.95% 99.95%
=======================================
Files 72 72
Lines 10452 10454 +2
=======================================
+ Hits 10447 10449 +2
Misses 5 5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Maybe this is out of the scope of this PR, but the from functools import reduce
from itertools import product
import numpy as np
from qibo import matrices
from qibo.models.dbi.utils import generate_Z_operators
def generate_Z_operators_new(nqubits):
combination_strings = list(product(["I", "Z"], repeat=nqubits))[1:]
dictionary = {}
dictionary["I"*nqubits] = np.eye(2**nqubits, dtype=complex)
for string in combination_strings:
matrix = [getattr(matrices, s) for s in string]
matrix = reduce(np.kron, matrix)
dictionary["".join(string)] = matrix
del matrix # maybe this is needed to control memory usage for nqubits >= 7-ish
return dictionary
nqubits = 2
%timeit generate_Z_operators(nqubits)
%timeit generate_Z_operators_new(nqubits)
nqubits = 5
%timeit generate_Z_operators(nqubits)
%timeit generate_Z_operators_new(nqubits) This is in line of how |
@Sam-XiaoyueLi please have a look Thank you @renatomello for the useful suggestion! |
@MatteoRobbiati may I ask you to review this soon because #1202 depends on it? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @andrea-pasquale for the fix and @renatomello for the reminder.
There is one test failing in test_quantum_info_metrics.py
with the tensorflow backend, but I guess we can face it elsewhere.
Now DBI tests are much faster and the implementation is GPU compatible.
Checklist: