对保管器(github.com/materialsproject/保管器)中的保管器类进行修改,以允许通过ssh将temp_dir复制到其他计算节点。

SSHCustodian的Python项目详细描述


这个模块依赖于custodian project中的托管类,它是一个包装 管理计算群集上运行的作业。托管模块是 The Materials Project

此模块通过创建子类sshcustodian扩展托管类, 它添加了复制通过monty创建的临时目录的功能。 到从属计算节点上的scratch分区,前提是 文件系统是这样配置的。实现调用子流程 利用集群上安装的ssh可执行文件,因此 特别优雅或独立于平台,这种解决方案也不太可能是 所有集群通用。这就是为什么没有提交此修改 作为对主托管项目的请求。

您使用sshcustodian的方式与托管类相同,它应该 与现有脚本集成。sshcustdiane类需要两个 创建新实例时的其他参数,scratch_dir_node_only 以及pbs_nodefile

scratch_dir_node_only (bool): If set to True, custodian will grab the list
    of nodes in the file path provided to pbs_nodefile and use copy the
    temp_dir to the scratch_dir on each node over ssh. This is necessary on
    cluster setups where each node has its own independent scratch
    partition.

pbs_nodefile (str): The filepath to the list of nodes to be used in a
    calculation. If this path does not point to a valid file, then
    scratch_dir_node_only will be automatically set to False.

还创建了sshvaspjob子类,该子类重写setup方法以 还要在auto_npar = True时检查环境变量PBS_NUM_PPN。这对于使用compute node scratch实现是必要的 基于pbs的排队系统上的分区,作为使用 multiprocessing.cpu_count()要计算核心数将包括 超线程,它会高估物理核心的数量并导致 NPAR设置得太大。设置过高的一个后果是 vasp作业将挂起,消耗资源,但不做任何有用的事情。如果你 使用这种划痕目录时,要小心设置NPAR。

在许多集群中,计算节点列表的文件路径位于 环境变量PBS_NODEFILE,可以在bash中作为 $PBS_NODEFILE,在python中使用os模块。一个例子 如何在脚本中使用sshcustedian如下:

import logging
import os
from sshcustodian.sshcustodian import SSHCustodian
from custodian.vasp.handlers import (VaspErrorHandler,
                                     UnconvergedErrorHandler,
                                     MeshSymmetryErrorHandler,
                                     NonConvergingErrorHandler,
                                     PotimErrorHandler)
from custodian.vasp.validators import VasprunXMLValidator
from sshcustodian.vasp.sshjobs import SSHVaspJob
from pymatgen.io.vasp import VaspInput

FORMAT = '%(asctime)s %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO, filename="run.log")

class VaspInputArgs:
    def __init__(self):
        """
        Set the default values for running a VASP job.
        """
        self.static_kpoint = 1

    def import_dict(self, in_dict):
        """
        Create and update self variables using dictionary.
        """
        for (key, value) in iteritems(in_dict):
            if key == "command":
                self.command = value
            if key == "static_kpoint":
                self.static_kpoint = value
            if key == "jobs":
                self.jobs = value


def get_runs(args):
    vasp_command = args.command.split()
    njobs = len(args.jobs)
    for i, job in enumerate(args.jobs):
        final = False if i != njobs - 1 else True
        if any(c.isdigit() for c in job):
            suffix = "." + job
        else:
            suffix = ".{}{}".format(job, i + 1)
        settings = []
        backup = True if i == 0 else False
        copy_magmom = False
        vinput = VaspInput.from_directory(".")
        if i > 0:
            settings.append(
                {"file": "CONTCAR",
                 "action": {"_file_copy": {"dest": "POSCAR"}}})
        job_type = job.lower()
        auto_npar = True
        if job_type.startswith("static"):
            m = [i * args.static_kpoint for i in vinput["KPOINTS"].kpts[0]]
            settings.extend([
                {"dict": "INCAR",
                 "action": {"_set": {"NSW": 0}}},
                {'dict': 'KPOINTS',
                 'action': {'_set': {'kpoints': [m]}}}])

        yield SSHVaspJob(vasp_command, final=final, suffix=suffix,
                         backup=backup, settings_override=settings,
                         copy_magmom=copy_magmom, auto_npar=auto_npar)


logging.info("Handlers used are %s" % args.handlers)
scratch_root = os.path.abspath("/scratch")
pbs_nodefile = os.environ.get("PBS_NODEFILE")
job_args = VaspInputArgs()
job_dict = {"command": "pvasp",
            "jobs": ["static"]}
job_args.import_dict(job_dict)
handlers = [VaspErrorHandler(), MeshSymmetryErrorHandler(),
            UnconvergedErrorHandler(), NonConvergingErrorHandler(),
            PotimErrorHandler()]
validators = [VasprunXMLValidator()]
c = SSHCustodian(handlers, get_runs(job_args), validators,
                 checkpoint=True,
                 scratch_dir=scratch_root,
                 scratch_dir_node_only=True,
                 pbs_nodefile=pbs_nodefile)
c.run()

请注意,根据集群的配置方式,需要将"command": "pvasp"更改为调用并行作业的方式。

有关如何使用保管器的更多信息,请参阅custodian project documentation

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java子类在构造函数中少取1个参数   arraylist在java中使用堆栈将对象添加到数组列表中   java如何使用扫描仪或缓冲读取器读取输入文件,并统计输入文件中出现的所有特定字符   java围绕其中心逆时针旋转2D数组,同时保持数组大小   java输入后,println不会输出任何内容   java未知HK2故障多重异常   SimplePath中字段的java Querydsl 4 StringExpression   循环遍历java代码中的多个集合   socket inputstream在使用BOX java sdk时损坏   java什么是面颊新闻活动?   列出比较多个整数并查找java中的最大整数   用户权限如何获得在java中Windows vista/7的C驱动器中打开目录的管理权限   范围内最大/最小值的java数据结构   文件如何使用Java下载和解压缩zip存档?   JavaSpring动态原型bean   类似于云浏览的java应用程序   java无法联系localhost:8005。关闭Tomcat时,Tomcat可能未运行错误