Esempio n. 1
0
class WorkflowLevelOptions(collections.Sized):

    ATTR_TO_ID = {
        'chunk_mode': to_workflow_option_ns('chunk_mode'),
        'max_nchunks': to_workflow_option_ns('max_nchunks'),
        'max_nproc': to_workflow_option_ns('max_nproc'),
        'total_max_nproc': to_workflow_option_ns("max_total_nproc"),
        'max_nworkers': to_workflow_option_ns('max_nworkers'),
        "distributed_mode": to_workflow_option_ns("distributed_mode"),
        "cluster_manager_path": to_workflow_option_ns("cluster_manager"),
        "tmp_dir": to_workflow_option_ns("tmp_dir"),
        "progress_status_url": to_workflow_option_ns("progress_status_url"),
        "exit_on_failure": to_workflow_option_ns("exit_on_failure")
    }

    def __init__(self, chunk_mode, max_nchunks, max_nproc, total_max_nproc,
                 max_nworkers, distributed_mode, cluster_manager_path, tmp_dir,
                 progress_status_url, exit_on_failure):
        """ Container for the known workflow options"""
        self.chunk_mode = chunk_mode
        self.max_nchunks = max_nchunks
        self.max_nproc = max_nproc
        self.total_max_nproc = total_max_nproc
        self.max_nworkers = max_nworkers
        self.distributed_mode = distributed_mode
        # This can be given as an abspath to a dir,
        # or "pbsmrtpipe.cluster_templates.sge"
        self.cluster_manager_path = cluster_manager_path
        self.tmp_dir = tmp_dir
        self.progress_status_url = progress_status_url
        self.exit_on_failure = exit_on_failure

    @staticmethod
    def from_defaults():
        return WorkflowLevelOptions.from_id_dict({})

    def __repr__(self):
        _d = dict(k=self.__class__.__name__,
                  h=self.max_nchunks,
                  n=self.max_nproc,
                  w=self.max_nworkers,
                  c=self.cluster_manager_path)
        return "<{k} chunk:{h} nproc:{n} workers:{w} cluster:{c}>".format(**_d)

    def __len__(self):
        return len(self.to_dict())

    @staticmethod
    def from_id_dict(d):
        """
        Create an instance from a id dict of options (pbsmrtpipe.options.x:value}
        """
        from pbsmrtpipe.pb_io import REGISTERED_WORKFLOW_OPTIONS
        import pbsmrtpipe.schema_opt_utils as OP

        adict = {}

        for opt_id, schema in REGISTERED_WORKFLOW_OPTIONS.iteritems():
            if opt_id in d:
                v = d[opt_id]
                OP.validate_value(schema, {opt_id: v})
                adict[opt_id] = v
            else:
                value = OP.get_default_from_schema(schema)
                d[opt_id] = value

        # build map to instance var names
        adict = {
            k: d[v]
            for k, v in WorkflowLevelOptions.ATTR_TO_ID.iteritems()
        }

        return WorkflowLevelOptions(**adict)

    def to_dict(self):
        return {v: getattr(self, k) for k, v in self.ATTR_TO_ID.iteritems()}
Esempio n. 2
0
def _to_wopt_id(s):
    """Workflow Level Options"""
    from pbsmrtpipe.constants import to_workflow_option_ns
    return to_workflow_option_ns(s)
Esempio n. 3
0
def _to_wopt_id(s):
    """Workflow Level Options"""
    from pbsmrtpipe.constants import to_workflow_option_ns

    return to_workflow_option_ns(s)