@pytest.mark.parametrize('x, y', gradient_test_data)
def test_addition_qnodes_gradient(self, qnodes, x, y):
    'Test the gradient of addition of two QNode circuits'
    (f, g) = qnodes

    def add(a, b):
        return (a + b)
    xt = Variable(x)
    yt = Variable(y)
    with tf.GradientTape() as tape:
        tape.watch([xt, yt])
        a = f(xt)
        b = g(yt)
        y = add(a, b)
        grad = tape.gradient(y, [a, b])
    assert (grad[0].numpy() == 1.0)
    assert (grad[1].numpy() == 1.0)
    with tf.GradientTape() as tape:
        tape.watch([xt, yt])
        a = f(xt)
        y = add(a, a)
        grad = tape.gradient(y, [a, a])
    assert (grad[0].numpy() == 2.0)
    assert (grad[1].numpy() == 2.0)
    with tf.GradientTape() as tape:
        tape.watch([xt, yt])
        a = f(xt)
        b = g(xt)
        y = add(a, b)
        grad = tape.gradient(y, [a, b])
    assert (grad[0].numpy() == 1.0)
    assert (grad[1].numpy() == 1.0)
Test the gradient of addition of two QNode circuits
@pytest.mark.parametrize('x, y', gradient_test_data)
def test_addition_qnodes_gradient(self, qnodes, x, y):
    
    (f, g) = qnodes

    def add(a, b):
        return (a + b)
    xt = Variable(x)
    yt = Variable(y)
    with tf.GradientTape() as tape:
        tape.watch([xt, yt])
        a = f(xt)
        b = g(yt)
        y = add(a, b)
        grad = tape.gradient(y, [a, b])
    assert (grad[0].numpy() == 1.0)
    assert (grad[1].numpy() == 1.0)
    with tf.GradientTape() as tape:
        tape.watch([xt, yt])
        a = f(xt)
        y = add(a, a)
        grad = tape.gradient(y, [a, a])
    assert (grad[0].numpy() == 2.0)
    assert (grad[1].numpy() == 2.0)
    with tf.GradientTape() as tape:
        tape.watch([xt, yt])
        a = f(xt)
        b = g(xt)
        y = add(a, b)
        grad = tape.gradient(y, [a, b])
    assert (grad[0].numpy() == 1.0)
    assert (grad[1].numpy() == 1.0)