code: def test_disconnected_cost_grad():
      # Tests that if we say the cost is disconnected via the
      # known_grads mechanism, it is treated as such by the rest of the
      # system.
      # This is so that Ops that are built around minigraphs like OpFromGraph
      # and scan can implement Op.grad by passing ograds to known_grads
  
      x = theano.tensor.iscalar()
      y = theano.tensor.iscalar()
      cost = x + y
      assert cost.dtype in theano.tensor.discrete_dtypes
      try:
          theano.tensor.grad(
              cost,
              [x, y],
              known_grads={cost: gradient.DisconnectedType()()},
              disconnected_inputs="raise",
          )
      except theano.gradient.DisconnectedInputError:
          return
      raise AssertionError("A disconnected gradient has been ignored.")
  
imports: from __future__ import absolute_import, print_function, division
  from collections import OrderedDict
  import unittest
  import numpy
  from six.moves import xrange
  import theano
  from theano import gof, change_flags
  from theano.compat import izip
  from theano.tests import unittest_tools
  from theano import gradient
  from theano import config
  from theano.gof.null_type import NullType
  from theano.sandbox.rng_mrg import MRG_RandomStreams
label_desc: Use image node_id 6 for calling a global function with example usage: test_disconnected_cost_grad() without return types