def test_mat1(backend): if backend == 'qgate': pytest.xfail('mat1 gate for qgate is unimplemented.') p = random.random() * math.pi q = random.random() * math.pi r = random.random() * math.pi a1 = Circuit().u(p, q, r)[0].run(backend=backend) a2 = Circuit().x[0].u(p, q, r)[0].run(backend=backend) a = np.hstack([a1.reshape((2, 1)), a2.reshape((2, 1))]) b1 = Circuit().mat1(a)[0].run(backend=backend) assert np.allclose(a1, b1) b2 = Circuit().x[0].mat1(a)[0].run(backend=backend) assert np.allclose(a2, b2)
def test_mat1_decomposite(backend): if backend == 'qgate': pytest.xfail('mat1 gate for qgate is unimplemented.') p = random.random() * math.pi q = random.random() * math.pi r = random.random() * math.pi a1 = Circuit().u3(p, q, r)[0].run(backend=backend) a2 = Circuit().x[0].u3(p, q, r)[0].run(backend=backend) a = np.hstack([a1.reshape((2, 1)), a2.reshape((2, 1))]) c = Circuit().mat1(a)[2, 4] v1 = c.run(backend=backend) v2 = c.run_with_2q_decomposition( basis='cx', mat1_decomposer=u3_decomposer).run(backend=backend) assert is_vec_same(v1, v2)