Exemple #1
0
def main():
    batch_dir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # intialize the BatchLauncher.
    from pymatgen.io.abinit.launcher import BatchLauncher
    batch = BatchLauncher(workdir=batch_dir)

    # Build multiple flows and add them to the BatchLauncher.

    for paral_kgb in range(2):
        #flow_dir = os.path.join(batch.workdir, "flow_paral_kgb_%d" % paral_kgb)

        # Get the SCF and the NSCF input and build the flow.
        scf_input, nscf_input = make_scf_nscf_inputs(paral_kgb)

        # Each flow will have a unique wordir inside batch.workdir. 
        # Note that we have to pass workdir=None and use set_name to specify the dir basename
        flow = abilab.bandstructure_flow(None, scf_input, nscf_input, allocate=False)
        flow.set_name("flow_paral_kgb_%d" % paral_kgb)

        batch.add_flow(flow)

    # Submit to the queue in batch mode.
    # Use abibatch.py to inspect the status or resubmit.
    job = batch.submit()
    print("batch.submit() returned: ", job.retcode)
    return job.retcode
Exemple #2
0
def main():
    batch_dir = os.path.basename(__file__).replace(".py", "").replace(
        "run_", "flow_")

    # intialize the BatchLauncher.
    from pymatgen.io.abinit.launcher import BatchLauncher
    batch = BatchLauncher(workdir=batch_dir)

    # Build multiple flows and add them to the BatchLauncher.

    for paral_kgb in range(2):
        #flow_dir = os.path.join(batch.workdir, "flow_paral_kgb_%d" % paral_kgb)

        # Get the SCF and the NSCF input and build the flow.
        scf_input, nscf_input = make_scf_nscf_inputs(paral_kgb)

        # Each flow will have a unique wordir inside batch.workdir.
        # Note that we have to pass workdir=None and use set_name to specify the dir basename
        flow = abilab.bandstructure_flow(None,
                                         scf_input,
                                         nscf_input,
                                         allocate=False)
        flow.set_name("flow_paral_kgb_%d" % paral_kgb)

        batch.add_flow(flow)

    # Submit to the queue in batch mode.
    # Use abibatch.py to inspect the status or resubmit.
    job = batch.submit()
    print("batch.submit() returned: ", job.retcode)
    return job.retcode
Exemple #3
0
def make_electronic_structure_flow(ngkpts_for_dos=((2, 2, 2), (4, 4, 4), (6, 6, 6), (8, 8, 8))):
    """Band structure calculation."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"), ndtset=2 + len(ngkpts_for_dos))
    # Global variables
    multi.set_vars(ecut=10)

    # Dataset 1
    multi[0].set_vars(tolvrs=1e-9)
    multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0])

    # Dataset 2
    multi[1].set_vars(tolwfr=1e-15)
    multi[1].set_kpath(ndivsm=5)

    # Dataset 3
    for i, ngkpt in enumerate(ngkpts_for_dos):
        multi[2+i].set_vars(tolwfr=1e-15)
        multi[2+i].set_kmesh(ngkpt=ngkpt, shiftk=[0,0,0])

    inputs = multi.split_datasets()
    scf_input, nscf_input, dos_input = inputs[0], inputs[1], inputs[2:]

    return abilab.bandstructure_flow(workdir="flow_dos_bands", scf_input=scf_input, nscf_input=nscf_input,
                                     dos_inputs=dos_input)
Exemple #4
0
def make_electronic_structure_flow(ngkpts_for_dos=[(2, 2, 2), (4, 4, 4), (6, 6, 6), (8, 8, 8)]):
    """Band structure calculation."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"), ndtset=2 + len(ngkpts_for_dos))
    # Global variables
    multi.set_vars(ecut=10)

    # Dataset 1
    multi[0].set_vars(tolvrs=1e-9)
    multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0])

    # Dataset 2
    multi[1].set_vars(tolwfr=1e-15)
    multi[1].set_kpath(ndivsm=5)

    # Dataset 3
    for i, ngkpt in enumerate(ngkpts_for_dos):
        multi[2+i].set_vars(tolwfr=1e-15)
        multi[2+i].set_kmesh(ngkpt=ngkpt, shiftk=[0,0,0])

    inputs = multi.split_datasets()
    scf_input, nscf_input, dos_input = inputs[0], inputs[1], inputs[2:]

    return abilab.bandstructure_flow(workdir="flow_dos_bands", scf_input=scf_input, nscf_input=nscf_input,
                                     dos_inputs=dos_input)
