code: def add_results(self, results, keep_provenance=False):
      if keep_provenance and results.provenance:
          self.g = deepcopy(results.provenance)
          return self.g
      runtime = results.runtime
      interface = results.interface
      inputs = results.inputs
      outputs = results.outputs
      classname = interface.__name__
      modulepath = f"{interface.__module__}.{interface.__name__}"
      activitytype = "".join(
          [i.capitalize() for i in modulepath.split(".")]
      )
  
      a0_attrs = {
          nipype_ns["module"]: interface.__module__,
          nipype_ns["interface"]: classname,
          pm.PROV["type"]: nipype_ns[activitytype],
          pm.PROV["label"]: classname,
          nipype_ns["duration"]: safe_encode(runtime.duration),
          nipype_ns["workingDirectory"]: safe_encode(runtime.cwd),
          nipype_ns["returnCode"]: safe_encode(runtime.returncode),
          nipype_ns["platform"]: safe_encode(runtime.platform),
          nipype_ns["version"]: safe_encode(runtime.version),
      }
      a0_attrs[foaf["host"]] = pm.Literal(
          runtime.hostname, pm.XSD["anyURI"]
      )
  
      try:
          a0_attrs.update(
              {nipype_ns["command"]: safe_encode(runtime.cmdline)}
          )
          a0_attrs.update(
              {
                  nipype_ns["commandPath"]: safe_encode(
                      runtime.command_path
                  )
              }
          )
          a0_attrs.update(
              {
                  nipype_ns["dependencies"]: safe_encode(
                      runtime.dependencies
                  )
              }
          )
      except AttributeError:
          pass
      a0 = self.g.activity(
          get_id(), runtime.startTime, runtime.endTime, a0_attrs
      )
      # environment
      id = get_id()
      env_collection = self.g.collection(id)
      env_collection.add_attributes(
          {
              pm.PROV["type"]: nipype_ns["Environment"],
              pm.PROV["label"]: "Environment",
          }
      )
      self.g.used(a0, id)
      # write environment entities
      for idx, (key, val) in enumerate(sorted(runtime.environ.items())):
          if key not in PROV_ENVVARS:
              continue
          in_attr = {
              pm.PROV["label"]: key,
              nipype_ns["environmentVariable"]: key,
              pm.PROV["value"]: safe_encode(val),
          }
          id = get_attr_id(in_attr)
          self.g.entity(id, in_attr)
          self.g.hadMember(env_collection, id)
      # write input entities
      if inputs:
          id = get_id()
          input_collection = self.g.collection(id)
          input_collection.add_attributes(
              {
                  pm.PROV["type"]: nipype_ns["Inputs"],
                  pm.PROV["label"]: "Inputs",
              }
          )
          # write input entities
          for idx, (key, val) in enumerate(sorted(inputs.items())):
              in_entity = prov_encode(self.g, val).identifier
              self.g.hadMember(input_collection, in_entity)
              used_attr = {
                  pm.PROV["label"]: key,
                  nipype_ns["inPort"]: key,
              }
              self.g.used(
                  activity=a0,
                  entity=in_entity,
                  other_attributes=used_attr,
              )
      # write output entities
      if outputs:
          id = get_id()
          output_collection = self.g.collection(id)
          if not isinstance(outputs, dict):
              outputs = outputs.get_traitsfree()
          output_collection.add_attributes(
              {
                  pm.PROV["type"]: nipype_ns["Outputs"],
                  pm.PROV["label"]: "Outputs",
              }
          )
          self.g.wasGeneratedBy(output_collection, a0)
          # write output entities
          for idx, (key, val) in enumerate(sorted(outputs.items())):
              out_entity = prov_encode(self.g, val).identifier
              self.g.hadMember(output_collection, out_entity)
              gen_attr = {
                  pm.PROV["label"]: key,
                  nipype_ns["outPort"]: key,
              }
              self.g.generation(
                  out_entity, activity=a0, other_attributes=gen_attr
              )
      # write runtime entities
      id = get_id()
      runtime_collection = self.g.collection(id)
      runtime_collection.add_attributes(
          {
              pm.PROV["type"]: nipype_ns["Runtime"],
              pm.PROV["label"]: "RuntimeInfo",
          }
      )
      self.g.wasGeneratedBy(runtime_collection, a0)
      for key, value in sorted(runtime.items()):
          if not value:
              continue
          if key not in ["stdout", "stderr", "merged"]:
              continue
          attr = {
              pm.PROV["label"]: key,
              nipype_ns[key]: safe_encode(value),
          }
          id = get_id()
          self.g.entity(get_id(), attr)
          self.g.hadMember(runtime_collection, id)
  
      # create agents
      user_attr = {
          pm.PROV["type"]: pm.PROV["Person"],
          pm.PROV["label"]: getpass.getuser(),
          foaf["name"]: safe_encode(getpass.getuser()),
      }
      user_agent = self.g.agent(get_attr_id(user_attr), user_attr)
      agent_attr = {
          pm.PROV["type"]: pm.PROV["SoftwareAgent"],
          pm.PROV["label"]: "Nipype",
          foaf["name"]: safe_encode("Nipype"),
          nipype_ns["version"]: __version__,
      }
      for key, value in list(get_info().items()):
          agent_attr.update({nipype_ns[key]: safe_encode(value)})
      software_agent = self.g.agent(get_attr_id(agent_attr), agent_attr)
      self.g.wasAssociatedWith(
          a0,
          user_agent,
          None,
          None,
          {pm.PROV["hadRole"]: nipype_ns["LoggedInUser"]},
      )
      self.g.wasAssociatedWith(a0, software_agent)
      return self.g
  
imports: from collections import OrderedDict
  from copy import deepcopy
  from pickle import dumps
  import os
  import getpass
  import platform
  from uuid import uuid1
  import simplejson
  import numpy
  import prov.model
  from ..None import get_info, logging, __version__
  from .filemanip import md5, hashlib, hash_infile
label_desc: Use image node_id 2 for calling the ProvStore obj's underlying member method code with example usage: obj.add_results(results, keep_provenance) and returns: self, self