예제 #1
0
def main_init(args):
    """Initialize a FlowProject from a template.

    The available templates are defined in the template module.
    """
    if not args.alias.isidentifier():
        raise ValueError(
            "The alias '{}' is not a valid Python identifier and can therefore "
            "not be used as a FlowProject alias.".format(args.alias)
        )
    try:
        get_project()
    except LookupError:
        init_project(name=args.alias)
        print(
            "Initialized signac project with name '{}' in "
            "current directory.".format(args.alias),
            file=sys.stderr,
        )
    try:
        return template.init(alias=args.alias, template=args.template)
    except OSError as error:
        raise RuntimeError(
            f"Error occurred while trying to initialize a flow project: {error}"
        )
예제 #2
0
def main():
    project = signac.init_project("rpa", workspace="workspace")

    for N in range(76, 96 + 2, 2):
        for T in (0.0, 0.5, 1.0, 2.0):
            statepoint = dict(
                # atomic number Z
                proton_number=50,  # fixed atomic number
                # neutron number N
                neutron_number=N,
                # nucleus angular momentum
                angular_momentum=1,  #
                # nucleus parity
                parity="-",  #
                # system temperature in MeV
                temperature=T,
                # transition energy in MeV
                transition_energy=0.42,  # 0.42 is random
            )
            project.open_job(statepoint).init()

    for job in project:
        nprot = job.sp.proton_number
        nneutr = job.sp.neutron_number
        nucleus = util.get_nucleus(proton_number=nprot, neutron_number=nneutr)
        job.doc.setdefault("nucleus", nucleus)
예제 #3
0
    def test_sync_merge(self):
        project_b = signac.init_project("ProjectB",
                                        os.path.join(self.tmpdir.name, "b"))
        self.call("python -m signac init ProjectA".split())
        project_a = signac.Project()
        for i in range(4):
            project_a.open_job({"a": i}).init()
            project_b.open_job({"a": i}).init()
        project_a.open_job({"c": 1}).init()
        project_b.open_job({"b": 1}).init()
        project_b.open_job({"a": 4}).init()
        assert len(project_a) == 5
        assert len(project_b) == 6

        # sync with projects having diffent schema
        with pytest.raises(ExitCodeError):
            self.call("python -m signac sync {} {}".format(
                os.path.join(self.tmpdir.name, "b"), self.tmpdir.name).split())
        assert len(project_a) == 5
        assert len(project_b) == 6

        self.call("python -m signac sync {} {} --merge".format(
            os.path.join(self.tmpdir.name, "b"), self.tmpdir.name).split())
        assert len(project_a) == 7
        assert len(project_b) == 6
예제 #4
0
def main(args, random_seed):
    project = signac.init_project('MyProject')
    statepoints_init = []
    for replication_index in range(args.num_replicas):
        for p in np.linspace(0.5, 5.0, 10):
            statepoint = dict(
                # system size
                N=512,

                # Lennard-Jones potential parameters
                sigma=1.0,
                epsilon=1.0,
                r_cut=2.5,

                # random seed
                seed=random_seed * (replication_index + 1),

                # thermal energy
                kT=1.0,
                # presure
                p=p,
                # thermostat coupling constant
                tau=1.0,
                # barostat coupling constant
                tauP=1.0)
            project.open_job(statepoint).init()
            statepoints_init.append(statepoint)

    # Writing statepoints to hash table as backup
    project.write_statepoints(statepoints_init)
예제 #5
0
def model_experiments_finished(job: signac.Project.Job, key="succeeded"):
    if not model_experiments_needed(job):
        return False

    for featureJob, splitJob, feature_graph_name, feature_graph_files in feature_split_iter(job):
        if re.search(get_exp_regex(job), feature_graph_name) is None:
            continue
        elif splitJob not in utils.signac_tools.getSplitProject(featureJob).find_jobs(
                task_args.split_filter, task_args.split_doc_filter):
            continue
        md5_str = "_".join(map(lambda x: calculate_md5(
            splitJob.fn(x)), feature_graph_files))

        exp_args_list = task_args.model_args or splitJob.doc.get(
            expCode, default=[])
        if exp_args_list == [] and is_tuning():
            exp_args_list = [""]
        for args in exp_args_list:
            if task_args.arg_regex is not None and re.search(task_args.arg_regex, args) is None:
                continue
            dataset_dir = splitJob.workspace()
            datasetDirObj = Path(dataset_dir)

            # Workspace path
            workspaceDirObj = datasetDirObj / workspaceRoot  # type:Path
            if not (workspaceDirObj.exists() and workspaceDirObj.is_dir()):
                return False
            modelProject = signac.init_project(
                name=expProjectName, root=str(workspaceDirObj))
            run_id = "{}@{}".format(args, md5_str)
            if is_tuning():
                run_id += "[tuning]"
            if not any(map(lambda job_i: job_i.doc.get(key, False), modelProject.find_jobs(filter={"run_id": run_id}))):
                return False
    return True
