def test_defgate(): dg = DefGate("TEST", np.array([[1., 0.], [0., 1.]])) assert dg.out() == "DEFGATE TEST:\n 1.0, 0.0\n 0.0, 1.0\n" test = dg.get_constructor() tg = test(DirectQubit(1), DirectQubit(2)) assert tg.out() == "TEST 1 2"
def test_defgate(): dg = DefGate("TEST", np.array([[0 + 0.5j, 0.5], [0.5, 0 - 0.5j]])) assert dg.out( ) == "DEFGATE TEST:\n 0.0+0.5i, 0.5+0.0i\n 0.5+0.0i, 0.0-0.5i\n" test = dg.get_constructor() tg = test(DirectQubit(1), DirectQubit(2)) assert tg.out() == "TEST 1 2"
def unpack_qubit(qubit): """ Get a qubit from an object. :param qubit: An int or AbstractQubit. :return: An AbstractQubit instance """ if isinstance(qubit, int): return DirectQubit(qubit) elif not isinstance(qubit, AbstractQubit): raise TypeError("qubit should be an int or AbstractQubit instance") else: return qubit
def test_defgate_param(): dgp = DefGate("TEST", [[1., 0.], [0., 1.]]) assert dgp.out() == "DEFGATE TEST:\n 1.0, 0.0\n 0.0, 1.0\n" test = dgp.get_constructor() tg = test(DirectQubit(1)) assert tg.out() == "TEST 1"
def test_gate(): tg = Gate("TEST", qubits=(DirectQubit(1), DirectQubit(2)), params=[]) assert tg.out() == "TEST 1 2"