对保管器(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需要一种简单的方法来创建用于排序的comparator类   java getReadableDatabase和getWriteableDatabase无法解析   查找列表<Long>中与某个元素对应的所有索引的java方法   安卓将视图添加到ViewFlipper会导致java。StackOverflowerr语言   java根据它所包含的长“curTime”类字段将N的列表拆分为24(小时)   Android N中的Java8流API   自动生成Java策略文件的安全性   垃圾收集鼓励Java中的主要GC(但不是STW GC)   java如何检查UDP服务器上侦听的客户端数量   在前一台主机被Datastax Java驱动程序关闭后,Cassandra尝试重新连接到下一台主机   java如何使用Spring Boot创建部分代理   java是否有一个网站或资源可以完全比较EJB版本   java无需使用第三方库从gradle生成输出   继承由于这个多态性的基本示例中的语法有什么不同吗?(爪哇)   java字符串数组中的空字符串   java为什么CMS中的初始标记阶段是串行的   为什么Lucene有时与InChIKeys不匹配?   安卓通知Java应用程序数据库中的更改   java如何将单个json对象值解析为按钮   java打印堆栈将运行时错误跟踪到文件