예제 #6
0
def main():
    project = signac.init_project("Ideal-Gas-Example-Project")
    # sweep over 10 pressures evenly spaced between 0.5 and 5.0
    for p in np.linspace(0.5, 5.0, 10):
        statepoint = dict(
            # system size
            N=512,
            # Lennard-Jones potential parameters
            sigma=1.0,
            epsilon=1.0,
            r_cut=2.5,
            # thermal energy
            kT=1.0,
            # pressure
            p=float(p),
            # thermostat coupling constant
            tau=1.0,
            # barostat coupling constant
            tauP=1.0,
        )

        # open the job and initialize
        job = project.open_job(statepoint)

        # define run steps in the job document so that run_steps
        # can be changed without modifying the statepoint
        job.doc["run_steps"] = 5000
        print(f"initializing state point with id {job.id} and p = {job.sp.p}")
        job.init()
예제 #7
0
def init_project():

    # Initialize project
    project = signac.init_project("nvt-1x1x1nm_1-layer")

    # Define temperature
    temperature = 298.0 * u.K

    # Define number of waters in the pore
    nwater = 24

    # Run for 500 M steps
    nsteps_eq = 5000000
    nsteps_prod = 505000000

    # For reproducibility
    np.random.seed(1)

    for run in range(3):
        # Define the state point
        state_point = {
            "T": float(temperature.in_units(u.K).value),
            "nsteps": {
                "equil" : nsteps_eq,
                "prod" : nsteps_prod,
            },
            "run": run,
            "nwater" : nwater,
            "seed1" : np.random.randint(10**8),
            "seed2" : np.random.randint(10**8),
        }

        job = project.open_job(state_point)
        job.init()
예제 #8
0
def main(args, random_seed):
    project = signac.init_project('Lennard-Jones-Fluid-Example-Project')
    for replication_index in range(args.num_replicas):
        for p in np.linspace(0.5, 5.0, 10):
            statepoint = dict(
                # system size
                N=512,

                # Lennard-Jones potential parameters
                sigma=1.0,
                epsilon=1.0,
                r_cut=2.5,

                # random seed
                seed=random_seed * (replication_index + 1),

                # thermal energy
                kT=1.0,
                # presure
                p=p,
                # thermostat coupling constant
                tau=1.0,
                # barostat coupling constant
                tauP=1.0)
            project.open_job(statepoint).init()
예제 #9
0
    def test_sync_file(self):
        self.call("python -m signac init ProjectA".split())
        project_a = signac.Project()
        project_b = signac.init_project("ProjectB", os.path.join(self.tmpdir.name, "b"))
        job_src = project_a.open_job({"a": 0}).init()
        job_dst = project_b.open_job({"a": 0}).init()
        for i, job in enumerate([job_src, job_dst]):
            with open(job.fn("test"), "w") as file:
                file.write("x" * (i + 1))
        # FileSyncConflict
        with pytest.raises(ExitCodeError):
            self.call(
                "python -m signac sync {} {}".format(
                    os.path.join(self.tmpdir.name, "b"), self.tmpdir.name
                ).split()
            )
        self.call(
            "python -m signac sync {} {} --strategy never".format(
                os.path.join(self.tmpdir.name, "b"), self.tmpdir.name
            ).split()
        )
        with open(job_dst.fn("test")) as file:
            assert file.read() == "xx"

        with pytest.raises(ExitCodeError):
            self.call(
                "python -m signac sync {} {}".format(
                    os.path.join(self.tmpdir.name, "b"), self.tmpdir.name
                ).split()
            )
        self.call(
            "python -m signac sync {} {} --update".format(
                os.path.join(self.tmpdir.name, "b"), self.tmpdir.name
            ).split()
        )
