Skip to content

Commit

Permalink
fixed some more simulation bottlenecks
Browse files Browse the repository at this point in the history
  • Loading branch information
positr0nium committed Feb 21, 2024
1 parent 8f11d05 commit 80a39c1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/qrisp/simulator/bi_array_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def sparse_matrix_mult(A, B):
log_sparsity_a = -np.log2(B.nnz/(B.shape[0]*B.shape[1]))
log_sparsity_b = -np.log2(A.nnz/(A.shape[0]*A.shape[1]))

if get_prediction(log_shape_0_a, log_shape_1_b, log_sparsity_a, log_sparsity_b):
if get_prediction(log_shape_0_a, log_shape_1_b, log_sparsity_a, log_sparsity_b) and False:
return (A @ B).tocoo()
else:
return coo_sparse_matrix_mult(A, B)
Expand Down
48 changes: 12 additions & 36 deletions src/qrisp/simulator/bi_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,43 +677,15 @@ def multi_measure(self, indices, return_new_arrays = True):


return new_bi_arrays, p_list, outcome_index_list




col_indices = sprs.indices
row_ptr = sprs.indptr
data = sprs.data

for r in range(len(row_ptr) - 1):
if row_ptr[r] != row_ptr[r + 1]:

temp_data = data[row_ptr[r] : row_ptr[r + 1]]
p = np.abs(np.vdot(temp_data, temp_data))

if p < float_tresh:
continue

p_list.append(p)
outcome_index_list.append(r)

if return_new_arrays:

new_bi_array = SparseBiArray(
(
col_indices[row_ptr[r] : row_ptr[r + 1]].astype(np.int64),
data[row_ptr[r] : row_ptr[r + 1]],
),
shape=(self.size // 2 ** len(indices),),
)

new_bi_arrays.append(new_bi_array)
else:

new_bi_arrays.append(None)

return new_bi_arrays, p_list, outcome_index_list

# Should return a cheap guess whether two inputs are linearly independent
def exclude_linear_indpendence(self, other):

if not 0.5 < len(self.data)/len(other.data) < 2:
return False
return True


# Calculate the squared norm, ie. the sesquilinear scalar product of self with
# itself
def squared_norm(self):
Expand Down Expand Up @@ -1135,6 +1107,10 @@ def vdot(self, other):
self.apply_swaps()
other.apply_swaps()
return np.vdot(self.data, other.data)

# Should return a cheap guess whether two inputs are linearly independent
def exclude_linear_indpendence(self, other):
return True

# This method works similarly as it's equivalent in SparseBiArray
def to_array(self):
Expand Down
9 changes: 2 additions & 7 deletions src/qrisp/simulator/circuit_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,13 +846,8 @@ def circuit_preprocessor(qc):
return qc.copy()

# TO-DO find reliable classifiaction when automatic disentangling works best
if len(qc.qubits) < 26:
qc = group_qc(qc)
elif len(qc.qubits) < 34:
qc = group_qc(qc)
if len(qc.qubits) > 45:
qc = insert_disentangling(qc)
else:
qc = insert_disentangling(qc)
qc = group_qc(qc)
qc = group_qc(qc)

return reorder_circuit(qc, ["measure", "reset", "disentangle"])
3 changes: 3 additions & 0 deletions src/qrisp/simulator/tensor_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def disentangle(self, qubit):
# print("disentangling successfull")
return TensorFactor([qubit], temp), TensorFactor(new_qubits, new_bi_arrays[0])

if not new_bi_arrays[0].exclude_linear_indpendence(new_bi_arrays[1]):
return self, self

vdot_value = new_bi_arrays[0].vdot(new_bi_arrays[1])


Expand Down

0 comments on commit 80a39c1

Please sign in to comment.