def get_bare_stabilizer(H: QubitOperator): ''' Identify the stabilizer of H. Currently admits only stabilizer with all z since hf can only identifies the value of these terms ''' n = get_number_qubit(H) pws = [] for pw, _ in H.terms.items(): pws.append(pw) binvecs = pauli2binvec(pws, n) nullvecs = binary_null_space(np.array(binvecs)) stabs = [] for vec in nullvecs: # If is all z if all(vec[:n] == 0): stab = QubitOperator.identity() for i in range(n): if vec[n + i] == 1: stab = stab * QubitOperator('Z' + str(i)) stabs.append(stab) else: print('Stabilizer with x/y terms ignored. ') return stabs
def test_binary_null_space(): matrix = np.array(prepare_binary_matrix()) null_basis = binary_null_space(matrix.copy()) # if gets null basis for vec in null_basis: assert (all((matrix @ vec.T) % 2 == 0))