Trim DAG to keep only nodes that produce targets
186777
def subgraph_from(self, targets: sos_targets):
        ''''''
        if 'DAG' in env.config['SOS_DEBUG'] or 'ALL' in env.config['SOS_DEBUG']:
            env.log_to_file('DAG', 'create subgraph')
        # first, find all nodes with targets
        subnodes = []
        for node in self.nodes():
            if node._output_targets.valid() and any(
                    x in node._output_targets for x in targets):
                subnodes.append(node)
        #
        ancestors = set()
        for node in subnodes:
            ancestors |= nx.ancestors(self, node)
        return SoS_DAG(nx.subgraph(self, subnodes + list(ancestors)))
623929
def get_independent_nodes(dag):
    """"""
    nodes = set(dag.keys())
    dependent_nodes = set([node for downstream_nodes in dag.values() for node in downstream_nodes])
    return set(nodes - dependent_nodes)
1194012
def filtered(self, step_names):
        """"""
        return Graph(steps=self.steps, dag=self.dag.filter(step_names))
580384
def generate_dep_names(self, target: Target):
        """"""
        yield from sorted(get_descendants(self.target_graph, target.name))
1204823
def eliminate(self, node, data):
        

        # Cache resolved value
        self.eliminated[node] = data
        others = self.checks[node]
        del self.checks[node]

        # Pass messages to all associated checks
        for check in others:
            check.check ^= data
            check.src_nodes.remove(node)

            # Yield all nodes that can now be resolved
            if len(check.src_nodes) == 1:
                yield (next(iter(check.src_nodes)), check.check)
220057
function defaultUngrep(targets) {
    if (targets && targets.length) {
        var ungreps = [], target, len = targets.length;

        for (var i = 0; i < len; i++) {
            target = targets[i];
            target = '(?:^' + path.dirname(target) + sep + '){1}';
            target += '(?:/?.*/?)*' + NM_SEG;
            ungreps.push(new RegExp(escape(target)));
        }
        return ungreps;
    }
    return [new RegExp(escape(NM_SEG))];
}
357124
function removeUnnecessaryParens(node, rootNode=false) {
  // Parens that wrap everything are redundant.
  // NOTE: removeUnnecessaryParensSearch recursively removes parens that aren't
  // needed, while this step only applies to the very top level expression.
  // e.g. (2 + 3) * 4 can't become 2 + 3 * 4, but if (2 + 3) as a top level
  // expression can become 2 + 3
  if (rootNode) {
    while (Node.Type.isParenthesis(node)) {
      node = node.content;
    }
  }
  return removeUnnecessaryParensSearch(node);
}
875169
function filterPoints (data, start, end) {
  if (!end) {
    end = start
  }

  var node = start,
    again
  do {
    again = false

    if (!node.steiner && (equals(data, node.i, node.next.i) || orient(data, node.prev.i, node.i, node.next.i) === 0)) {

      // remove node
      node.prev.next = node.next
      node.next.prev = node.prev

      if (node.prevZ) {
        node.prevZ.nextZ = node.nextZ
      }
      if (node.nextZ) {
        node.nextZ.prevZ = node.prevZ
      }

      node = end = node.prev

      if (node === node.next) {
        return null
      }
      again = true

    } else {
      node = node.next
    }
  } while (again || node !== end)

  return end
}
76020
void markSuccess() {
    // It's possible that the dag is killed before this method is called.
    assertRunningOrKilling();
    changeStatus(Status.SUCCESS);
    for (final Node child : this.children) {
      child.runIfAllowed();
    }
    this.dag.updateDagStatus();
  }