예제 #10
0
    def test_clone(self):
        self.call('python -m signac init ProjectA'.split())
        project_a = signac.Project()
        project_b = signac.init_project('ProjectB',
                                        os.path.join(self.tmpdir.name, 'b'))
        job = project_a.open_job({'a': 0})
        job.init()
        assert len(project_a) == 1
        assert len(project_b) == 0

        self.call("python -m signac clone {} {}".format(
            os.path.join(self.tmpdir.name, 'b'), job.id).split())
        assert len(project_a) == 1
        assert job in project_a
        assert len(project_b) == 1
        assert job in project_b

        # cloning a job that exist at both source and destination
        err = self.call("python -m signac clone {} {}".format(
            os.path.join(self.tmpdir.name, 'b'), job.id).split(),
                        error=True)
        assert 'Destination already exists' in err
        assert len(project_a) == 1
        assert job in project_a
        assert len(project_b) == 1
        assert job in project_b

        # checking for id that does not exit at source
        with pytest.raises(ExitCodeError):
            self.call("python -m signac clone {} 9bfd29df07674bc5".format(
                os.path.join(self.tmpdir.name, 'b')).split())
        assert len(project_a) == 1
        assert len(project_b) == 1
예제 #11
0
def main(args, random_seed):
    project = signac.init_project("TerminalGroupScreeningNewWithOld")
    logging.info("Init begin: {}".format(datetime.datetime.today()))
    logging.info("Initialized project name")
    statepoints = list()
    # generate the new top and bottom monolayers
    for replication_index in range(args.num_replicas):
        for terminal_group_a in terminal_groups_A:
            for terminal_group_b in terminal_groups_new_B:
                if terminal_group_a != terminal_group_b:
                    the_statepoint = dict(
                        # Carbon backbone length
                        chainlength=17,
                        # Number of monolayer chains
                        n=100,
                        # Random seed
                        seed=random_seed * (replication_index + 1),
                        # Terminal group chemistries
                        terminal_groups=tuple(
                            sorted((terminal_group_a, terminal_group_b))))
                project.open_job(statepoint=the_statepoint).init()
                statepoints.append(the_statepoint)
                logging.info(
                    msg="At the statepoint: {}".format(the_statepoint))
    # write statepoints to signac statepoint file
    project.write_statepoints(statepoints=statepoints)
예제 #12
0
 def test_import_sync(self):
     project_b = signac.init_project("ProjectB",
                                     os.path.join(self.tmpdir.name, "b"))
     self.call("python -m signac init ProjectA".split())
     prefix_data = os.path.join(self.tmpdir.name, "data")
     project_a = signac.Project()
     for i in range(4):
         project_a.open_job({"a": i}).init()
         project_b.open_job({"a": i}).init()
     job_dst = project_a.open_job({"a": 0})
     job_src = project_b.open_job({"a": 0})
     job_src.document["a"] = 0
     project_b.export_to(prefix_data)
     err = self.call(f"python -m signac import {prefix_data}".split(),
                     error=True)
     assert "Import failed" in err
     self.call(f"python -m signac import {prefix_data} --sync".split(),
               error=True)
     assert len(project_a) == 4
     assert "a" in job_dst.document
     assert job_dst.document["a"] == 0
     out = self.call(
         f"python -m signac import {prefix_data} --sync-interactive",
         "print(str(tmp_project), len(tmp_project)); exit()",
         shell=True,
     )
     assert "ProjectA" in out
     assert "4" in out
예제 #13
0
def main(args):
    project = signac.init_project('oak_ridge_ray')
    statepoints_init = []
    temperatures = [283, 288, 293, 298, 303, 308, 313, 318, 323, 328, 333]
    cations = ['EMIM', 'BMIM', 'HMIM']
    for cation in cations:
        for temp in temperatures:
            if cation == 'EMIM':
                for conc in ES_conc:
                    statepoint = dict(cation=cation,
                                      T=temp,
                                      concIL=float(conc[0]),
                                      concACN=float(conc[1]))
                    project.open_job(statepoint).init()
                    statepoints_init.append(statepoint)
            if cation == 'BMIM':
                for conc in BS_conc:
                    statepoint = dict(cation=cation,
                                      T=temp,
                                      concIL=float(conc[0]),
                                      concACN=float(conc[1]))
                    project.open_job(statepoint).init()
                    statepoints_init.append(statepoint)
            if cation == 'HMIM':
                for conc in HS_conc:
                    statepoint = dict(cation=cation,
                                      T=temp,
                                      concIL=float(conc[0]),
                                      concACN=float(conc[1]))
                    project.open_job(statepoint).init()
                    statepoints_init.append(statepoint)
    # Writing statepoints to hash table as a backup
    project.write_statepoints(statepoints_init)
