Esempio n. 1
0
class ActionFactory(Action):
    def __init__(self, action: str, allowed_actions: dict):
        assert action in allowed_actions, ("unsupported action of job", action)
        super().__init__(action, allowed_actions[action])
        suffix = action.replace('-', '_')
        for attr in ["define_arguments", "check_arguments", "do_action"]:
            if hasattr(self, f"{attr}_{suffix}"):
                setattr(self, attr, getattr(self, f"{attr}_{suffix}"))
            else:
                assert attr != "do_action", f"must specify a method named {attr}_{suffix} in {self.__class__.__name__}"

        self.__job__ = Job()
        self.__clusters__ = ClusterList()
        self.enable_svaing = dict(job=False, clusters=False)

    def restore(self, args):
        if getattr(args, 'job_name', None):
            self.__job__.load(job_name=args.job_name)
        self.__clusters__.load()
        return self

    def store(self, args):
        if self.enable_svaing["job"]:
            self.__job__.save()
        if self.enable_svaing["clusters"]:
            self.__clusters__.save()
        return self
Esempio n. 2
0
class ActionFactory(Action):
    def __init__(self, action: str, allowed_actions: dict):
        assert action in allowed_actions, ("unsupported action of job", action)
        super().__init__(action, allowed_actions[action])
        suffix = action.replace('-', '_')
        self.define_arguments = getattr(self, "define_arguments_" + suffix,
                                        super().define_arguments)
        self.check_arguments = getattr(self, "check_arguments_" + suffix,
                                       super().check_arguments)
        self.do_action = getattr(self, "do_action_" + suffix, None)
        self.__job__ = Job()
        self.__clusters__ = ClusterList()
        self.disable_saving = dict()

    def restore(self, args):
        if getattr(args, 'job_name', None):
            self.__job__.load(job_name=args.job_name)
        self.__clusters__.load()
        return self

    def store(self, args):
        if not self.disable_saving.get("job", False):
            self.__job__.save()
        if not self.disable_saving.get("clusters", False):
            self.__clusters__.save()
        return self
Esempio n. 3
0
def submit_notebook(
    job: Job, cluster_alis: str, nb_file: str, image: str, workspace: str, # cluster related
    interactive_mode: bool=True, token: str="abcd", # notebook only
    gpu: int=0, cpu: int=1, memoryMB: int=10240, ports: dict={}, # resources related
    **kwargs
    ):
    job_name = os.path.splitext(os.path.basename(nb_file))[0] + "_" + randstr().hex
    job.from_notebook(nb_file, image, interactive_mode, token, gpu=gpu, cpu=cpu, memoryMB=memoryMB, ports=ports)
    job.decorate(cluster_alis, workspace)
    return job
Esempio n. 4
0
 def __init__(self, action: str, allowed_actions: dict):
     assert action in allowed_actions, ("unsupported action of job", action)
     super().__init__(action, allowed_actions[action])
     suffix = action.replace('-', '_')
     self.define_arguments = getattr(self, "define_arguments_" + suffix,
                                     super().define_arguments)
     self.check_arguments = getattr(self, "check_arguments_" + suffix,
                                    super().check_arguments)
     self.do_action = getattr(self, "do_action_" + suffix, None)
     self.__job__ = Job()
     self.__clusters__ = ClusterList()
Esempio n. 5
0
    def __init__(self, action: str, allowed_actions: dict):
        assert action in allowed_actions, ("unsupported action of job", action)
        super().__init__(action, allowed_actions[action])
        suffix = action.replace('-', '_')
        for attr in ["define_arguments", "check_arguments", "do_action"]:
            if hasattr(self, f"{attr}_{suffix}"):
                setattr(self, attr, getattr(self, f"{attr}_{suffix}"))
            else:
                assert attr != "do_action", f"must specify a method named {attr}_{suffix} in {self.__class__.__name__}"

        self.__job__ = Job()
        self.__clusters__ = ClusterList()
        self.enable_svaing = dict(job=False, clusters=False)
 def job_cfg_file(self):
     return Job.get_config_file(job_name=self.job_c["job-name"], v2=False)