code: def test_solving_backward_pde_for_sde_with_const_coeffs(self):
      # Integration test for converting 2d SDE with constant coeffs to a
      # backward Kolmogorov PDE and solving it.
      # The SDE is:
      # dS_x = (dW_1 + dW_2) / sqrt(2)
      # dS_y = (dW_1 + dW_2) / sqrt(2)
      # It is of course trivial, but we'll solve it the hard way for the sake of
      # testing.
      # The Kolmogorov backwards PDE is:
      # u_{t} + D u_{xx} / 2 +  D u_{yy} / 2 + D u_{xy} = 0
      # The equation can be rewritten as `u_{t} + D u_{zz} = 0`, where
      # z = (x + y) / sqrt(2).
      #  If the final condition is a gaussian centered at (0, 0) with variance
      #  sigma, then the solution is:
      # `u(x, y, t) = gaussian((x + y)/sqrt(2), sigma + 2D(t_final - t)) *
      # gaussian((x - y)/sqrt(2), sigma)`.
  
      def vol_fn(t, grid):
          del t
          xs = grid[..., 1]
          vol_elem = tf.ones_like(xs) / np.sqrt(
              2
          )  # all 4 elements are equal.
          return tf.stack(
              (
                  tf.stack((vol_elem, vol_elem), axis=-1),
                  tf.stack((vol_elem, vol_elem), axis=-1),
              ),
              axis=-1,
          )
  
      drift_fn = lambda t, grid: tf.zeros(grid.shape)
  
      process = tff.models.GenericItoProcess(
          dim=2,
          volatility_fn=vol_fn,
          drift_fn=drift_fn,
          dtype=tf.float32,
      )
  
      grid = tff.math.pde.grids.uniform_grid(
          minimums=[-10, -20],
          maximums=[10, 20],
          sizes=[201, 301],
          dtype=tf.float32,
      )
      ys = self.evaluate(grid[0])
      xs = self.evaluate(grid[1])
  
      diff_coeff = 1
      time_step = 0.1
      final_t = 3
      final_variance = 1
      variance_along_diagonal = (
          final_variance + 2 * diff_coeff * final_t
      )
  
      def expected_fn(x, y):
          return _gaussian(
              (x + y) / np.sqrt(2), variance_along_diagonal
          ) * _gaussian((x - y) / np.sqrt(2), final_variance)
  
      expected = np.array([[expected_fn(x, y) for x in xs] for y in ys])
  
      final_values = tf.expand_dims(
          tf.constant(
              np.outer(
                  _gaussian(ys, final_variance),
                  _gaussian(xs, final_variance),
              ),
              dtype=tf.float32,
          ),
          axis=0,
      )
  
      result = self.evaluate(
          process.fd_solver_backward(
              start_time=final_t,
              end_time=0,
              coord_grid=grid,
              values_grid=final_values,
              time_step=time_step,
              dtype=tf.float32,
          )[0]
      )
  
      self.assertLess(
          np.max(np.abs(result - expected)) / np.max(expected), 0.01
      )
  
imports: import os
  from unittest import mock
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 11 for calling the GenericItoProcessTest obj's underlying member method code with example usage: obj.test_solving_backward_pde_for_sde_with_const_coeffs() and returns: tf, unknown