def test_keywordarg_gradient(self, qubit_device_2_wires, tol):
    "Tests that qnodes' keyword arguments work with gradients"

    def circuit(x, y, input_state=np.array([0, 0])):
        qml.BasisState(input_state, wires=[0, 1])
        qml.RX(x, wires=[0])
        qml.RY(y, wires=[0])
        return qml.expval(qml.PauliZ(0))
    circuit = qml.QNode(circuit, qubit_device_2_wires).to_tf()
    x = 0.543
    y = 0.45632
    expected_grad = np.array([(np.sin(x) * np.cos(y)), (np.sin(y) * np.cos(x))])
    x_t = Variable(x)
    y_t = Variable(y)
    with tf.GradientTape() as tape:
        c = circuit(x_t, y_t, input_state=np.array([0, 0]))
        grads = np.array(tape.gradient(c, [x_t, y_t]))
    assert np.allclose(grads, (- expected_grad), atol=tol, rtol=0)
    with tf.GradientTape() as tape:
        c = circuit(x_t, y_t, input_state=np.array([1, 0]))
        grads = np.array(tape.gradient(c, [x_t, y_t]))
    assert np.allclose(grads, expected_grad, atol=tol, rtol=0)
    with tf.GradientTape() as tape:
        c = circuit(x_t, y_t)
        grads = np.array(tape.gradient(c, [x_t, y_t]))
    assert np.allclose(grads, (- expected_grad), atol=tol, rtol=0)
Tests that qnodes' keyword arguments work with gradients
def test_keywordarg_gradient(self, qubit_device_2_wires, tol):
    

    def circuit(x, y, input_state=np.array([0, 0])):
        qml.BasisState(input_state, wires=[0, 1])
        qml.RX(x, wires=[0])
        qml.RY(y, wires=[0])
        return qml.expval(qml.PauliZ(0))
    circuit = qml.QNode(circuit, qubit_device_2_wires).to_tf()
    x = 0.543
    y = 0.45632
    expected_grad = np.array([(np.sin(x) * np.cos(y)), (np.sin(y) * np.cos(x))])
    x_t = Variable(x)
    y_t = Variable(y)
    with tf.GradientTape() as tape:
        c = circuit(x_t, y_t, input_state=np.array([0, 0]))
        grads = np.array(tape.gradient(c, [x_t, y_t]))
    assert np.allclose(grads, (- expected_grad), atol=tol, rtol=0)
    with tf.GradientTape() as tape:
        c = circuit(x_t, y_t, input_state=np.array([1, 0]))
        grads = np.array(tape.gradient(c, [x_t, y_t]))
    assert np.allclose(grads, expected_grad, atol=tol, rtol=0)
    with tf.GradientTape() as tape:
        c = circuit(x_t, y_t)
        grads = np.array(tape.gradient(c, [x_t, y_t]))
    assert np.allclose(grads, (- expected_grad), atol=tol, rtol=0)