Exemple #5
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace(
            "run_", "flow_")

    #pseudos = abidata.pseudos("12mg.pspnc", "5b.pspnc")
    structure = abidata.structure_from_ucell("MgB2")

    # Get pseudos from a table.
    table = abilab.PseudoTable(abidata.pseudos("12mg.pspnc", "5b.pspnc"))
    pseudos = table.get_pseudos_for_structure(structure)

    nval = structure.num_valence_electrons(pseudos)
    #print(nval)

    inputs = make_scf_nscf_inputs(structure, pseudos)
    scf_input, nscf_input, dos_inputs = inputs[0], inputs[1], inputs[2:]
    #print(scf_input.pseudos)

    return abilab.bandstructure_flow(workdir,
                                     scf_input,
                                     nscf_input,
                                     dos_inputs=dos_inputs,
                                     manager=options.manager)
def itest_bandstructure_schedflow(fwp, tvars):
    """
    Run a bandstructure flow with the scheduler.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="Si.GGA_PBE-JTH-paw.xml")

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, fwp.manager, scf_input, nscf_input)

    flow.build_and_pickle_dump()

    fwp.scheduler.add_flow(flow)
    print(fwp.scheduler)
    # scheduler cannot handle more than one flow.
    with pytest.raises(fwp.scheduler.Error):
        fwp.scheduler.add_flow(flow)

    fwp.scheduler.start()
    assert fwp.scheduler.num_excs == 0
    assert fwp.scheduler.nlaunch == 2

    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)
def itest_bandstructure_schedflow(fwp, tvars):
    """
    Run a bandstructure flow with the scheduler.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="Si.GGA_PBE-JTH-paw.xml")

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager)

    # Will remove output files (WFK)
    flow.set_cleanup_exts()
    flow.build_and_pickle_dump()

    fwp.scheduler.add_flow(flow)
    print(fwp.scheduler)
    # scheduler cannot handle more than one flow.
    with pytest.raises(fwp.scheduler.Error):
        fwp.scheduler.add_flow(flow)

    assert fwp.scheduler.start() 
    assert not fwp.scheduler.exceptions
    assert fwp.scheduler.nlaunch == 2

    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)

    # The WFK files should have been removed because we called set_cleanup_exts
    for task in flow[0]:
        assert not task.outdir.has_abiext("WFK")
Exemple #8
0
def build_flow(workdir):
    #workdir = "flow_test"

    # Instantiate the TaskManager.
    manager = abilab.TaskManager.from_user_config()

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs()

    # Build the flow.
    return abilab.bandstructure_flow(workdir, scf_input, nscf_input, manager=manager)
Exemple #9
0
def build_bands_flow(workdir):

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs()

    # Instantiate the TaskManager from `taskmanager.yml`.
    manager = abilab.TaskManager.from_user_config()
                                                               
    # Build the flow.
    flow = abilab.bandstructure_flow(workdir, manager, scf_input, nscf_input)
    return flow.allocate()
Exemple #10
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs()
    print(scf_input.to_string(sortmode="section"))

    # Build the flow.
    return abilab.bandstructure_flow(workdir, scf_input, nscf_input, manager=options.manager)
def itest_unconverged_scf(fwp, tvars):
    """Test the treatment of unconverged GS calculations."""
    print("tvars:\n %s" % str(tvars))

    # Build the SCF and the NSCF input (note nstep to have an unconverged run)
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc", nstep=1)

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, fwp.manager, scf_input, nscf_input)

    flow.allocate()
    flow.build_and_pickle_dump()

    t0 = flow[0][0]
    t1 = flow[0][1]

    # This run should not converge.
    t0.start_and_wait()
    t0.check_status()
    assert t0.status == t0.S_UNCONVERGED

    # Remove nstep from the input so that we use the default value.
    # Then restart the GS task and test that GS is OK.
    assert not t1.can_run
    t0.strategy.remove_extra_abivars(["nstep"])
    assert t0.num_restarts == 0
    t0.restart()
    t0.wait()
    assert t0.num_restarts == 1
    t0.check_status()
    assert t0.status == t1.S_OK

    # Now we can start the NSCF step
    assert t1.can_run
    t1.start_and_wait()
    t1.check_status()
    assert t1.status == t0.S_UNCONVERGED

    assert not flow.all_ok

    # Restart (same trick as the one used for the GS run)
    t1.strategy.remove_extra_abivars(["nstep"])
    assert t1.num_restarts == 0
    assert t1.restart()
    t1.wait()
    assert t1.num_restarts == 1
    assert t1.status == t1.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK

    flow.show_status()
    assert flow.all_ok
