def test_dihedral_random_decompose(self): """ Test that random elements are CNOTDihedral and to_circuit and from_circuit methods (where num_qubits < 3) """ for qubit_num in range(1, 5): for nseed in range(20): elem = random_cnotdihedral(qubit_num, seed=nseed) self.assertTrue(elem, 'Error: random element is not CNOTDihedral') if qubit_num < 3: test_circ = elem.to_circuit() self.assertTrue(test_circ, 'Error: cannot decompose a random ' 'CNOTDihedral element to a circuit') new_elem = CNOTDihedral(qubit_num) test_elem = new_elem.from_circuit(test_circ) # Test of to_circuit and from_circuit methods self.assertEqual(elem, test_elem, 'Error: decomposed circuit is not equal ' 'to the original circuit') test_gates = elem.to_instruction() self.assertIsInstance(test_gates, qiskit.circuit.Gate, 'Error: cannot decompose a random ' 'CNOTDihedral element to a Gate') self.assertEqual(test_gates.num_qubits, test_circ.num_qubits, 'Error: wrong num_qubits in decomposed gates') new_elem1 = CNOTDihedral(qubit_num) test_elem1 = new_elem1.from_circuit(test_gates) # Test of to_instruction and from_circuit methods self.assertEqual(elem, test_elem1, 'Error: decomposed gates are not equal ' 'to the original gates')
def test_dot_method(self): """Test dot method""" samples = 10 nseed = 222 for qubit_num in range(1, 3): for i in range(samples): elem1 = random_cnotdihedral(qubit_num, seed=nseed + i) elem2 = random_cnotdihedral(qubit_num, seed=nseed + samples + i) circ1 = elem1.to_circuit() circ2 = elem2.to_circuit() value = elem1.dot(elem2) target = CNOTDihedral(qubit_num) target = target.from_circuit(circ2.extend(circ1)) self.assertEqual(target, value, 'Error: composed circuit is not the same')
def test_dihedral_random_decompose(self): """ Test that random elements are CNOTDihedral and to_circuit and from_circuit methods (where num_qubits < 3) """ for qubit_num in range(1, 5): for nseed in range(20): elem = random_cnotdihedral(qubit_num, seed=nseed) self.assertTrue(elem, 'Error: random element is not CNOTDihedral') if qubit_num < 3: test_circ = elem.to_circuit() self.assertTrue( test_circ, 'Error: cannot decompose a random ' 'CNOTDihedral element to a circuit') new_elem = CNOTDihedral(qubit_num) test_elem = new_elem.from_circuit(test_circ) # Test of to_circuit and from_circuit methods self.assertEqual( elem, test_elem, 'Error: decomposed circuit is not equal ' 'to the original circuit')