class_docstr: Records all computations done with a function in a file at output_path.
  Writes into the file the index of each apply node and sha256 digests of the
  numpy ndarrays it receives as inputs and produces as output.
  
  Example:
     # We use RecordMode to test that the computation of a function is
     identical. Create a Record object and use it to initialize a
     RecordMode object.
     output = cStringIO.StringIO()
     record = Record(file_object=output, replay=False)
     record_mode = RecordMode(record)
  
     # Then compile and call the function you wish to test, which uses
     # Apply nodes with record_mode as first parameter to record all the
     # computations to file. For example, call a Theano function with the
     # RecordMode object.
     x = theano.tensor.dscalar()
     f = theano.function([x], 2*x, mode=record_mode)
     print f(4)
  
     # Create another RecordMode object and initialize it with the previous
     # record.
     output = cStringIO.StringIO(output.getvalue())
     playback = Record(file_object=output, replay=True)
     playback_mode = RecordMode(playback)
  
     # Compile and call the function to test again with record_mode as
     # first parameter. An exception will be thrown if the recorded
     # computations are not identical between the two runs.
     x = theano.tensor.dscalar()
     f = theano.function([x], 2*x, mode=playback_mode)
     print f(4)
class_docstr_tok: ["Records","all","computations","done","with","a","function","in","a","file","at","output_path",".","Writes","into","the","file","the","index","of","each","apply","node","and","sha256","digests","of","the","numpy","ndarrays","it","receives","as","inputs","and","produces","as","output",".","Example",":","#","We","use","RecordMode","to","test","that","the","computation","of","a","function","is","identical",".","Create","a","Record","object","and","use","it","to","initialize","a","RecordMode","object",".","output","=","cStringIO.StringIO","(",")","record","=","Record","(","file_object=output",",","replay=False",")","record_mode","=","RecordMode","(","record",")","#","Then","compile","and","call","the","function","you","wish","to","test",",","which","uses","#","Apply","nodes","with","record_mode","as","first","parameter","to","record","all","the","#","computations","to","file",".","For","example",",","call","a","Theano","function","with","the","#","RecordMode","object",".","x","=","theano.tensor.dscalar","(",")","f","=","theano.function","(","[","x","]",",","2","*","x",",","mode=record_mode",")","print","f","(","4",")","#","Create","another","RecordMode","object","and","initialize","it","with","the","previous","#","record",".","output","=","cStringIO.StringIO","(","output.getvalue","(",")",")","playback","=","Record","(","file_object=output",",","replay=True",")","playback_mode","=","RecordMode","(","playback",")","#","Compile","and","call","the","function","to","test","again","with","record_mode","as","#","first","parameter",".","An","exception","will","be","thrown","if","the","recorded","#","computations","are","not","identical","between","the","two","runs",".","x","=","theano.tensor.dscalar","(",")","f","=","theano.function","(","[","x","]",",","2","*","x",",","mode=playback_mode",")","print","f","(","4",")"]
docstr: Takes either a Record object or the keyword arguments to make one.
  
  Parameters
  ----------
  record : Record
      The existing Record object to use.
  kwargs : pointer?
      Keyword arguments to construct new object.
docstr_tok: ["Takes","either","a","Record","object","or","the","keyword","arguments","to","make","one",".","Parameters","--","--","--","--","--","record",":","Record","The","existing","Record","object","to","use",".","kwargs",":","pointer","?","Keyword","arguments","to","construct","new","object","."]
code: def __init__(self, record=None, **kwargs):
      """
      Takes either a Record object or the keyword arguments to make one.
  
      Parameters
      ----------
      record : Record
          The existing Record object to use.
      kwargs : pointer?
          Keyword arguments to construct new object.
      """
  
      if record is None:
          record = Record(**kwargs)
      else:
          assert len(kwargs.keys()) == 0
  
      self.set_record(record)
  
      def handle_line(line, i, node, fn):
          """
          Records new node computation.
  
          Parameters
          ----------
          line : string
              Line to record. For example, the function name or node name.
          i : integer
              Node number in the toposort order.
          node : Apply,
              The Apply node which created the entry.
          fn : Function,
              Function related to Apply node.
          """
          try:
              self.record.handle_line(line)
          except MismatchError as e:
              print("Got this MismatchError:")
              print(e)
              print("while processing node i=" + str(i) + ":")
              print("str(node):", str(node))
              print("Symbolic inputs: ")
              for elem in node.inputs:
                  print(theano.printing.min_informative_str(elem))
              print("str(output) of outputs: ")
              for elem in fn.outputs:
                  assert isinstance(elem, list)
                  (elem,) = elem
                  print(str(elem))
              print("function name: " + node.fgraph.name)
              raise MismatchError(
                  "Non-determinism detected by WrapLinker"
              )
  
      def callback(i, node, fn):
          """
          Function called by Apply nodes at the end of each computation?
          """
  
          fgraph = node.fgraph
  
          if fgraph.name is None:
              raise ValueError(
                  "Un-named functions are not allowed with RecordMode, "
                  "because they make it impossible to tell if the same function is "
                  "running during the playback."
              )
  
          if fgraph not in self.known_fgraphs:
              assert not any(
                  [
                      elem.name == fgraph.name
                      for elem in self.known_fgraphs
                  ]
              )
              self.known_fgraphs.add(fgraph)
              num_app = len(fgraph.apply_nodes)
              line = (
                  "Function "
                  + fgraph.name
                  + " has "
                  + str(num_app)
                  + " apply nodes.\n"
              )
              handle_line(line, i, node, fn)
  
          line = "Function name: " + fgraph.name + "\n"
          handle_line(line, i, node, fn)
          line = "Node " + str(i) + ":" + str(node) + "\n"
          handle_line(line, i, node, fn)
          assert all(
              [isinstance(x, list) and len(x) == 1 for x in fn.inputs]
          )
  
          def digest(x):
              x = x[0]
              return hex_digest(x)
  
          inputs_digest = " ".join([digest(x) for x in fn.inputs])
          line = "Inputs: " + inputs_digest + "\n"
          handle_line(line, i, node, fn)
          fn()
          outputs_digest = " ".join([digest(x) for x in fn.outputs])
          line = "Outputs: " + outputs_digest + "\n"
          handle_line(line, i, node, fn)
  
      # linker = theano.gof.OpWiseCLinker()
      linker = theano.gof.vm.VM_Linker(
          use_cloop=bool(theano.config.cxx)
      )
  
      wrap_linker = theano.gof.WrapLinkerMany([linker], [callback])
      super(RecordMode, self).__init__(
          wrap_linker, optimizer="fast_run"
      )
  
file_path: Theano/theano/tests/record.py
imports: from __future__ import absolute_import, print_function, division
  from theano.compile import Mode
  import theano
  from theano.printing import hex_digest
label_desc: Use image node_id 2 to create a new RecordMode object from inherited base classes: Mode with example: obj = RecordMode(record)