Exemple #12
0
def build_flow(workdir):
    #workdir = "flow_test"

    # Instantiate the TaskManager.
    manager = abilab.TaskManager.from_user_config()

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs()

    # Build the flow.
    return abilab.bandstructure_flow(workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=manager)
Exemple #13
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # Instantiate the TaskManager.
    manager = abilab.TaskManager.from_user_config() if not options.manager else \
              abilab.TaskManager.from_file(options.manager)

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs()

    # Build the flow.
    return abilab.bandstructure_flow(workdir, manager, scf_input, nscf_input)
Exemple #14
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace(
            "run_", "flow_")

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs()
    print(scf_input.to_string(sortmode="section"))

    # Build the flow.
    return abilab.bandstructure_flow(workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=options.manager)
Exemple #15
0
def build_bands_flow(workdir="tmp_mgb2_edoses"):
    pseudos = data.pseudos("12mg.pspnc", "05b.soft_tm")
    structure = data.structure_from_ucell("MgB2")

    nval = structure.calc_nvalence(pseudos)
    print(nval)

    inputs = make_scf_nscf_inputs(structure, pseudos)
    scf_input, nscf_input, dos_inputs = inputs[0], inputs[1], inputs[2:]
    print(scf_input.pseudos)

    manager = abilab.TaskManager.from_user_config()
                                                               
    flow = abilab.bandstructure_flow(workdir, manager, scf_input, nscf_input, dos_inputs=dos_inputs)

    return flow.allocate()
Exemple #16
0
def itest_bandstructure_schedflow(fwp, tvars):
    """
    Testing bandstructure flow with the scheduler.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(
        tvars, pp_paths="Si.GGA_PBE-JTH-paw.xml")

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=fwp.manager)

    # Will remove output files (WFK)
    flow.set_garbage_collector()
    flow.build_and_pickle_dump(abivalidate=True)

    fwp.scheduler.add_flow(flow)
    print(fwp.scheduler)
    # scheduler cannot handle more than one flow.
    with pytest.raises(fwp.scheduler.Error):
        fwp.scheduler.add_flow(flow)

    assert fwp.scheduler.start() == 0
    assert not fwp.scheduler.exceptions
    assert fwp.scheduler.nlaunch == 2

    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)

    # The WFK files should have been removed because we called set_garbage_collector
    for task in flow[0]:
        assert not task.outdir.has_abiext("WFK")

    # Test if GSR files are produced and are readable.
    for i, task in enumerate(flow[0]):
        with task.open_gsr() as gsr:
            print(gsr)
            assert gsr.nsppol == 1
            #assert gsr.structure == structure
            ebands = gsr.ebands
Exemple #17
0
def make_ebands_flow():
    """Band structure calculation."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"), ndtset=2)
    # Global variables
    multi.set_vars(ecut=10)

    # Dataset 1
    multi[0].set_vars(tolvrs=1e-9)
    multi[0].set_kmesh(ngkpt=[4,4,4], shiftk=[0,0,0])

    # Dataset 2
    multi[1].set_vars(tolwfr=1e-15)
    multi[1].set_kpath(ndivsm=5)

    scf_input, nscf_input = multi.split_datasets()

    return abilab.bandstructure_flow(workdir="flow_base3_ebands", scf_input=scf_input, nscf_input=nscf_input)
Exemple #18
0
def eh_convergence_study():
    """
    """
    scf_input, nscf_input, bse_template = make_inputs()
    workdir = "flow_bse_bands"

    if not os.path.exists(workdir):
        print("Calling the scheduler")
        bands_flow = abilab.bandstructure_flow(workdir, scf_input, nscf_input)
        bands_flow.make_scheduler().start()
    else:
        print("Initializing flow from %s" % workdir)
        bands_flow = abilab.Flow.pickle_load(workdir)

    if not bands_flow.all_ok:
        raise RuntimeError("bands_flow must have reached all_ok")

    wfk_file = bands_flow.nscf_task.outdir.has_abiext("WFK")
    if not wfk_file:
        raise RuntimeError("WFK file does not exist")

    work = abilab.Work()
    #for inp in bse_template.generate(ecuteps=range(2, 4, 1)):
    for inp in bse_template.generate(zcut=["0.1 eV", "0.2 eV", "0.3 eV"]):
        work.register_bse_task(inp, deps={wfk_file: "WFK"})

    flow = abilab.Flow(workdir="flow_bse_ecuteps")
    flow.register_work(work)
    flow.allocate()
    flow.build()

    #flow.make_scheduler().start()

    import matplotlib.pyplot as plt
    import pandas as pd

    with abilab.abirobot(flow, "MDF") as robot:
        frame = robot.get_dataframe()
        #print(frame)
        #plotter = robot.get_mdf_plotter()
        #plotter.plot()

        robot.plot_conv_mdf(hue="broad")
