code: def _load_operation(context, op_spec):
      if not isinstance(op_spec, pm.Operation):
          raise TypeError("Invalid Operation spec object")
  
      op_type = op_spec.type
      if op_type == "const" or "constexpr_" in op_type:
          if op_spec.blocks:
              raise ValueError(
                  "const / constexpr operation can't have any block"
              )
          if op_spec.inputs:
              raise ValueError(
                  "const / constexpr operation can't have any input"
              )
          _load_const_op(context, op_spec)
  
      else:
          if op_type == "custom_layer":
              raise NotImplementedError(
                  "Loading Custom Layer operation not yet implemented"
              )
  
          # The conversion steps of an operation proto -> PyMIL operation are as following:
  
          # (i)   Convert the input arguments:
          #       In most of the cases, the input variable is already created beforehand, hence we can
          #       directly access and get them through the TranscriptionContext.
          #       There are cases, though, the inputs are literal value. This could happens in the classify op spec.
          #       For that case, we directly create a constant variable.
  
          # (ii)  Create nested blocks for control flow operations:
          #       The Python functional input arguments for control flow ops cannot be recovered from milproto -> pymil conversion,
          #       for instance, the _body, _cond for mb.while_loop and _true_fn, _false_fn for mb.cond are not invertible
          #       Hence, here we directly create the nested blocks from the proto, and set them to mb.while_loop.blocks / mb.cond.blocks.
          #       Note that, when creating a block, PyMIL required an outer_op, which should be the control flow operation itself. However,
          #       in this approach we take, the outer_op hasn't been created at the time when the blocks produced. Here, we make a "dummy outer_op",
          #       which could pass the check in PyMIL, also it could provide enough information (such as visible variables in the blocks etc.)
          #       for the creation of the block.
  
          # (iii) Create PyMIL operation using inputs / blocks
          #       Note that for the control flow cases, we create dummy functional inputs, and use the existing block to create the op.
  
          # (iv)  Set the outer_op for control flow
          #       Once the operation is created, we replace the dummy outer_op with the legit one, to make it a valid PyMIL program
  
          attrs = list(op_spec.attributes.items())
          if len(attrs) > 0:
              if len(attrs) != 1 or attrs[0][0] != "name":
                  raise ValueError(
                      '"name" is the only supported attribute for operation'
                  )
          inputs = {
              k: _load_value(context, v)
              for k, v in op_spec.attributes.items()
          }
  
          for param_name, argument in op_spec.inputs.items():
              vars = []
              for binding in argument.arguments:
                  binding_type = binding.WhichOneof("binding")
                  if binding_type == "name":
                      vars.append(
                          context.get_var_from_name(binding.name)
                      )
                  elif binding_type == "value":
                      # We only support the list value for now (for the classifier use case)
                      value_spec = binding.value
                      assert (
                          value_spec.WhichOneof("value")
                          == "immediateValue"
                      )
                      assert (
                          value_spec.immediateValue.WhichOneof("value")
                          == "list"
                      )
                      list_value = _load_immediate_value(
                          value_spec.immediateValue
                      )
                      values = []
                      for value_spec in list_value:
                          values.append(
                              _load_value(context, value_spec)
                          )
                      var = mb.const(val=mil_list(values))
                      vars.append(var)
                  else:
                      raise NotImplementedError(
                          "Binding {} not yet implemented".format(
                              binding_type
                          )
                      )
              op_cls = _SSAOpRegistry._get_core_op_cls(op_type)
              if len(vars) == 1 and not isinstance(
                  op_cls.input_spec.input_types[param_name],
                  TupleInputType,
              ):
                  inputs[param_name] = vars[0]
              else:
                  inputs[param_name] = vars
  
          blocks = _create_nested_blocks(context, op_spec)
          _set_inputs_for_control_flow_op(inputs, blocks, op_type)
  
          output_var = getattr(mb, op_type)(**inputs)
          if not isinstance(output_var, (tuple, list)):
              output_var = [output_var]
  
          if len(output_var) != len(op_spec.outputs):
              raise AssertionError(
                  "Mismatch between number of outputs in operation specification vs PyMIL outputs"
              )
  
          for spec, var in zip(op_spec.outputs, output_var):
              context.register_var_with_name(spec.name, var)
  
              pymil_type = var.sym_type
              proto_type = proto_to_types(spec.type)
              if not types.is_compatible_type(pymil_type, proto_type):
                  # We allow a corner case where the pymil has an 0 rank tensor and the spec produces a scalar
                  if types.is_tensor(pymil_type) and types.is_scalar(
                      proto_type
                  ):
                      if pymil_type.get_primitive() == proto_type:
                          continue
                  raise AssertionError(
                      "Mismatch between var types in specification vs PyMIL"
                  )
  
          _set_outer_op_for_nested_blocks(blocks, output_var[0].op)
  
imports: import os
  import numpy
  from coremltools import _logger
  from coremltools.converters.mil._deployment_compatibility import AvailableTarget
  from coremltools.converters.mil.backend.mil import helper
  from coremltools.converters.mil.mil import Block
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Function, ListVar, Placeholder, Program, TupleInputType, Var, mil_list, types
  from coremltools.converters.mil.mil.block import curr_block
  from coremltools.converters.mil.mil.ops.registry import SSAOpRegistry
  from coremltools.proto import MIL_pb2
  from coremltools.proto import Model_pb2
  from .helper import proto_to_types
label_desc: Use image node_id 10 for calling a global function with example usage: _load_operation(context, op_spec) without return types