def test_cx_int(self, n): """Test CX.power(<int>) method. """ result = CnotGate().power(n) self.assertEqual(result.label, 'cx^' + str(n)) self.assertIsInstance(result, UnitaryGate) assert_array_almost_equal(result.to_matrix(), self.results[n])
def test_standard_2Q_one(self): """Test standard 2Q gate.repeat(1) method. """ qr = QuantumRegister(2, 'qr') expected_circ = QuantumCircuit(qr) expected_circ.append(CnotGate(), [qr[0], qr[1]]) expected = expected_circ.to_instruction() result = CnotGate().repeat(1) self.assertEqual(result.name, 'cx*1') self.assertEqual(result.definition, expected.definition) self.assertIsInstance(result, Gate)
def __init__(self, kak_basis_gate=CnotGate(), force_consolidate=False): """ Args: kak_basis_gate (Gate): Basis gate for KAK decomposition. force_consolidate (bool): Force block consolidation """ super().__init__() self.force_consolidate = force_consolidate self.decomposer = TwoQubitBasisDecomposer(kak_basis_gate)
def test_standard_2Q_zero(self): """Test standard 2Q gate.repeat(0) method. Raises, since n<1. """ with self.assertRaises(CircuitError) as context: _ = CnotGate().repeat(0) self.assertIn('strictly positive integer', str(context.exception))