code: def test_replace_nonreplaceable_vars():
      """
      The conversion should error out if an invalid replacement is invoked with nonreplaceable vars
      """
      constexpr_op = "constexpr_sparse_to_dense"
  
      @mb.program(input_specs=[mb.TensorSpec(shape=(4, 2))])
      def prog(x):
          constexpr = CONSTEXPR_FUNCS[constexpr_op]((4, 2))
          return mb.add(x=x, y=constexpr)
  
      block = prog.functions["main"]
      constexpr_op = block.find_ops(op_type=constexpr_op)[0]
  
      with block:
          const = mb.const(
              val=np.random.rand(4, 2), before_op=constexpr_op
          )
          expected_err_str = "might potentially be removed during the replacement of those vars."
          with pytest.raises(ValueError, match=expected_err_str):
              block.replace_uses_of_var_after_op(
                  anchor_op=constexpr_op,
                  old_var=constexpr_op.outputs[0],
                  new_var=const,
              )
  
imports: import copy
  import numpy
  import pytest
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil.passes.tests.test_passes import CONSTEXPR_FUNCS
  from coremltools.converters.mil.testing_utils import assert_same_output_names, assert_same_output_shapes, get_op_types_in_program
label_desc: Use image node_id 9 for calling a global function with example usage: test_replace_nonreplaceable_vars() and returns: mb