Exemple #19
0
def itest_bandstructure_schedflow(fwp, tvars):
    """
    Testing bandstructure flow with the scheduler.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="Si.GGA_PBE-JTH-paw.xml")

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager)

    # Will remove output files (WFK)
    flow.set_garbage_collector()
    flow.build_and_pickle_dump()

    fwp.scheduler.add_flow(flow)
    print(fwp.scheduler)
    # scheduler cannot handle more than one flow.
    with pytest.raises(fwp.scheduler.Error):
        fwp.scheduler.add_flow(flow)

    assert fwp.scheduler.start() == 0
    assert not fwp.scheduler.exceptions
    assert fwp.scheduler.nlaunch == 2

    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)

    # The WFK files should have been removed because we called set_garbage_collector
    for task in flow[0]:
        assert not task.outdir.has_abiext("WFK")

    # Test if GSR files are produced and are readable.
    for i, task in enumerate(flow[0]):
        with task.open_gsr() as gsr:
            print(gsr)
            assert gsr.nsppol == 1
            #assert gsr.structure == structure
            ebands = gsr.ebands
Exemple #20
0
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    # Instantiate the TaskManager.
    manager = abilab.TaskManager.from_user_config() if not options.manager else \
              abilab.TaskManager.from_file(options.manager)

    pseudos = data.pseudos("12mg.pspnc", "5b.pspnc")
    structure = data.structure_from_ucell("MgB2")

    nval = structure.num_valence_electrons(pseudos)
    #print(nval)

    inputs = make_scf_nscf_inputs(structure, pseudos)
    scf_input, nscf_input, dos_inputs = inputs[0], inputs[1], inputs[2:]
    print(scf_input.pseudos)
                                                               
    return abilab.bandstructure_flow(workdir, manager, scf_input, nscf_input, dos_inputs=dos_inputs)
Exemple #21
0
def make_ebands_flow():
    """Band structure calculation."""
    multi = abilab.MultiDataset(structure=abidata.cif_file("si.cif"),
                                pseudos=abidata.pseudos("14si.pspnc"),
                                ndtset=2)
    # Global variables
    multi.set_vars(ecut=10)

    # Dataset 1
    multi[0].set_vars(tolvrs=1e-9)
    multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=[0, 0, 0])

    # Dataset 2
    multi[1].set_vars(tolwfr=1e-15)
    multi[1].set_kpath(ndivsm=5)

    scf_input, nscf_input = multi.split_datasets()

    return abilab.bandstructure_flow(workdir="flow_base3_ebands",
                                     scf_input=scf_input,
                                     nscf_input=nscf_input)
def build_flow(options):
    # Working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_")
    workdir = options.workdir
    if not options.workdir:
        workdir = os.path.basename(__file__).replace(".py", "").replace("run_","flow_") 

    #pseudos = abidata.pseudos("12mg.pspnc", "5b.pspnc")
    structure = abidata.structure_from_ucell("MgB2")

    # Get pseudos from a table. 
    table = abilab.PseudoTable(abidata.pseudos("12mg.pspnc", "5b.pspnc"))
    pseudos = table.get_pseudos_for_structure(structure)

    nval = structure.num_valence_electrons(pseudos)
    #print(nval)

    inputs = make_scf_nscf_inputs(structure, pseudos)
    scf_input, nscf_input, dos_inputs = inputs[0], inputs[1], inputs[2:]
    #print(scf_input.pseudos)
                                                               
    return abilab.bandstructure_flow(workdir, scf_input, nscf_input, 
                                     dos_inputs=dos_inputs, manager=options.manager)
Exemple #23
0
def bands_flow():
    inp = abilab.AbiInput(pseudos=abidata.pseudos("14si.pspnc"), ndtset=2)
    inp.set_structure_from_file(abidata.cif_file("si.cif"))

    # Global variables
    inp.ecut = 10

    # Dataset 1
    inp[1].set_variables(tolvrs=1e-9)
    inp[1].set_kmesh(ngkpt=[4,4,4], shiftk=[0,0,0])

    # Dataset 2
    inp[2].set_variables(tolwfr=1e-15)
    inp[2].set_kpath(ndivsm=5)

    scf_input, nscf_input = inp.split_datasets()

    flow = abilab.bandstructure_flow(workdir="flow_bands", scf_input=scf_input, nscf_input=nscf_input)
    flow.make_scheduler().start()
    
    nscf_task = flow[0][1]
    with nscf_task.open_gsr() as gsr:
        gsr.ebands.plot()
Exemple #24
0
def itest_unconverged_scf(fwp, tvars):
    """Testing the treatment of unconverged GS calculations."""
    print("tvars:\n %s" % str(tvars))

    # Build the SCF and the NSCF input (note nstep to have an unconverged run)
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc", nstep=1)

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager)
    flow.allocate()

    # Use smart-io
    flow.use_smartio()

    flow.build_and_pickle_dump()

    t0 = flow[0][0]
    t1 = flow[0][1]

    assert t0.uses_paral_kgb(tvars.paral_kgb)
    assert t1.uses_paral_kgb(tvars.paral_kgb)

    # This run should not converge.
    t0.start_and_wait()
    t0.check_status()
    assert t0.status == t0.S_UNCONVERGED
    # Unconverged with smart-io --> WFK must be there
    assert t0.outdir.has_abiext("WFK")
    #assert 0

    # Remove nstep from the input so that we use the default value.
    # Then restart the GS task and test that GS is OK.
    assert not t1.can_run
    t0.input.pop("nstep")
    assert t0.num_restarts == 0
    t0.restart()
    t0.wait()
    assert t0.num_restarts == 1
    t0.check_status()
    assert t0.status == t1.S_OK

    # Converged with smart-io --> WFK is not written
    assert not t0.outdir.has_abiext("WFK")

    # Now we can start the NSCF step
    assert t1.can_run
    t1.start_and_wait()
    t1.check_status()
    assert t1.status == t0.S_UNCONVERGED

    assert not flow.all_ok

    # Restart (same trick as the one used for the GS run)
    t1.input.pop("nstep")
    assert t1.num_restarts == 0
    assert t1.restart()
    t1.wait()
    assert t1.num_restarts == 1
    assert t1.status == t1.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK

    flow.show_status()
    assert flow.all_ok

    # Test inspect methods
    if has_matplotlib():
        t0.inspect(show=False)

    # Test get_results
    t0.get_results()
    t1.get_results()

    # Build tarball file.
    tarfile = flow.make_tarfile()

    #assert flow.validate_json_schema()

    # Test reset_from_scratch
    t0.reset_from_scratch()
    assert t0.status == t0.S_READY
    # Datetime counters shouls be set to None
    dt = t0.datetimes
    assert (dt.submission, dt.start, dt.end) == (None, None, None)

    t0.start_and_wait()
    t0.reset_from_scratch()

    # Datetime counters shouls be set to None
    dt = t0.datetimes
    assert (dt.submission, dt.start, dt.end) == (None, None, None)
Exemple #25
0
def itest_bandstructure_flow(fwp, tvars):
    """
    Testing band-structure flow with one dependency: SCF -> NSCF.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc")

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, scf_input, nscf_input, manager=fwp.manager)
    flow.build_and_pickle_dump(abivalidate=True)

    t0 = flow[0][0]
    t1 = flow[0][1]

    # Test initialization status, task properties and links (t1 requires t0)
    assert t0.status == t0.S_INIT
    assert t1.status == t1.S_INIT
    assert t0.can_run
    assert not t1.can_run
    assert t1.depends_on(t0)
    assert not t1.depends_on(t1)
    assert t0.isnc
    assert not t0.ispaw

    # Flow properties and methods
    assert flow.num_tasks == 2
    assert not flow.all_ok
    assert flow.ncores_reserved == 0
    assert flow.ncores_allocated == 0
    assert flow.ncores_used == 0
    flow.check_dependencies()
    flow.show_status()
    flow.show_receivers()

    # Run t0, and check status
    assert t0.returncode == 0
    t0.start_and_wait()
    assert t0.returncode == 0
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert t1.can_run

    # Cannot start t0 twice...
    with pytest.raises(t0.Error):
        t0.start()

    # But we can restart it.
    fired = t0.restart()
    assert fired
    t0.wait()
    assert t0.num_restarts == 1
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert not t0.can_run

    # Now we can run t1.
    t1.start_and_wait()
    assert t1.status == t0.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK
    assert not t1.can_run

    # This one does not work yet
    #fired = t1.restart()
    #atrue(fired)
    #t1.wait()
    #aequal(t1.num_restarts, 1)
    #aequal(t1.status, t1.S_DONE)
    #t1.check_status()
    #aequal(t1.status, t1.S_OK)
    #afalse(t1.can_run)

    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)

    for task in flow.iflat_tasks():
        assert len(task.outdir.list_filepaths(wildcard="*GSR.nc")) == 1

    # Test GSR robot
    with abilab.abirobot(flow, "GSR") as robot:
        table = robot.get_dataframe()
        assert table is not None
        print(table)

    # Test AbinitTimer.
    timer = t0.parse_timing()
    print(timer)

    if has_matplotlib:
        timer.plot_pie(show=False)
        timer.plot_stacked_hist(show=False)
        timer.plot_efficiency(show=False)