예제 #14
0
 def test_import_sync(self):
     project_b = signac.init_project('ProjectB',
                                     os.path.join(self.tmpdir.name, 'b'))
     self.call('python -m signac init ProjectA'.split())
     prefix_data = os.path.join(self.tmpdir.name, 'data')
     project_a = signac.Project()
     for i in range(4):
         project_a.open_job({'a': i}).init()
         project_b.open_job({'a': i}).init()
     job_dst = project_a.open_job({'a': 0})
     job_src = project_b.open_job({'a': 0})
     job_src.document['a'] = 0
     project_b.export_to(prefix_data)
     err = self.call(
         "python -m signac import {}".format(prefix_data).split(),
         error=True)
     assert "Import failed" in err
     self.call(
         "python -m signac import {} --sync".format(prefix_data).split(),
         error=True)
     assert len(project_a) == 4
     assert 'a' in job_dst.document
     assert job_dst.document['a'] == 0
     out = self.call('python -m signac import {} --sync-interactive'.format(
         prefix_data),
                     'print(str(tmp_project), len(tmp_project)); exit()',
                     shell=True)
     assert 'ProjectA' in out
     assert '4' in out
예제 #15
0
def main():
    project = signac.init_project("project")
    param_names, param_combinations = get_parameters()
    # Create the generate jobs
    for params in param_combinations:
        parent_statepoint = dict(zip(param_names, params))
        parent_job = project.open_job(parent_statepoint)
        parent_job.init()
        try:
            parent_job.doc.setdefault("steps", parent_statepoint["n_steps"])
        except:
            parent_job.doc.setdefault(
                "steps", np.sum(parent_statepoint["anneal_sequence"]))
            parent_job.doc.setdefault("step_sequence",
                                      parent_statepoint["anneal_sequence"])
        if parent_job.sp['signac_args'] is not [None]:
            parent_job.doc.setdefault("use_signac", True)
            parent_job.doc.setdefault("slab_files",
                                      parent_job.sp['signac_args'])
        elif parent_job.sp['slab_file'] is not [None]:
            parent_job.doc.setdefault("use_signac", False)
            parent_job.doc.setdefault("slab_files", parent_job.sp['slab_file'])

    if custom_job_doc:
        for key in custom_job_doc:
            parent_job.doc.setdefault(key, custom_job_doc[key])

    project.write_statepoints()
예제 #16
0
def init_project():

    # Initialize project
    project = signac.init_project("a1x1x1nm_1-layer")

    # Define temperature
    temperature = 298.0 * u.K
    # Define chemical potentials
    mus = [
        -43.0 * u.kJ / u.mol,
        -42.0 * u.kJ / u.mol,
    ]

    # Run for 300 M steps
    nsteps_gcmc = 300000000

    # For reproducibility
    np.random.seed(9597)

    for mu in mus:
        for run in range(3):
            # Define the state point
            state_point = {
                "T": float(temperature.in_units(u.K).value),
                "mu": float(mu.in_units(u.kJ / u.mol).value),
                "nsteps_gcmc": nsteps_gcmc,
                "seed1": np.random.randint(10**8),
                "seed2": np.random.randint(10**8),
                "run": run,
            }

            job = project.open_job(state_point)
            job.init()
