code: def test_scipy__disconnected_variable(
      compile: bool, jit: bool, allow_unused_variables: bool
  ) -> None:
      target1 = [0.2, 0.8]
      v1 = tf.Variable([0.5, 0.5], dtype=default_float(), name="v1")
      v2 = tf.Variable([0.5], dtype=default_float(), name="v2")
  
      def f() -> tf.Tensor:
          # v2 not used.
          return tf.reduce_sum((target1 - v1) ** 2)
  
      opt = gpflow.optimizers.Scipy()
      tf_fun_args = {jit_compile_arg: True} if jit else {}
  
      if allow_unused_variables:
          with warnings.catch_warnings(record=True) as w:
              warnings.simplefilter("always")
              result = opt.minimize(
                  f,
                  [v1, v2],
                  compile=compile,
                  allow_unused_variables=allow_unused_variables,
                  tf_fun_args=tf_fun_args,
              )
  
          (warning,) = w
          message = warning.message
          assert isinstance(message, Warning)
          msg = message.args[0]
          assert v2.name in msg
  
          assert result.success
          np.testing.assert_allclose(target1 + [0.5], result.x)
          np.testing.assert_allclose(target1, v1)
          np.testing.assert_allclose([0.5], v2)
      else:
          with pytest.raises(ValueError, match=v2.name):
              opt.minimize(
                  f,
                  [v1, v2],
                  compile=compile,
                  allow_unused_variables=allow_unused_variables,
                  tf_fun_args=tf_fun_args,
              )
  
imports: import unittest
  import warnings
  from typing import Any, Callable, Dict, List, Sequence, Tuple
  from unittest.mock import MagicMock
  import numpy
  import pytest
  import tensorflow
  from packaging.version import Version
  import gpflow
  from gpflow.base import AnyNDArray
  from gpflow.config import default_float
  from gpflow.models import GPR, GPModel
  from gpflow.optimizers.scipy import LossClosure
label_desc: Use image node_id 6 for calling a global function with example usage: test_scipy__disconnected_variable(compile, jit, allow_unused_variables) and returns: tf