def test_crotations_cirq(): c1 = Circuit(3) c1.add(gates.RX(0, 0.1)) c1.add(gates.RZ(1, 0.4)) c1.add(gates.CRX(0, 2, 0.5)) c1.add(gates.RY(1, 0.3).controlled_by(2)) # catches unknown gate "crx" with pytest.raises(exception.QasmException): c2 = circuit_from_qasm(c1.to_qasm())
def test_from_qasm_crotations(): import numpy as np target = """OPENQASM 2.0; qreg q[2]; crx(0.1) q[0],q[1]; crz(0.3) q[1],q[0]; cry(0.2) q[0],q[1];""" c = Circuit.from_qasm(target) assert c.depth == 3 assert isinstance(c.queue[0], gates.CRX) assert isinstance(c.queue[1], gates.CRZ) assert isinstance(c.queue[2], gates.CRY) c2 = Circuit(2) c2.add([gates.CRX(0, 1, 0.1), gates.CRZ(1, 0, 0.3), gates.CRY(0, 1, 0.2)]) np.testing.assert_allclose(c2().numpy(), c().numpy())
def test_crotations(): c = Circuit(3) c.add(gates.RX(0, 0.1)) c.add(gates.RZ(1, 0.4)) c.add(gates.CRX(0, 2, 0.5)) c.add(gates.RY(1, 0.3).controlled_by(2)) target = f"""// Generated by QIBO {__version__} OPENQASM 2.0; include "qelib1.inc"; qreg q[3]; rx(0.1) q[0]; rz(0.4) q[1]; crx(0.5) q[0],q[2]; cry(0.3) q[2],q[1];""" assert_strings_equal(c.to_qasm(), target) c = Circuit(2) c.add(gates.CU2(0, 1, 0.1, 0.2)) with pytest.raises(ValueError): target = c.to_qasm()