def __mul__(self, other):
        """Method to perform matrix multiplication. Combines gates sequentially
        and acts gates on registers. Multiplied objects must have the same size

        """

        if (type(other) == int):
            if (self.type == "Gate"):
                return Gate(self.array * other)
            else:
                return Qubit(self.array * other)

        elif (self.type == "Gate") and (other.type == "Gate"):
            assert self.array.shape == other.array.shape, "Gates must be of same size"
            return Gate(self.array * other.array)

        elif (self.type == "Qubit") and (other.type == "Qubit"):
            assert self.array.shape == other.array.shape, "Qubit registers must have same size"
            return Gate(sp.outer(self.array, other.array))

        else:
            assert (self.type == "Gate") and (
                other.type == "Qubit"), "Gate must act on Qubit register"
            #assert self.array.shape[0]==other.array.shape[0], "Qubit register and gate must be of same size"
            return Qubit(other.array * self.array)
Beispiel #2
0
def test_outer(shape1, shape2):
    s1 = sparse.random(shape1, density=0.5)
    s2 = sparse.random(shape2, density=0.5)

    x1 = s1.todense()
    x2 = s2.todense()

    assert_eq(sparse.outer(s1, s2), np.outer(x1, x2))
    assert_eq(np.multiply.outer(s1, s2), np.multiply.outer(x1, x2))
Beispiel #3
0
def test_outer(s1, s2):
    x1 = s1.todense()
    x2 = s2.todense()

    assert_eq(sparse.outer(s1, s2), np.outer(x1, x2))
    assert_eq(np.multiply.outer(s1, s2), np.multiply.outer(x1, x2))