code: def create_optimization_step(optimizer, model: gpflow.models.GPR):
      @tf.function
      def optimization_step():
          with tf.GradientTape(watch_accessed_variables=False) as tape:
              tape.watch(model.trainable_variables)
              objective = model.training_loss()
          grads = tape.gradient(objective, model.trainable_variables)
          optimizer.apply_gradients(
              zip(grads, model.trainable_variables)
          )
          return objective
  
      return optimization_step
  
file_path: GPflow/notebooks/tailor/external-mean-function.pct.py
imports: import matplotlib.pyplot
  import numpy
  import tensorflow
  import gpflow
  from gpflow.ci_utils import reduce_in_tests
  from gpflow.kernels import RBF
  from gpflow.models import GPR
  from gpflow.config import default_float
  from gpflow import set_trainable
  import time
label_desc: Use image node_id 5 for calling a global function with example usage: create_optimization_step(optimizer, model) and returns: optimization_step, objective