371060
def frozen_default_graph_def(input_node_names, output_node_names):
  """"""

  sess = tf.get_default_session()
  input_graph_def = tf.get_default_graph().as_graph_def()

  pruned_graph = tf.graph_util.remove_training_nodes(
      input_graph_def, protected_nodes=(output_node_names + input_node_names)
  )
  pruned_graph = tf.graph_util.extract_sub_graph(pruned_graph, output_node_names)

  # remove explicit device assignments
  for node in pruned_graph.node:
      node.device = ""

  all_variable_names = [v.op.name for v in tf.global_variables()]
  output_graph_def = tf.graph_util.convert_variables_to_constants(
      sess=sess,
      input_graph_def=pruned_graph,
      output_node_names=output_node_names,
      variable_names_whitelist=all_variable_names,
  )

  return output_graph_def
813453
def remove(self, *args):
        '''
        
        '''
        return Plan(reduce(lambda m,k: m.remove(k), args, self.nodes))
92887
def prune(self, whole=False, keys=[], names=[], filters=[]):
        
        for node in self.climb(whole):
            # Select only nodes with key content
            if not all([key in node.data for key in keys]):
                continue
            # Select nodes with name matching regular expression
            if names and not any(
                    [re.search(name, node.name) for name in names]):
                continue
            # Apply advanced filters if given
            try:
                if not all([utils.filter(filter, node.data, regexp=True)
                        for filter in filters]):
                    continue
            # Handle missing attribute as if filter failed
            except utils.FilterError:
                continue
            # All criteria met, thus yield the node
            yield node
940104
def trim(self):
        """"""
        for key, value in list(iteritems(self.counters)):
            if value.empty():
                del self.counters[key]
855638
def filter_nodes(graph: BELGraph, node_predicates: NodePredicates) -> Iterable[BaseEntity]:
    """"""
    concatenated_predicate = concatenate_node_predicates(node_predicates=node_predicates)
    for node in graph:
        if concatenated_predicate(graph, node):
            yield node
425726
def static_adam_preprocessing_dag(job, inputs, sample, output_dir, suffix=''):
    
    inputs.sample = sample
    inputs.output_dir = output_dir
    inputs.suffix = suffix

    if inputs.master_ip is not None or inputs.run_local:
        if not inputs.run_local and inputs.master_ip == 'auto':
            # Static, standalone Spark cluster managed by uberscript
            spark_on_toil = False
            scale_up = job.wrapJobFn(scale_external_spark_cluster, 1)
            job.addChild(scale_up)
            spark_work = job.wrapJobFn(download_run_and_upload,
                                       inputs.master_ip, inputs, spark_on_toil)
            scale_up.addChild(spark_work)
            scale_down = job.wrapJobFn(scale_external_spark_cluster, -1)
            spark_work.addChild(scale_down)
        else:
            # Static, external Spark cluster
            spark_on_toil = False
            spark_work = job.wrapJobFn(download_run_and_upload,
                                       inputs.master_ip, inputs, spark_on_toil)
            job.addChild(spark_work)
    else:
        # Dynamic subclusters, i.e. Spark-on-Toil
        spark_on_toil = True
        cores = multiprocessing.cpu_count()
        master_ip = spawn_spark_cluster(job,
                                        False, # Sudo
                                        inputs.num_nodes-1,
                                        cores=cores,
                                        memory=inputs.memory)
        spark_work = job.wrapJobFn(download_run_and_upload,
                                   master_ip, inputs, spark_on_toil)
        job.addChild(spark_work)
1020629
def output_files(self):
        """"""
        for dep in self.subgraph.successors(self.address):
            dep_rule = self.subgraph.node[dep]['target_obj']
            for out_file in dep_rule.output_files:
                yield out_file
457140
def clean(ctx, node=False, translations=False, all=False):
    ''''''
    header('Clean all build artifacts')
    patterns = [
        'build', 'dist', 'cover', 'docs/_build',
        '**/*.pyc', '*.egg-info', '.tox', 'udata/static/*'
    ]
    if node or all:
        patterns.append('node_modules')
    if translations or all:
        patterns.append('udata/translations/*/LC_MESSAGES/udata.mo')
    for pattern in patterns:
        info(pattern)
    lrun('rm -rf {0}'.format(' '.join(patterns)))