Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Sep 22, 2023
1 parent ef6ec4b commit b57b652
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/library/randomized_benchmarking/test_clifford_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from numpy.random import default_rng

from qiskit import QuantumCircuit
from qiskit.exceptions import QiskitError
from qiskit.circuit.library import (
IGate,
XGate,
Expand All @@ -43,6 +44,7 @@
_num_from_layer_indices,
_layer_indices_from_num,
_CLIFFORD_LAYER,
_CLIFFORD_INVERSE_2Q,
)


Expand Down Expand Up @@ -195,3 +197,24 @@ def test_num_from_layer(self):
circ.compose(_CLIFFORD_LAYER[layer][idx], inplace=True)
layered = Clifford(circ)
self.assertEqual(standard, layered)

def test_num_from_2q_circuit(self):
qc = QuantumCircuit(2)
qc.h(0)
num = num_from_2q_circuit(qc)
self.assertEqual(num, 1)
qc = qc.decompose()
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)

# regression test for using the dense multiplication table
qc = QuantumCircuit(2)
qc.cz(1, 0)
num = num_from_2q_circuit(qc)

def test_clifford_inverse_table(self):
for lhs, rhs in enumerate(_CLIFFORD_INVERSE_2Q):
c = compose_2q(lhs, rhs)
self.assertEqual(c, 0)
print(lhs, rhs, c)

0 comments on commit b57b652

Please sign in to comment.