Exemple #26
0
def itest_unconverged_scf(fwp, tvars):
    """Testing the treatment of unconverged GS calculations."""
    print("tvars:\n %s" % str(tvars))

    # Build the SCF and the NSCF input (note nstep to have an unconverged run)
    scf_input, nscf_input = make_scf_nscf_inputs(tvars,
                                                 pp_paths="14si.pspnc",
                                                 nstep=1)

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=fwp.manager)
    flow.allocate()

    # Use smart-io
    flow.use_smartio()

    flow.build_and_pickle_dump(abivalidate=True)

    t0 = flow[0][0]
    t1 = flow[0][1]

    assert t0.uses_paral_kgb(tvars.paral_kgb)
    assert t1.uses_paral_kgb(tvars.paral_kgb)

    # This run should not converge.
    t0.start_and_wait()
    t0.check_status()
    assert t0.status == t0.S_UNCONVERGED
    # Unconverged with smart-io --> WFK must be there
    assert t0.outdir.has_abiext("WFK")
    #assert 0

    # Remove nstep from the input so that we use the default value.
    # Then restart the GS task and test that GS is OK.
    assert not t1.can_run
    t0.input.pop("nstep")
    assert t0.num_restarts == 0
    t0.restart()
    t0.wait()
    assert t0.num_restarts == 1
    t0.check_status()
    assert t0.status == t1.S_OK

    # Converged with smart-io --> WFK is not written
    assert not t0.outdir.has_abiext("WFK")

    # Now we can start the NSCF step
    assert t1.can_run
    t1.start_and_wait()
    t1.check_status()
    assert t1.status == t0.S_UNCONVERGED

    assert not flow.all_ok

    # Restart (same trick as the one used for the GS run)
    t1.input.pop("nstep")
    assert t1.num_restarts == 0
    assert t1.restart()
    t1.wait()
    assert t1.num_restarts == 1
    assert t1.status == t1.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK

    flow.show_status()
    assert flow.all_ok

    # Test inspect methods
    if has_matplotlib():
        t0.inspect(show=False)

    # Test get_results
    t0.get_results()
    t1.get_results()

    # Build tarball file.
    tarfile = flow.make_tarfile()

    #assert flow.validate_json_schema()

    # Test reset_from_scratch
    t0.reset_from_scratch()
    assert t0.status == t0.S_READY
    # Datetime counters shouls be set to None
    dt = t0.datetimes
    assert (dt.submission, dt.start, dt.end) == (None, None, None)

    t0.start_and_wait()
    t0.reset_from_scratch()

    # Datetime counters shouls be set to None
    dt = t0.datetimes
    assert (dt.submission, dt.start, dt.end) == (None, None, None)