예제 #17
0
def main(args, random_seed):
    project = signac.init_project('TerminalGroupScreeningMixed')
    statepoints = []
    for replication_index in range(args.num_replicas):
        for terminal_group_a in terminal_groups_a:
            for terminal_group_b in terminal_groups_b:
                if terminal_group_a != terminal_group_b:
                    statepoint = dict(
                        # Carbon backbone length
                        chainlength=17,
                        # Number of monolayer chains
                        n=100,
                        # Random seed
                        seed=random_seed * (replication_index + 1),
                        # Terminal group chemistries
                        terminal_groups=tuple(
                            sorted((terminal_group_a, terminal_group_b))))
                    project.open_job(statepoint).init()
                    statepoints.append(statepoint)
    '''
    ------------------------------------------
    Writing statpoints to hash table as backup
    ------------------------------------------
    '''
    project.write_statepoints(statepoints)
예제 #18
0
def make_project(alias="project", root=None, **kwargs):
    r"""Initialize a project for testing.

    The initialized project has a few operations and a few jobs that are in
    various points in the workflow defined by the project.

    Parameters
    ----------
    alias : str
        Python identifier used as a file name for the template output.
        (Default value = ``"project"``)
    root : str
        Directory where the output file is placed. Uses the current working
        directory if None. (Default value = None)
    \*\*kwargs
        Keyword arguments forwarded to :meth:`signac.testing.init_jobs`.

    Returns
    -------
    :class:`signac.Project`
        Project with initialized jobs.

    """
    init(alias=alias, root=root, template="testing")
    project = signac.init_project(name=alias, root=root)
    signac.testing.init_jobs(project, **kwargs)
    return project
예제 #19
0
    def test_sync_merge(self):
        project_b = signac.init_project('ProjectB',
                                        os.path.join(self.tmpdir.name, 'b'))
        self.call('python -m signac init ProjectA'.split())
        project_a = signac.Project()
        for i in range(4):
            project_a.open_job({'a': i}).init()
            project_b.open_job({'a': i}).init()
        project_a.open_job({'c': 1}).init()
        project_b.open_job({'b': 1}).init()
        project_b.open_job({'a': 4}).init()
        assert len(project_a) == 5
        assert len(project_b) == 6

        # sync with projects having diffent schema
        with pytest.raises(ExitCodeError):
            self.call('python -m signac sync {} {}'.format(
                os.path.join(self.tmpdir.name, 'b'), self.tmpdir.name).split())
        assert len(project_a) == 5
        assert len(project_b) == 6

        self.call('python -m signac sync {} {} --merge'.format(
            os.path.join(self.tmpdir.name, 'b'), self.tmpdir.name).split())
        assert len(project_a) == 7
        assert len(project_b) == 6
예제 #20
0
def init_project():

    # Initialize project
    project = signac.init_project("gromacs_nvt1x1x1-1nm_1-layer")

    # Define temperature
    temperature = 298.0 * u.K

    # Start with a few different number of waters in the pore
    nwaters = [1, 23, 24]

    for nwater in nwaters:
        if nwater == 1:
            nsteps = 100000000
        else:
            nsteps = 50000000
        # Define the state point
        state_point = {
            "T": float(temperature.in_units(u.K).value),
            "nwater": nwater,
            "nsteps": nsteps,
        }

        job = project.open_job(state_point)
        job.init()
예제 #21
0
    def test_move(self):
        self.call('python -m signac init ProjectA'.split())
        project_a = signac.Project()
        project_b = signac.init_project('ProjectB',
                                        os.path.join(self.tmpdir.name, 'b'))
        job = project_a.open_job({'a': 0})
        job.init()
        assert len(project_a) == 1
        assert len(project_b) == 0

        self.call("python -m signac move {} {}".format(
            os.path.join(self.tmpdir.name, 'b'), job.id).split())
        assert len(project_a) == 0
        assert job not in project_a
        assert len(project_b) == 1
        assert job in project_b

        # moving a job that already exists at destination
        project_a.open_job({'a': 0}).init()
        err = self.call("python -m signac move {} {}".format(
            os.path.join(self.tmpdir.name, 'b'), job.id).split(),
                        error=True)
        assert 'Destination already exists' in err
        assert len(project_a) == 1
        assert job in project_a
        assert len(project_b) == 1
        assert job in project_b

        # moving a job that does not exits
        with pytest.raises(ExitCodeError):
            self.call("python -m signac move {} 9bfd29df07674bc5".format(
                os.path.join(self.tmpdir.name, 'b')).split())
        assert len(project_a) == 1
        assert len(project_b) == 1
