From b57b652e9f8df3accc97d4d6bc8d31dd4e33d98b Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 22 Sep 2023 16:32:22 +0200 Subject: [PATCH] add tests --- .../test_clifford_utils.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/library/randomized_benchmarking/test_clifford_utils.py b/test/library/randomized_benchmarking/test_clifford_utils.py index 000ed3c36c..f9cac4d8ee 100644 --- a/test/library/randomized_benchmarking/test_clifford_utils.py +++ b/test/library/randomized_benchmarking/test_clifford_utils.py @@ -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, @@ -43,6 +44,7 @@ _num_from_layer_indices, _layer_indices_from_num, _CLIFFORD_LAYER, + _CLIFFORD_INVERSE_2Q, ) @@ -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)