Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Sep 25, 2023
1 parent caa947a commit 7bd41ec
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
_CLIFFORD_INVERSE_2Q = np.load(f"{_DATA_FOLDER}/clifford_inverse_2q.npz")["table"]
_clifford_compose_2q_data = np.load(f"{_DATA_FOLDER}/clifford_compose_2q_dense_selected.npz")
_CLIFFORD_COMPOSE_2Q_DENSE = _clifford_compose_2q_data["table"]
# valid indices for the columns of the _CLIFFORD_COMPOSE_2Q_DENSE table
_valid_sparse_indices = _clifford_compose_2q_data["valid_sparse_indices"]
# map a clifford number to the index of _CLIFFORD_COMPOSE_2Q_DENSE
_clifford_num_to_dense_index = {idx: ii for ii, idx in enumerate(_valid_sparse_indices)}

# Transpilation utilities
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,27 @@ def gen_clifford_compose_2q_gate():
for rhs in _CLIFF_SINGLE_GATE_MAP_2Q.values():
composed = cliff_lhs.compose(_CLIFF_2Q[rhs])
products[lhs, rhs] = _TO_INT_2Q[_hash_cliff(composed)]
return products.tocsr()
return products.tocsc()


def gen_clifford_compose_2q_dense() -> tuple[np.typing.NDArray[int], list[int]]:
"""Generate a dense multiplication table for 1-qubit Clifford numbers
The multiplication table is generated from the sparse table generated by :meth:`gen_clifford_compose_2q_gate`.
Returns:
Tuple with a dense multiplication table and the valid indices for the columns
"""
_CLIFFORD_COMPOSE_2Q = gen_clifford_compose_2q_gate()
number_of_cliffords = _CLIFFORD_COMPOSE_2Q.shape[0]
valid_sparse_indices = [
num
for num in range(number_of_cliffords)
if _CLIFFORD_COMPOSE_2Q[:, num].nnz == number_of_cliffords - 1
]
_CLIFFORD_COMPOSE_2Q_DENSE = _CLIFFORD_COMPOSE_2Q[:, valid_sparse_indices].toarray()

return _CLIFFORD_COMPOSE_2Q_DENSE, valid_sparse_indices


_GATE_LIST_1Q = [
Expand Down Expand Up @@ -185,18 +205,10 @@ def gen_cliff_single_2q_gate_map():
)
np.savez_compressed("clifford_inverse_2q.npz", table=gen_clifford_inverse_2q())

_CLIFFORD_COMPOSE_2Q = gen_clifford_compose_2q_gate()
scipy.sparse.save_npz("clifford_compose_2q_sparse.npz", _CLIFFORD_COMPOSE_2Q)

_CLIFFORD_COMPOSE_2Q_TRANSPOSED = _CLIFFORD_COMPOSE_2Q.T
valid_sparse_indices = [
num for num in range(11520) if _CLIFFORD_COMPOSE_2Q_TRANSPOSED[num, :].nnz == 11520 - 1
]
clifford_num_to_dense_index = {idx: ii for ii, idx in enumerate(valid_sparse_indices)}
_CLIFFORD_COMPOSE_2Q_DENSE, valid_sparse_indices = gen_clifford_compose_2q_dense()

np.savez_compressed(
"clifford_compose_2q_dense_selected.npz",
table=_CLIFFORD_COMPOSE_2Q[:, valid_sparse_indices].toarray(),
table=_CLIFFORD_COMPOSE_2Q_DENSE,
valid_sparse_indices=valid_sparse_indices,
clifford_num_to_dense_index=clifford_num_to_dense_index,
)
3 changes: 2 additions & 1 deletion test/library/randomized_benchmarking/test_clifford_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def test_num_from_2q_circuit(self):
qc.h(0)
num = num_from_2q_circuit(qc)
self.assertEqual(num, 5760)
qc = qc.decompose()
qc = QuantumCircuit(2)
qc.u(0, 0, np.pi, 0)
with self.assertRaises(QiskitError):
# raising an error is ok, num_from_2q_circuit does not support all 2-qubit gates
num_from_2q_circuit(qc)
Expand Down

0 comments on commit 7bd41ec

Please sign in to comment.