예제 #22
0
def main():
    talys_proj = signac.init_project("talys", workspace="workspace")
    logger.info("talys project: %s" % talys_proj.workspace())

    rpa_proj = signac.get_project(root="../rpa/")
    logger.info("rpa project: %s" % rpa_proj.workspace())

    for psf, jobs in rpa_proj.find_jobs({
            "proton_number": 50
    }).groupbydoc("photon_strength_function"):
        for rpa_job in jobs:
            logger.info(f"Processing %s.." % rpa_job.workspace())
            sp = rpa_proj.open_job(id=rpa_job.id).statepoint()

            for yn in "y", "n":
                sp.update(
                    dict(
                        # flag for calculation of astrophysics reaction rate
                        astro=yn))
                talys_job = talys_proj.open_job(sp).init()

                util.copy_file(source=rpa_job.fn(psf),
                               destination=talys_job.fn(psf))
                talys_job.doc.setdefault("photon_strength_function", psf)

                talys_api.energy_file(talys_job)
                talys_api.input_file(talys_job)
예제 #23
0
def getSplitProject(featureJob: signac.Project.Job):
    try:
        splitProject = signac.get_project(root=featureJob.workspace(),
                                          search=False)
    except LookupError:
        splitProject = signac.init_project("SyntheticExperimentSplits",
                                           root=featureJob.workspace(),
                                           workspace="splits")
    return splitProject
예제 #24
0
def getFeatureProject(graphJob: signac.Project.Job):
    try:
        featureProject = signac.get_project(root=graphJob.workspace(),
                                            search=False)
    except LookupError:
        featureProject = signac.init_project("SyntheticExperimentFeatures",
                                             root=graphJob.workspace(),
                                             workspace="features")
    return featureProject
예제 #25
0
def setup_random_project(N, num_keys=1, num_doc_keys=0,
                         data_size=0, data_std=0, seed=0, root=None):
    random.seed(seed)
    if not isinstance(N, int):
        raise TypeError("N must be an integer!")

    with TemporaryDirectory(dir=root) as tmp:
        project = signac.init_project('benchmark-N={}'.format(N), root=tmp)
        generate_random_data(project, N, num_keys, num_doc_keys, data_size, data_std)
        yield project
예제 #26
0
def main(args):
    project = signac.init_project('Alkanes')
    for seed in range(args.num_replicas):
        for C_n in [6, 8, 10]:
            statepoint = dict(
                # length of alkane
                C_n=C_n,
                # random seed
                seed=seed)
            project.open_job(statepoint).init()
예제 #27
0
def make_project(alias='project', root=None, **kwargs):
    """Initialize a project for testing.

    The initialized project has a few operations and a few jobs that are in
    various points in the workflow defined by the project.
    """
    init(alias=alias, root=root, template='testing')
    project = signac.init_project(name=alias, root=root)
    signac.testing.init_jobs(project, **kwargs)
    return project
예제 #28
0
def main(parameters):
    project = signac.init_project(project_name)
    param_names, param_combinations = get_parameters(parameters)
    # Create the generate jobs
    for params in param_combinations:
        parent_statepoint = dict(zip(param_names, params))
        parent_job = project.open_job(parent_statepoint)
        parent_job.init()
        parent_job.doc.setdefault("steps", sum(parent_statepoint["n_steps"]))
    project.write_statepoints()
    print(f"Initialized. ({len(param_combinations)} total jobs)")
예제 #29
0
def main(args):
    """For the particles synthesized by Zhe at the Secanna group"""
    project = signac.init_project('SecannaAssembly')

    pfs = round_wrap(np.linspace(0.55, 0.60, 5, endpoint=True))
    truncations = round_wrap(np.arange(0.47, 0.84, 0.02))
    structures = ['cubicdiamond', 'hexagonaldiamond']

    sps = cartesian(pf=pfs, truncation=truncations, structure=structures)

    for sp in sps:
        project.open_job(sp).init()
예제 #30
0
def main(args):
    if not os.path.exists(PROJECT_DIR):
        os.makedirs(PROJECT_DIR)
    elif args.force:
        import shutil
        shutil.rmtree(PROJECT_DIR)
        os.makedirs(PROJECT_DIR)
    else:
        return

    p = signac.init_project(name=gen.PROJECT_NAME, root=PROJECT_DIR)
    p.import_from(origin=gen.ARCHIVE_DIR)