code: def get_instruments(
      graph: nx.DiGraph, treatment_nodes, outcome_nodes
  ):
      treatment_nodes = parse_state(treatment_nodes)
      outcome_nodes = parse_state(outcome_nodes)
      parents_treatment = set()
      for node in treatment_nodes:
          parents_treatment = parents_treatment.union(
              set(graph.predecessors(node))
          )
      g_no_parents_treatment = do_surgery(
          graph, treatment_nodes, remove_incoming_edges=True
      )
      ancestors_outcome = set()
      for node in outcome_nodes:
          ancestors_outcome = ancestors_outcome.union(
              nx.ancestors(g_no_parents_treatment, node)
          )
      # [TODO: double check these work with multivariate implementation:]
      # Exclusion
      candidate_instruments = parents_treatment.difference(
          ancestors_outcome
      )
      _logger.debug(
          "Candidate instruments after satisfying exclusion: %s",
          candidate_instruments,
      )
      # As-if-random setup
      children_causes_outcome = [
          nx.descendants(g_no_parents_treatment, v)
          for v in ancestors_outcome
      ]
      children_causes_outcome = set(
          [
              item
              for sublist in children_causes_outcome
              for item in sublist
          ]
      )
  
      # As-if-random
      instruments = candidate_instruments.difference(
          children_causes_outcome
      )
      _logger.debug(
          "Candidate instruments after satisfying exclusion and as-if-random: %s",
          instruments,
      )
      return list(instruments)
  
imports: import itertools
  import logging
  import re
  from abc import abstractmethod
  from typing import Any, List, Protocol
  import networkx
  from networkx.algorithms.dag import has_cycle
  from dowhy.utils.api import parse_state
  from dowhy.utils.graph_operations import daggity_to_dot
label_desc: Use image node_id 13 for calling a global function with example usage: get_instruments(graph, treatment_nodes, outcome_nodes) and returns: list