Skip to content

Commit

Permalink
Merge pull request #229 from Qiskit-Extensions/remove-SDD-stuff
Browse files Browse the repository at this point in the history
Remove SDD stuff
  • Loading branch information
nonhermitian authored Sep 25, 2024
2 parents 14832a8 + da7fb0f commit ed6e545
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 202 deletions.
85 changes: 0 additions & 85 deletions mthree/matrix.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -98,88 +98,3 @@ cdef void omp_element_compute(size_t jj, const unsigned char * bitstrings,
col_norms_ptr[jj] = col_norm
for ii in range(num_elems):
W_ptr[col_idx+ii] /= col_norm

@cython.boundscheck(False)
def sdd_check(dict counts, float[::1] cals,
unsigned int num_bits, unsigned int distance):
"""Determines if the sub-space A matrix is strictly
diagonally dominant or not.
Parameters:
counts (dict): Input dict of counts.
cals (double ndarray): Calibrations.
num_bits (unsigned int): Number of bits in bit-strings.
distance (unsigned int): Distance to go out to.
Returns:
int: Is matrix SDD or not.
"""
cdef float shots = sum(counts.values())
cdef map[string, float] counts_map = counts
cdef unsigned int num_elems = counts_map.size()
cdef unsigned int MAX_DIST

cdef size_t row
cdef unsigned int is_sdd = 1

if distance > num_bits:
raise ValueError('Distance ({}) cannot be larger than'
'the number of bits ({}).'.format(distance, num_bits))

MAX_DIST = distance == num_bits

# Assign memeory for bitstrings and input probabilities
cdef unsigned char * bitstrings = <unsigned char *>malloc(num_bits*num_elems*sizeof(unsigned char))
cdef float * input_probs = <float *>malloc(num_elems*sizeof(float))
# Assign memeory for column norms
cdef float * col_norms = <float *>malloc(num_elems*sizeof(float))

# Assign memeory sdd checks
cdef bool * row_sdd = <bool *>malloc(num_elems*sizeof(bool))
# Convert sorted counts dict into bistrings and input probability arrays
counts_to_internal(&counts_map, bitstrings, input_probs, num_bits, shots)
# Compute column norms
compute_col_norms(col_norms, bitstrings, &cals[0], num_bits, num_elems, distance)

with nogil:
for row in prange(num_elems, schedule='static'):
omp_sdd_compute(row, bitstrings, &cals[0], col_norms,
row_sdd, num_bits, num_elems, distance, MAX_DIST)

for row in range(num_elems):
if not row_sdd[row]:
is_sdd = 0
break

# Free stuff here
# ---------------
free(bitstrings)
free(input_probs)
free(col_norms)
free(row_sdd)

return is_sdd

@cython.boundscheck(False)
@cython.cdivision(True)
cdef void omp_sdd_compute(size_t row,
const unsigned char * bitstrings,
const float * cals,
const float * col_norms,
bool * row_sdd,
unsigned int num_bits,
unsigned int num_elems,
unsigned int distance,
unsigned int MAX_DIST) noexcept nogil:

cdef size_t col
cdef float diag_elem, mat_elem, row_sum = 0

diag_elem = matrix_element(row, row, bitstrings, cals, num_bits, distance, MAX_DIST)
diag_elem /= col_norms[row]
for col in range(num_elems):
if col != row:
mat_elem = matrix_element(row, col, bitstrings, cals, num_bits, distance, MAX_DIST)
mat_elem /= col_norms[col]
row_sum += mat_elem
row_sdd[row] = row_sum < diag_elem
31 changes: 1 addition & 30 deletions mthree/mitigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
balanced_cal_strings,
balanced_cal_circuits,
)
from mthree.matrix import _reduced_cal_matrix, sdd_check
from mthree.matrix import _reduced_cal_matrix
from mthree.utils import counts_to_vector, vector_to_quasiprobs, gmres
from mthree.norms import ainv_onenorm_est_lu, ainv_onenorm_est_iter
from mthree.matvec import M3MatVec
Expand Down Expand Up @@ -111,35 +111,6 @@ def _form_cals(self, qubits):
cals[4 * kk: 4 * kk + 4] = self.single_qubit_cals[qubit].ravel()
return cals

def _check_sdd(self, counts, qubits, distance=None):
"""Checks if reduced A-matrix is SDD or not
Parameters:
counts (dict): Dictionary of counts.
qubits (array_like): List of qubits.
distance (int): Distance to compute over.
Returns:
bool: True if A-matrix is SDD, else False
Raises:
M3Error: Number of qubits supplied does not match bit-string length.
"""
# If distance is None, then assume max distance.
num_bits = len(qubits)
if distance is None:
distance = num_bits

# check if len of bitstrings does not equal number of qubits passed.
bitstring_len = len(next(iter(counts)))
if bitstring_len != num_bits:
raise M3Error(
"Bitstring length ({}) does not match".format(bitstring_len)
+ " number of qubits ({})".format(num_bits)
)
cals = self._form_cals(qubits)
return sdd_check(counts, cals, num_bits, distance)

def tensored_cals_from_system(
self, qubits=None, shots=None, method="balanced", rep_delay=None, cals_file=None
):
Expand Down
87 changes: 0 additions & 87 deletions mthree/test/test_sdd.py

This file was deleted.

0 comments on commit ed6e545

Please sign in to comment.