@pytest.mark.parametrize('x, y', gradient_test_data)
def test_composition_qnodes_gradient(self, qnodes, x, y):
    'Test the gradient of composition of two QNode circuits'
    (f, g) = qnodes
    xt = Variable(x)
    yt = Variable(y)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        y = f(xt)
        grad1 = tape.gradient(y, xt)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        y = f(xt)
        grad2 = tape.gradient(y, xt)
    assert tf.equal(grad1, grad2)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        a = f(xt)
        y = f(a)
        grad1 = tape.gradient(y, a)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        a = f(xt)
        y = f(a)
        grad2 = tape.gradient(y, a)
    assert tf.equal(grad1, grad2)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        b = g(xt)
        y = g(b)
        grad1 = tape.gradient(y, b)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        b = g(xt)
        y = g(b)
        grad2 = tape.gradient(y, b)
    assert tf.equal(grad1, grad2)
Test the gradient of composition of two QNode circuits
@pytest.mark.parametrize('x, y', gradient_test_data)
def test_composition_qnodes_gradient(self, qnodes, x, y):
    
    (f, g) = qnodes
    xt = Variable(x)
    yt = Variable(y)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        y = f(xt)
        grad1 = tape.gradient(y, xt)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        y = f(xt)
        grad2 = tape.gradient(y, xt)
    assert tf.equal(grad1, grad2)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        a = f(xt)
        y = f(a)
        grad1 = tape.gradient(y, a)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        a = f(xt)
        y = f(a)
        grad2 = tape.gradient(y, a)
    assert tf.equal(grad1, grad2)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        b = g(xt)
        y = g(b)
        grad1 = tape.gradient(y, b)
    with tf.GradientTape() as tape:
        tape.watch([xt])
        b = g(xt)
        y = g(b)
        grad2 = tape.gradient(y, b)
    assert tf.equal(grad1, grad2)