def test_cx_bell_to_iswap(self): """Verify we can translate a CX bell to iSwap,U3.""" bell = QuantumCircuit(2) bell.h(0) bell.cx(0, 1) in_dag = circuit_to_dag(bell) out_dag = BasisTranslator(std_eqlib, ['iswap', 'u']).run(in_dag) self.assertTrue(set(out_dag.count_ops()).issubset(['iswap', 'u'])) self.assertEqual(Operator(bell), Operator(dag_to_circuit(out_dag)))
def test_cx_bell_to_cz(self): """Verify we can translate a CX bell circuit to CZ,RX,RZ.""" bell = QuantumCircuit(2) bell.h(0) bell.cx(0, 1) in_dag = circuit_to_dag(bell) out_dag = BasisTranslator(std_eqlib, ['cz', 'rx', 'rz']).run(in_dag) self.assertTrue(set(out_dag.count_ops()).issubset(['cz', 'rx', 'rz'])) self.assertEqual(Operator(bell), Operator(dag_to_circuit(out_dag)))
def test_definition_unroll_parameterized(self): """Verify that unrolling complex gates with parameters does not raise.""" qr = QuantumRegister(2) qc = QuantumCircuit(qr) theta = Parameter('theta') qc.cp(theta, qr[1], qr[0]) qc.cp(theta * theta, qr[0], qr[1]) dag = circuit_to_dag(qc) pass_ = UnrollCustomDefinitions(std_eqlib, ['p', 'cx']) dag = pass_.run(dag) out_dag = BasisTranslator(std_eqlib, ['p', 'cx']).run(dag) self.assertEqual(out_dag.count_ops(), {'p': 6, 'cx': 4})
def test_cx_bell_to_cp(self): """Verify we can translate a CX bell to CP,U.""" bell = QuantumCircuit(2) bell.h(0) bell.cx(0, 1) in_dag = circuit_to_dag(bell) out_dag = BasisTranslator(std_eqlib, ["cp", "u"]).run(in_dag) self.assertTrue(set(out_dag.count_ops()).issubset(["cp", "u"])) self.assertEqual(Operator(bell), Operator(dag_to_circuit(out_dag))) qr = QuantumRegister(2, "q") expected = QuantumCircuit(qr) expected.u(pi / 2, 0, pi, 0) expected.u(pi / 2, 0, pi, 1) expected.cp(pi, 0, 1) expected.u(pi / 2, 0, pi, 1) expected_dag = circuit_to_dag(expected) self.assertEqual(out_dag, expected_dag)