Exemple #27
0
def itest_bandstructure_flow(fwp, tvars):
    """
    Testing band-structure flow with one dependency: SCF -> NSCF.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc")

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir,
                                     scf_input,
                                     nscf_input,
                                     manager=fwp.manager)
    flow.build_and_pickle_dump(abivalidate=True)

    t0 = flow[0][0]
    t1 = flow[0][1]

    # Test initialization status, task properties and links (t1 requires t0)
    assert t0.status == t0.S_INIT
    assert t1.status == t1.S_INIT
    assert t0.can_run
    assert not t1.can_run
    assert t1.depends_on(t0)
    assert not t1.depends_on(t1)
    assert t0.isnc
    assert not t0.ispaw

    # Flow properties and methods
    assert flow.num_tasks == 2
    assert not flow.all_ok
    assert flow.ncores_reserved == 0
    assert flow.ncores_allocated == 0
    assert flow.ncores_used == 0
    flow.check_dependencies()
    flow.show_status()
    flow.show_receivers()

    # Run t0, and check status
    assert t0.returncode == 0
    t0.start_and_wait()
    assert t0.returncode == 0
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert t1.can_run

    # Cannot start t0 twice...
    with pytest.raises(t0.Error):
        t0.start()

    # But we can restart it.
    fired = t0.restart()
    assert fired
    t0.wait()
    assert t0.num_restarts == 1
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert not t0.can_run

    # Now we can run t1.
    t1.start_and_wait()
    assert t1.status == t0.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK
    assert not t1.can_run

    # This one does not work yet
    #fired = t1.restart()
    #atrue(fired)
    #t1.wait()
    #aequal(t1.num_restarts, 1)
    #aequal(t1.status, t1.S_DONE)
    #t1.check_status()
    #aequal(t1.status, t1.S_OK)
    #afalse(t1.can_run)

    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)

    for task in flow.iflat_tasks():
        assert len(task.outdir.list_filepaths(wildcard="*GSR.nc")) == 1

    # Test GSR robot
    with abilab.abirobot(flow, "GSR") as robot:
        table = robot.get_dataframe()
        assert table is not None
        print(table)

    # Test AbinitTimer.
    timer = t0.parse_timing()
    print(timer)

    if has_matplotlib:
        timer.plot_pie(show=False)
        timer.plot_stacked_hist(show=False)
        timer.plot_efficiency(show=False)
def itest_bandstructure_flow(fwp, tvars):
    """
    Test band-structure flow with one dependency: SCF -> NSCF.
    """
    print("tvars:\n %s" % str(tvars))

    # Get the SCF and the NSCF input.
    scf_input, nscf_input = make_scf_nscf_inputs(tvars, pp_paths="14si.pspnc")

    # Build the flow and create the database.
    flow = abilab.bandstructure_flow(fwp.workdir, fwp.manager, scf_input, nscf_input)

    flow.build_and_pickle_dump()

    t0 = flow[0][0]
    t1 = flow[0][1]

    # Test initialization status, task properties and links (t1 requires t0)
    assert t0.status == t0.S_INIT
    assert t1.status == t1.S_INIT
    assert t0.can_run
    assert not t1.can_run
    assert t1.depends_on(t0)
    assert not t1.depends_on(t1)
    assert t0.isnc
    assert not t0.ispaw

    # Flow properties and methods
    assert flow.num_tasks == 2
    assert not flow.all_ok
    assert flow.ncpus_reserved == 0
    assert flow.ncpus_allocated == 0
    assert flow.ncpus_inuse == 0
    flow.check_dependencies()
    flow.show_status()
    flow.show_receivers()

    # Run t0, and check status
    assert t0.returncode == 0
    t0.start_and_wait()
    assert t0.returncode == 0
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert t1.can_run

    # Cannot start t0 twice...
    with pytest.raises(t0.Error):
        t0.start()

    # But we can restart it.
    fired = t0.restart()
    assert fired
    t0.wait()
    assert t0.num_restarts == 1
    assert t0.status == t0.S_DONE
    t0.check_status()
    assert t0.status == t0.S_OK
    assert not t0.can_run

    # Now we can run t1.
    t1.start_and_wait()
    assert t1.status == t0.S_DONE
    t1.check_status()
    assert t1.status == t1.S_OK
    assert not t1.can_run

    # This one does not work yet
    #fired = t1.restart()
    #atrue(fired)
    #t1.wait()
    #aequal(t1.num_restarts, 1)
    #aequal(t1.status, t1.S_DONE)
    #t1.check_status()
    #aequal(t1.status, t1.S_OK)
    #afalse(t1.can_run)

    flow.show_status()
    assert flow.all_ok
    assert all(work.finalized for work in flow)

    for task in flow.iflat_tasks():
        assert len(task.outdir.list_filepaths(wildcard="*GSR.nc")) == 1