def test_variadic_arguments(self, mock_device):
        """Test that variadic arguments are properly converted to Variable instances."""
        def circuit(a, *b):
            qml.RX(a, wires=[0])
            qml.RX(b[0], wires=[0])
            qml.RX(b[1][1], wires=[0])
            qml.RX(b[2], wires=[0])

            return qml.expval(qml.PauliX(0))

        node = BaseQNode(circuit, mock_device)
        arg_vars, kwarg_vars = node._make_variables(
            [0.1, 0.2, np.array([0, 1, 2, 3]), 0.5], {})

        expected_arg_vars = [
            Variable(0, "a"),
            Variable(1, "b[0]"),
            Variable(2, "b[1][0]"),
            Variable(3, "b[1][1]"),
            Variable(4, "b[1][2]"),
            Variable(5, "b[1][3]"),
            Variable(6, "b[2]"),
        ]

        assert not kwarg_vars

        for var, expected in zip(qml.utils._flatten(arg_vars),
                                 expected_arg_vars):
            assert var == expected
    def test_array_arguments(self, mock_device):
        """Test that array arguments are properly converted to Variable instances."""
        def circuit(weights):
            qml.RX(weights[0, 0], wires=[0])
            qml.RY(weights[0, 1], wires=[0])
            qml.RZ(weights[1, 0], wires=[0])
            qml.RZ(weights[1, 1], wires=[0])

            return qml.expval(qml.PauliX(0))

        node = BaseQNode(circuit, mock_device)

        weights = np.array([[1, 2], [3, 4]])
        arg_vars, kwarg_vars = node._make_variables([weights], {})

        expected_arg_vars = [
            Variable(0, "weights[0,0]"),
            Variable(1, "weights[0,1]"),
            Variable(2, "weights[1,0]"),
            Variable(3, "weights[1,1]"),
        ]

        for var, expected in zip(qml.utils._flatten(arg_vars),
                                 expected_arg_vars):
            assert var == expected

        assert not kwarg_vars
    def test_regular_keyword_arguments(self, mock_device):
        """Test that regular keyword arguments are properly converted to Variable instances."""
        def circuit(*, a=1, b=2, c=3, d=4):
            qml.RX(a, wires=[0])
            qml.RY(b, wires=[0])
            qml.RZ(c, wires=[0])
            qml.RZ(d, wires=[0])

            return qml.expval(qml.PauliX(0))

        node = BaseQNode(circuit, mock_device)
        arg_vars, kwarg_vars = node._make_variables([], {"b": 3})

        expected_kwarg_vars = {
            "a": [Variable(0, "a", is_kwarg=True)],
            "b": [Variable(0, "b", is_kwarg=True)],
            "c": [Variable(0, "c", is_kwarg=True)],
            "d": [Variable(0, "d", is_kwarg=True)],
        }

        assert not arg_vars

        for expected_key in expected_kwarg_vars:
            for var, expected in zip(
                    qml.utils._flatten(kwarg_vars[expected_key]),
                    qml.utils._flatten(expected_kwarg_vars[expected_key]),
            ):
                assert var == expected
    def test_regular_arguments(self, mock_device):
        """Test that regular arguments are properly converted to Variable instances."""
        def circuit(a, b, c, d):
            qml.RX(a, wires=[0])
            qml.RY(b, wires=[0])
            qml.RZ(c, wires=[0])
            qml.RZ(d, wires=[0])

            return qml.expval(qml.PauliX(0))

        node = BaseQNode(circuit, mock_device)
        arg_vars, kwarg_vars = node._make_variables([1.0, 2.0, 3.0, 4.0], {})

        expected_arg_vars = [
            Variable(0, "a"),
            Variable(1, "b"),
            Variable(2, "c"),
            Variable(3, "d"),
        ]

        for var, expected in zip(qml.utils._flatten(arg_vars),
                                 expected_arg_vars):
            assert var == expected

        assert not kwarg_vars
    def test_array_keyword_arguments(self, mock_device):
        """Test that array keyword arguments are properly converted to Variable instances."""
        def circuit(*, a=np.array([[1, 0], [0, 1]]), b=np.array([1, 2, 3])):
            qml.RX(a[0, 0], wires=[0])
            qml.RX(a[0, 1], wires=[0])
            qml.RX(a[1, 0], wires=[0])
            qml.RX(a[1, 1], wires=[0])
            qml.RY(b[0], wires=[0])
            qml.RY(b[1], wires=[0])
            qml.RY(b[2], wires=[0])

            return qml.expval(qml.PauliX(0))

        node = BaseQNode(circuit, mock_device)
        arg_vars, kwarg_vars = node._make_variables(
            [], {"b": np.array([6, 7, 8, 9])})

        expected_kwarg_vars = {
            "a": [
                Variable(0, "a[0,0]", is_kwarg=True),
                Variable(1, "a[0,1]", is_kwarg=True),
                Variable(2, "a[1,0]", is_kwarg=True),
                Variable(3, "a[1,1]", is_kwarg=True),
            ],
            "b": [
                Variable(0, "b[0]", is_kwarg=True),
                Variable(1, "b[1]", is_kwarg=True),
                Variable(2, "b[2]", is_kwarg=True),
                Variable(3, "b[3]", is_kwarg=True),
            ],
        }

        assert not arg_vars

        for expected_key in expected_kwarg_vars:
            for var, expected in zip(
                    qml.utils._flatten(kwarg_vars[expected_key]),
                    qml.utils._flatten(expected_kwarg_vars[expected_key]),
            ):
                assert var == expected