diff --git a/src/qrisp/simulator/bi_array_helper.py b/src/qrisp/simulator/bi_array_helper.py index d02225b4..eacc84a2 100644 --- a/src/qrisp/simulator/bi_array_helper.py +++ b/src/qrisp/simulator/bi_array_helper.py @@ -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) diff --git a/src/qrisp/simulator/bi_arrays.py b/src/qrisp/simulator/bi_arrays.py index 17459a1a..0c788f45 100644 --- a/src/qrisp/simulator/bi_arrays.py +++ b/src/qrisp/simulator/bi_arrays.py @@ -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): @@ -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): diff --git a/src/qrisp/simulator/circuit_preprocessing.py b/src/qrisp/simulator/circuit_preprocessing.py index ce5bd21b..d272add3 100644 --- a/src/qrisp/simulator/circuit_preprocessing.py +++ b/src/qrisp/simulator/circuit_preprocessing.py @@ -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"]) diff --git a/src/qrisp/simulator/tensor_factor.py b/src/qrisp/simulator/tensor_factor.py index ae196ec2..9110431b 100644 --- a/src/qrisp/simulator/tensor_factor.py +++ b/src/qrisp/simulator/tensor_factor.py @@ -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])