def execute(self, name):
        try:
            self.state.saveState('READY')
            lp = LaunchPad(**self.db)
            lp.reset('', require_password=False)
            tasks = []
            for idx, command in enumerate(self.commands):
                if idx > 0:
                    tasks.append(
                        Firework(ScriptTask.from_str(command),
                                 name=f'task_{idx}',
                                 fw_id=idx,
                                 parents=[tasks[idx - 1]]))
                else:
                    tasks.append(
                        Firework(ScriptTask.from_str(command),
                                 name=f'task_{idx}',
                                 fw_id=idx))

            self.state.saveState('RUNNING')
            wf = Workflow(tasks, name=name)
            lp.add_wf(wf)
            rapidfire(lp)
            self.state.saveState('FINISHED')
        except Exception as e:
            print(e)
            self.state.saveState('ERROR')
예제 #2
0
 def run_task(self, fw_spec):
     job_info_array = fw_spec['_job_info']
     prev_job_info = job_info_array[-1]
     path2setup = prev_job_info['launch_dir']
     for file in glob.glob(path2setup + '/*'):
         if string.split(file, '.')[-1] == 'json': continue
         shutil.copy(file, '.')
     ### print infos to file
     ST = ScriptTask.from_str('rm JOB-*;touch JOB-' + self["wf_name"] +
                              '-hessian')
     Action = ST.run_task(fw_spec)
     ### prepare controle file
     ST = ScriptTask.from_str('prep_aoforce')
     Action = ST.run_task(fw_spec)
     ### run aoforce
     ST = ScriptTask.from_str('aoforce > force.out')
     Action = ST.run_task(fw_spec)
     ### run Merz Kollman fit
     ST = ScriptTask.from_str('dscf > charge.out')
     Action = ST.run_task(fw_spec)
     ### tm2molden ###
     ST = ScriptTask.from_str('tm2molden < tm2molden.prot > /dev/null')
     Action = ST.run_task(fw_spec)
     ### check for negative frequencies
     noneg = check_aoforce('molden.input')
     return Action
예제 #3
0
 def __init__(self, final_message):
     super(FirstFirework, self).__init__(tasks=[
         ScriptTask.from_str("echo 'Here we go!'"),
         MiddleTask(message="next",
                    fw_action=FWAction(additions=Firework([
                        ScriptTask.from_str("echo '" + final_message + "'")
                    ])))
     ])
예제 #4
0
 def run_task(self, fw_spec):
     job_info_array = fw_spec['_job_info']
     prev_job_info = job_info_array[-1]
     path2setup = prev_job_info['launch_dir']
     for file in glob.glob(path2setup + '/*'):
         if string.split(file, '.')[-1] == 'json': continue
         shutil.copy(file, '.')
     ### print infos to file
     ST = ScriptTask.from_str('rm JOB-*;touch JOB-' + self["wf_name"] +
                              '-opt')
     Action = ST.run_task(fw_spec)
     ### run jobex
     ST = ScriptTask.from_str('jobex -ri -c 200 > jobex.out')
     Action = ST.run_task(fw_spec)
     return Action
예제 #5
0
def wf_creator_complex(x):
    """
    Testing a custom workflow of five fireworks with complex dependencies, and
    optimization in the middle.
    This "complex" Workflow has the form:
                    fw0
                    / \
                  fw1 fw2
                   \  /
                   fw3 (optimization)
                    |
                   fw4
                    |
                   fw5
    """

    spec = {'_x': x}
    fw0 = Firework(AdditionTask(), spec={"input_array": [1, 2]}, name='Parent')
    fw1 = Firework(AdditionTask(), spec={"input_array": [2, 3]}, name='Child A')
    fw2 = Firework(AdditionTask(), spec={"input_array": [3, 4]}, name='Child B')
    bt = BasicTestTask()
    ot = OptTask(**db_info)
    fw3 = Firework([bt, ot], spec=spec, name="Optimization")
    fw4 = Firework(AdditionTask(), spec={"input_array": [5, 6]}, name='After 1')
    fw5 = Firework(ScriptTask.from_str('echo "ScriptTask: Finished complex '
                                       'workflow w/ optimization."'),
                   name='After 2')

    return Workflow([fw0, fw1, fw2, fw3, fw4, fw5],
                    {fw0: [fw1, fw2], fw1: [fw3], fw2: [fw3], fw3: [fw4], fw4:
                        [fw5], fw5: []})
예제 #6
0
 def create_firework(cls, filename, spec):
     cur_dir = os.getcwd()
     task_path = cur_dir + "/" + filename
     command = "sh " + task_path
     task = ScriptTask.from_str(command)
     firework = Firework(task, spec=spec)
     return firework
예제 #7
0
def main():
    # set up the LaunchPad and reset it
    swarmpad = SwarmPad()
    swarmpad.reset('', require_password=False)

    firetask1 = ScriptTask.from_str('echo "starting"; sleep 30; echo "ending"')
    firetask2 = ScriptTask.from_str('echo "hello from BACKGROUND thread #1"')
    firetask3 = ScriptTask.from_str('echo "hello from BACKGROUND thread #2"')

    # Combine [firetasks] parallely to form a ParallelTask
    par_task = ParallelTask.from_firetasks([firetask1, firetask2])

    # Combine the par_task and firetask3 sequentially
    firework = Firework([par_task, firetask3])

    # store workflow and launch it locally
    swarmpad.add_wf(firework)
    rapidfire(swarmpad, FWorker())
예제 #8
0
 def FFfit(self, parent):
     # fit FF
     fit0 = ScriptTask.from_str(info(self.wfname, 'FF_fit'))
     fit1 = RemoteCopyTask(server='cmcc',
                           files=[self.fkey, self.ftxyz, self.fref])
     fit2 = ScriptTask.from_str('fit-cma -c %s -k %s -r %s > fit.out \
             2> fit.err' % (self.ftxyz, self.fkey, self.wfname))
     fit3 = ScriptTask.from_str('compare-freqs -c %s -k %s/opt.key -r %s > \
             /dev/null 2> compare-freqs.err' %
                                (self.ftxyz, self.wfname, self.wfname))
     fit = Firework([fit0, fit1, fit2, fit3],
                    name='FF_fit',
                    parents=[parent],
                    spec={
                        "_pass_job_info": True,
                        '_fworker': 'merry'
                    })
     return fit
예제 #9
0
def dummy_workflow():
    """
    dummy fireworks Workflow
    """
    # create the Firework consisting of multiple tasks
    firetask1 = TemplateWriterTask({'context': {'opt1': 5.0, 'opt2': 'fast method'}, 'template_file': 'simple_template.txt', 'output_file': 'inputs.txt'})
    firetask2 = ScriptTask.from_str('wc -w < inputs.txt > words.txt')
    firetask3 = FileTransferTask({'files': [{'src': 'words.txt', 'dest': '~/words.txt'}], 'mode': 'copy'})
    wf = Firework([firetask1, firetask2, firetask3])
    return wf
예제 #10
0
 def run_task(self, fw_spec):
     job_info_array = fw_spec['_job_info']
     prev_job_info = job_info_array[-1]
     path2setup = prev_job_info['launch_dir']
     for file in glob.glob(path2setup + '/*'):
         shutil.copy(file, '.')
     #ST = ScriptTask.from_str('jobex -ri -c 200 > jobex.out')
     ST = ScriptTask.from_str('touch foo')
     Action = ST.run_task(fw_spec)
     return Action
예제 #11
0
 def TMsetup(self, parent):
     # setup TM
     setup0 = FileTransferTask({
         'files': ['../' + self.fxyz, '../' + self.fprot],
         'dest':
         '.',
         'mode':
         'copy'
     })
     setup1 = ScriptTask.from_str(x2t(self.fxyz))  # x2t
     setup2 = ScriptTask.from_str(define(self.fprot))  # define
     setup3 = ScriptTask.from_str(info(self.wfname, 'TM_setup'))
     setup = Firework([setup0, setup1, setup2, setup3],
                      name='TM_setup',
                      spec={
                          "_pass_job_info": True,
                          '_fworker': 'cmcc_front'
                      },
                      parents=[parent])
     return setup
예제 #12
0
 def FFsetup(self, parent):
     # setup FF
     FF1 = CopyTask()
     FF2 = ScriptTask.from_str(info(self.wfname, 'FF_setup'))
     FF3 = ScriptTask.from_str(
         'xyz2txyz -i final.xyz -o %s > /dev/null 2> xyz2txyz.err' %
         self.ftxyz)
     FF4 = ScriptTask.from_str(
         'atomtyper -c %s -o %s > /dev/null 2> atomtyper.err' %
         (self.ftxyz, self.ftxyz))
     FF5 = ScriptTask.from_str(
         'create_key -i %s -o %s -r %s > key.out 2> key.err' %
         (self.ftxyz, self.fkey, self.wfname))
     FF = Firework([FF1, FF2, FF3, FF4, FF5],
                   name='FF_setup',
                   parents=[parent],
                   spec={
                       "_pass_job_info": True,
                       '_fworker': 'cmcc_front'
                   })
     return FF
예제 #13
0
 def extract(self, parent):
     # extract infos
     extract1 = ExtractTask(fxyz=self.fxyz, fref=self.wfname)
     extract2 = ScriptTask.from_str(info(self.wfname, 'extract'))
     extract = Firework([extract1, extract2],
                        name='extract',
                        parents=[parent],
                        spec={
                            "_pass_job_info": True,
                            '_fworker': 'cmcc_front'
                        })
     return extract
예제 #14
0
 def run_task(self, fw_spec):
     job_info_array = fw_spec['_job_info']
     prev_job_info = job_info_array[-1]
     path2setup = prev_job_info['launch_dir']
     #print path2setup
     shutil.copy(path2setup + '/' + self["fxyz"], ".")
     #print path2setup
     ST = ScriptTask.from_str('create_ref -c ' + self["fxyz"] + ' -r ' +
                              self["fref"] + ' -p ' + path2setup +
                              ' > create_ref.out 2> create_ref.err')
     Action = ST.run_task(fw_spec)
     shutil.copy(path2setup + '/final.xyz', ".")
     return Action
예제 #15
0
def wf_creator_complex(x, launchpad):
    """
    Testing a custom workflow of five fireworks with complex dependencies, and
    optimization in the middle.
    This "complex" Workflow has the form:
                    fw0
                    / \
                  fw1 fw2
                   \  /
                   fw3 (optimization)
                    |
                   fw4
                    |
                   fw5
    """

    spec = {'_x_opt': x}
    dims = [(1, 10), (10.0, 20.0), ['blue', 'green', 'red', 'orange']]
    fw0 = Firework(AdditionTask(), spec={"input_array": [1, 2]}, name='Parent')
    fw1 = Firework(AdditionTask(),
                   spec={"input_array": [2, 3]},
                   name='Child A')
    fw2 = Firework(AdditionTask(),
                   spec={"input_array": [3, 4]},
                   name='Child B')

    bt = BasicTestTask()
    ot = OptTask(wf_creator='rocketsled.tests.tests.wf_creator_complex',
                 dimensions=dims,
                 lpad=launchpad,
                 wf_creator_args=[launchpad],
                 opt_label='test_complex')
    fw3 = Firework([bt, ot], spec=spec, name="Optimization")

    fw4 = Firework(AdditionTask(),
                   spec={"input_array": [5, 6]},
                   name='After 1')
    fw5 = Firework(ScriptTask.from_str('echo "ScriptTask: Finished complex '
                                       'workflow w/ optimization."'),
                   name='After 2')

    return Workflow([fw0, fw1, fw2, fw3, fw4, fw5], {
        fw0: [fw1, fw2],
        fw1: [fw3],
        fw2: [fw3],
        fw3: [fw4],
        fw4: [fw5],
        fw5: []
    })
예제 #16
0
def wf_creator_complex(x):
    """
    Testing a custom workflow of five fireworks with complex dependencies, and
    optimization in the middle.
    This "complex" Workflow has the form:
                    fw0
                    / \
                  fw1 fw2
                   \  /
                   fw3 (optimization)
                    |
                   fw4
                    |
                   fw5
    """

    spec = {"_x": x}
    fw0 = Firework(AdditionTask(), spec={"input_array": [1, 2]}, name="Parent")
    fw1 = Firework(AdditionTask(),
                   spec={"input_array": [2, 3]},
                   name="Child A")
    fw2 = Firework(AdditionTask(),
                   spec={"input_array": [3, 4]},
                   name="Child B")
    bt = BasicTestTask()
    ot = OptTask(**db_info)
    fw3 = Firework([bt, ot], spec=spec, name="Optimization")
    fw4 = Firework(AdditionTask(),
                   spec={"input_array": [5, 6]},
                   name="After 1")
    fw5 = Firework(
        ScriptTask.from_str('echo "ScriptTask: Finished complex '
                            'workflow w/ optimization."'),
        name="After 2",
    )

    return Workflow(
        [fw0, fw1, fw2, fw3, fw4, fw5],
        {
            fw0: [fw1, fw2],
            fw1: [fw3],
            fw2: [fw3],
            fw3: [fw4],
            fw4: [fw5],
            fw5: []
        },
    )
예제 #17
0
    def run_task(self, fw_spec):

        if self["message"] == "next":

            print("The message was next!")
            print(self["message"])

            fw = Firework([
                ScriptTask.from_str("echo next"),
                MiddleTask(message="other",
                           fw_action=self.get("fw_action", FWAction()))
            ])

            return FWAction(additions=fw)

        else:

            print("The message was Something Else!")
            print(self["message"])
            print()
            print(self.get("fw_action", FWAction()))
            print()

            return FWAction.from_dict(self.get("fw_action", {}))
예제 #18
0
from swarmform import SwarmPad
from fireworks import Firework, ScriptTask, FWorker
from fireworks.core.rocket_launcher import launch_rocket

if __name__ == "__main__":
    # set up the SwarmPad and reset it
    swarmpad = SwarmPad()
    swarmpad.reset('', require_password=False)

    # create the Firework consisting of a custom "Addition" task
    firework = Firework(ScriptTask.from_str('echo "hello"'))

    # store workflow
    swarmpad.add_sf(firework)

    # Retrieve SwarmFlow from the SwarmPad
    sf = swarmpad.get_sf_by_id(1)

    sf = swarmpad.get_sf_by_name('Unnamed FW')

    # Run the swarmFlow
    launch_rocket(swarmpad, FWorker())
예제 #19
0
from fireworks import Firework, Workflow, LaunchPad, ScriptTask
from fireworks.core.rocket_launcher import rapidfire

# set up the LaunchPad and reset it
launchpad = LaunchPad()
launchpad.reset('', require_password=False)

# create the individual FireWorks and Workflow
fw1 = Firework(ScriptTask.from_str('echo "hello"'), name="hello")
fw2 = Firework(ScriptTask.from_str('echo "goodbye"'), name="goodbye", parents=[fw1,])
wf = Workflow([fw1, fw2], name="test workflow")

# store workflow and launch it locally
launchpad.add_wf(wf)
rapidfire(launchpad)
예제 #20
0
from fireworks import Firework, LaunchPad, ScriptTask
from fireworks.core.rocket_launcher import launch_rocket, rapidfire

# set up the LaunchPad and reset it
launchpad = LaunchPad(strm_lvl='WARNING') # set messaging lowest level to WARNING
launchpad.reset('', require_password=False)

# create the Firework consisting of a single task
firetask = ScriptTask.from_str('cd /projects/development/LDRDSANS/fireworks/localtest; ./test_cluster.sh')
firework = Firework(firetask)
fw_yaml = firework.to_file("my_firework.yaml") # save to yaml file, and get the string representation
fw_json = firework.to_file("my_firework.json") # save to json file, and get the string representation

# store workflow and launch it locally
launchpad.add_wf(firework)
launch_rocket(launchpad)  # same as "rlaunch singleshot"
#rapidfire(launchpad, FWorker(), strm_lvl='WARNING')  # same as "rlaunch rapidfire"

# loading from file
# any class in FireWorks that subclasses FWSerializable has methods from_file and to_file
#firework = Firework.from_file("fw_test.yaml")
#fw_yaml = Firework.from_file("fw_test.json")
예제 #21
0
"""
This code is described in the Introductory tutorial, https://materialsproject.github.io/fireworks/introduction.html
"""

from fireworks import Firework, LaunchPad, ScriptTask
from fireworks.core.rocket_launcher import launch_rocket

if __name__ == "__main__":
    # set up the LaunchPad and reset it
    launchpad = LaunchPad()
    # launchpad.reset('', require_password=False)

    # create the Firework consisting of a single task
    firetask = ScriptTask.from_str('echo "howdy, your job launched successfully!"')
    firework = Firework(firetask)

    # store workflow and launch it locally
    launchpad.add_wf(firework)
    launch_rocket(launchpad)
예제 #22
0
"""
This code is described in the Dynamic Workflow tutorial, https://materialsproject.github.io/fireworks/dynamic_wf_tutorial.html
"""

from fireworks import ScriptTask
from fireworks.core.firework import Firework, Workflow
from fireworks.core.launchpad import LaunchPad
from fireworks.core.rocket_launcher import rapidfire

from fw_tutorials.dynamic_wf.printjob_task import PrintJobTask

if __name__ == "__main__":
    # set up the LaunchPad and reset it
    launchpad = LaunchPad()
    # launchpad.reset('', require_password=False)

    # create the Workflow that passes job info
    fw1 = Firework([ScriptTask.from_str('echo "This is the first FireWork"')],
                   spec={"_pass_job_info": True},
                   fw_id=1)
    fw2 = Firework([PrintJobTask()], parents=[fw1], fw_id=2)
    wf = Workflow([fw1, fw2])

    # store workflow and launch it locally
    launchpad.add_wf(wf)
    rapidfire(launchpad)
예제 #23
0
"""
This code is described in the Introductory tutorial, http://pythonhosted.org/FireWorks/introduction.html
"""

from fireworks import Firework, LaunchPad, ScriptTask
from fireworks.core.rocket_launcher import launch_rocket

if __name__ == "__main__":
    # set up the LaunchPad and reset it
    launchpad = LaunchPad()
    # launchpad.reset('', require_password=False)

    # create the Firework consisting of a single task
    firetask = ScriptTask.from_str(
        'echo "howdy, your job launched successfully!"')
    firework = Firework(firetask)

    # store workflow and launch it locally
    launchpad.add_wf(firework)
    launch_rocket(launchpad)
예제 #24
0
"""
This code is described in the Dynamic Workflow tutorial, https://materialsproject.github.io/fireworks/dynamic_wf_tutorial.html
"""

from fireworks import ScriptTask
from fireworks.core.firework import Firework, Workflow
from fireworks.core.launchpad import LaunchPad
from fireworks.core.rocket_launcher import rapidfire

from fw_tutorials.dynamic_wf.printjob_task import PrintJobTask

if __name__ == "__main__":
    # set up the LaunchPad and reset it
    launchpad = LaunchPad()
    # launchpad.reset('', require_password=False)

    # create the Workflow that passes job info
    fw1 = Firework([ScriptTask.from_str('echo "This is the first FireWork"')], spec={"_pass_job_info": True}, fw_id=1)
    fw2 = Firework([PrintJobTask()], parents=[fw1], fw_id=2)
    wf = Workflow([fw1, fw2])

    # store workflow and launch it locally
    launchpad.add_wf(wf)
    rapidfire(launchpad)
예제 #25
0
    def addRunSteps(self, inpSim, userID, cores):
        #builds the following workflow for running simulations
        #creates directory for simulation using the sim name and uuid
        #writes gkyl input file to the directory
        #runs file in the directory
        #if run is successful, prints 'Done', if not, prints 'Failed
        #plots task

        #userid --> for folder location
        self.fws = []
        print(inpSim)
        self.last = len(self.launchpad.get_fw_ids())
        #        for fwork in self.launchpad.get_fw_ids():
        #            self.launchpad.delete_fws([fwork])
        sim = Sim(inpSim)

        #        path = '/home/adaniel99/gkylsoft/sims/'+str(userID)+'/'+inpSim+'/'
        path = '/home/dalex_99/gkylsoft/sims/' + str(
            userID) + '/' + inpSim + '/'
        n = 0
        #        for f in os.listdir('/home/adaniel99/gkylsoft/sims/'):
        for f in os.listdir('/home/dalex_99/gkylsoft/sims/'):
            if f == str(userID):
                #                for f in os.listdir('/home/adaniel99/gkylsoft/sims/'+str(userID)+'/'):
                for f in os.listdir('/home/dalex_99/gkylsoft/sims/' +
                                    str(userID) + '/'):
                    if f == inpSim:
                        n = n + 1
                        self.rerun = True

        if n == 0:
            desttask = ScriptTask.from_str('mkdir ' + path)
            writetask = FileWriteTask({
                'files_to_write': ([{
                    'filename': sim.name(),
                    'contents': sim.inpFile()
                }]),
                'dest':
                path
            })
            runtask = ScriptTask.from_str(
                'redis-cli PUBLISH ' + User(userID).name() +
                '2 "Running Simulation"; mpiexec -n ' + cores + 'gkyl ' +
                path + sim.name())
            runFlag = ScriptTask.from_str('redis-cli PUBLISH ' +
                                          User(userID).name() + '2' + ' Done')
            deleteFail = ScriptTask.from_str('lpad defuse_fws -i ' +
                                             str(6 + self.last))
            flagFail = ScriptTask.from_str('redis-cli PUBLISH ' +
                                           User(userID).name() + '2' +
                                           ' Failed')
            self.ids.clear()
            dest = Firework(desttask, name='Make Folder', fw_id=1 + self.last)
            self.ids.append(1 + self.last)
            write = Firework(writetask, name='Write', fw_id=2 + self.last)
            self.ids.append(2 + self.last)
            run = Firework(runtask, name='Run', fw_id=3 + self.last)
            self.ids.append(3 + self.last)
            flag1 = Firework(runFlag, name='done?', fw_id=4 + self.last)
            self.ids.append(4 + self.last)
            delfail = Firework(deleteFail,
                               name='remove fail flag',
                               fw_id=5 + self.last)
            self.ids.append(5 + self.last)
            failflag = Firework(flagFail,
                                name='fail flag',
                                fw_id=6 + self.last)
            self.ids.append(6 + self.last)

            self.fws.append(dest)
            self.fws.append(write)
            self.fws.append(run)
            self.fws.append(flag1)
            self.fws.append(delfail)
            self.fws.append(failflag)
            wf = Workflow(self.fws, {
                dest: [write],
                write: [run],
                run: [flag1],
                flag1: [delfail]
            },
                          name='Running ' + sim.name())
            self.launchpad.add_wf(wf)

        if n == 1:
            writetask = FileWriteTask({
                'files_to_write': ([{
                    'filename': sim.name(),
                    'contents': sim.inpFile()
                }]),
                'dest':
                path
            })
            runtask = ScriptTask.from_str(
                'redis-cli PUBLISH ' + User(userID).name() +
                '2 "Running Simulation"; mpiexec -n ' + cores + 'gkyl ' +
                path + sim.name())
            runFlag = ScriptTask.from_str('redis-cli PUBLISH ' +
                                          User(userID).name() + '2' + ' Done')
            deleteFail = ScriptTask.from_str('lpad defuse_fws -i ' +
                                             str(5 + self.last))
            flagFail = ScriptTask.from_str('redis-cli PUBLISH ' +
                                           User(userID).name() + '2' +
                                           ' Failed')
            self.ids.clear()
            write = Firework(writetask, name='Write', fw_id=1 + self.last)
            self.ids.append(1 + self.last)
            run = Firework(runtask, name='Run', fw_id=2 + self.last)
            self.ids.append(2 + self.last)
            flag1 = Firework(runFlag, name='done?', fw_id=3 + self.last)
            self.ids.append(3 + self.last)
            delfail = Firework(deleteFail,
                               name='remove fail flag',
                               fw_id=4 + self.last)
            self.ids.append(4 + self.last)
            failflag = Firework(flagFail,
                                name='fail flag',
                                fw_id=5 + self.last)
            self.ids.append(5 + self.last)
            wf = Workflow([write, run, flag1, delfail, failflag], {
                write: [run],
                run: [flag1],
                flag1: [delfail]
            },
                          name='Running ' + sim.name())
            self.launchpad.add_wf(wf)
예제 #26
0
 def add(self, id, command, **kwargs):
     '''Add a task to the dictionary of fireworks.'''
     name = kwargs.pop('name', 'unspecified_task')
     task = ScriptTask.from_str(command)
     firework = Firework(task, name=name, spec=self.spec)
     self.fireworks[id] = firework
예제 #27
0
"""
This code is described in the Workflow tutorial, https://materialsproject.github.io/fireworks/workflow_tutorial.html
"""

from fireworks import Firework, FWorker, LaunchPad, ScriptTask, Workflow
from fireworks.core.rocket_launcher import rapidfire

if __name__ == "__main__":
    # set up the LaunchPad and reset it
    launchpad = LaunchPad()
    # launchpad.reset('', require_password=False)

    # define four individual FireWorks used in the Workflow
    task1 = ScriptTask.from_str('echo "Ingrid is the CEO."')
    task2 = ScriptTask.from_str('echo "Jill is a manager."')
    task3 = ScriptTask.from_str('echo "Jack is a manager."')
    task4 = ScriptTask.from_str('echo "Kip is an intern."')

    fw1 = Firework(task1)
    fw2 = Firework(task2)
    fw3 = Firework(task3)
    fw4 = Firework(task4)

    # assemble Workflow from FireWorks and their connections by id
    workflow = Workflow([fw1, fw2, fw3, fw4], {fw1: [fw2, fw3], fw2: [fw4], fw3: [fw4]})

    # store workflow and launch it locally
    launchpad.add_wf(workflow)
    rapidfire(launchpad, FWorker())
예제 #28
0
    def run_task(self, fw_spec):

        directory = self.get("directory", os.getcwd())
        custodian = self.get("custodian", False)
        condition = self.get("condition", "energy") or "energy"
        tolerance = self.get(
            "tolerance", PulayTask.pulay_tolerance_dict[condition]
        ) or PulayTask.pulay_tolerance_dict[condition]

        perform_pulay_step = False

        if condition == "ionic_steps":

            vasprun = Vasprun(os.path.join(directory, "vasprun.xml"))

            if vasprun.nionic_steps > tolerance:
                print("Number of ionic steps of geometry optimization is more "
                      "than specified tolerance (" + str(tolerance) +
                      "). Performing another geometry optimization.")
                perform_pulay_step = True

        elif condition == "energy":

            vasprun = Vasprun(os.path.join(directory, "vasprun.xml"))

            ionic_energies = [step['e_wo_entrp'] for step in vasprun.ionic_steps]
            structure = vasprun.final_structure

            if abs(ionic_energies[-1] - ionic_energies[0]) / len(structure) \
                    > tolerance:
                print("Difference in energy per atom between first ionic step and "
                      "final ionic step is larger than specified tolerance (" +
                      str(tolerance) + "). Performing another geometry "
                                       "optimization.")
                perform_pulay_step = True

        elif condition == "lattice":

            # Check if the lattice vectors have changed significantly
            initial_structure = Structure.from_file(
                os.path.join(directory, "POSCAR")
            )
            final_structure = Structure.from_file(
                os.path.join(directory, "CONTCAR")
            )

            sum_differences = np.linalg.norm(
                initial_structure.lattice.matrix - final_structure.lattice.matrix
            )
            if sum_differences > tolerance:
                print("Lattice vectors have changed significantly during geometry "
                      "optimization. Performing another full geometry optimization "
                      "to make sure there were no Pulay stresses present.\n\n")
                perform_pulay_step = True

        if perform_pulay_step:

            tasks = list()

            # Change to quasi-Newton scheme
            incar = Incar.from_file(os.path.join(directory, "INCAR"))
            incar.update({"IBRION": 1})
            incar.write_file(os.path.join(directory, "INCAR"))

            # Create the ScriptTask that copies the CONTCAR to the POSCAR
            tasks.append(ScriptTask.from_str(
                "cp " + os.path.join(directory, "CONTCAR") +
                " " + os.path.join(directory, "POSCAR")
            ))

            # Run the calculation
            if custodian is True:
                tasks.append(VaspCustodianTask())
            elif isinstance(custodian, list):
                assert all([isinstance(h, ErrorHandler) for h in custodian]), \
                    "Not all elements in 'custodian' list are instances of " \
                    "the ErrorHandler class!"
                tasks.append(VaspCustodianTask(handlers=custodian))
            else:
                tasks.append(VaspTask())

            # Add the final geometry to the fw_spec of this firework and its children
            tasks.append(AddFinalGeometryToSpec(directory=directory))

            # Create the PyTask that check the Pulay stresses again
            tasks.append(PulayTask(
                directory=directory, custodian=custodian,
                condition=condition, tolerance=tolerance
            ))

            # Combine the two FireTasks into one FireWork
            optimize_fw = Firework(tasks=tasks,
                                   name="Pulay Step",
                                   spec=fw_spec)

            return FWAction(detours=optimize_fw)
예제 #29
0
"""
This code is described in the Workflow tutorial, https://materialsproject.github.io/fireworks/workflow_tutorial.html
"""

from fireworks import Firework, Workflow, FWorker, LaunchPad, ScriptTask
from fireworks.core.rocket_launcher import rapidfire

if __name__ == "__main__":
    # set up the LaunchPad and reset it
    launchpad = LaunchPad()
    # launchpad.reset('', require_password=False)

    # define four individual FireWorks used in the Workflow
    task1 = ScriptTask.from_str('echo "Ingrid is the CEO."')
    task2 = ScriptTask.from_str('echo "Jill is a manager."')
    task3 = ScriptTask.from_str('echo "Jack is a manager."')
    task4 = ScriptTask.from_str('echo "Kip is an intern."')

    fw1 = Firework(task1)
    fw2 = Firework(task2)
    fw3 = Firework(task3)
    fw4 = Firework(task4)

    # assemble Workflow from FireWorks and their connections by id
    workflow = Workflow([fw1, fw2, fw3, fw4], {fw1: [fw2, fw3], fw2: [fw4], fw3: [fw4]})

    # store workflow and launch it locally
    launchpad.add_wf(workflow)
    rapidfire(launchpad, FWorker())
예제 #30
0
    def run_task(self, fw_spec):
        """

        Args:
            fw_spec:

        Returns:
            FWAction

        """
        # Extract the parameters into variables; this makes for cleaner code IMO
        directory = self["directory"]
        in_custodian = self.get("in_custodian", False)
        number_nodes = self.get("number_nodes", None)
        tolerance = self.get("tolerance", PulayTask.pulay_tolerance)
        fw_action = self.get('fw_action', {})

        # Check if the lattice vectors have changed significantly
        initial_structure = Structure.from_file(
            os.path.join(directory, "POSCAR"))
        final_structure = Structure.from_file(
            os.path.join(directory, "CONTCAR"))

        sum_differences = np.linalg.norm(initial_structure.lattice.matrix -
                                         final_structure.lattice.matrix)

        # If the difference is small, return an empty FWAction
        if sum_differences < tolerance:
            return FWAction.from_dict(fw_action)

        # Else, set up another geometry optimization
        else:
            print(
                "Lattice vectors have changed significantly during geometry "
                "optimization. Performing another full geometry optimization to "
                "make sure there were no Pulay stresses present.\n\n")

            # Create the ScriptTask that copies the CONTCAR to the POSCAR
            copy_contcar = ScriptTask.from_str(
                "cp " + os.path.join(directory, "CONTCAR") + " " +
                os.path.join(directory, "POSCAR"))

            # Create the PyTask that runs the calculation
            if in_custodian:
                vasprun = CustodianTask(directory=directory)
            else:
                vasprun = VaspTask(directory=directory)

            # Create the PyTask that check the Pulay stresses again
            pulay_task = PulayTask(directory=directory,
                                   in_custodian=in_custodian,
                                   number_nodes=number_nodes,
                                   tolerance=tolerance,
                                   fw_action=fw_action)

            # Add number of nodes to spec, or "none"
            firework_spec = {"_launch_dir": os.getcwd()}
            if number_nodes is None:
                firework_spec.update({"_category": "none"})
            else:
                firework_spec.update(
                    {"_category": str(number_nodes) + "nodes"})

            # Combine the two FireTasks into one FireWork
            relax_firework = Firework(
                tasks=[copy_contcar, vasprun, pulay_task],
                name="Pulay Step",
                spec=firework_spec)

            return FWAction(additions=relax_firework)
예제 #31
0
 def setUp(self):
     self.mol_file = 'SiC_0.cif'
     self.config_file = os.path.join(test_dir, 'vasp_interface_defaults.yaml')
     self.input = VaspInputInterface(s=self.mol_file, config_file=self.config_file)
     self.misc_task = ScriptTask.from_str("echo 'Hello World!'")
예제 #32
0
parser = ArgumentParser(description="test")
parser.add_argument("--file_list",action="store",required=True)
parser.add_argument("--outdir",action="store",required=False)
parser.add_argument("--script",action="store",help='absolute path to script.py',required=False)
parser.add_argument("--cores",type=int,action="store",default='32',required=False)
parser.add_argument("--brick",action="store",default='2523p355',required=False)
parser.add_argument("--zoom",type=int,action="store",default='1600',required=False)
args = parser.parse_args()

launchpad= LaunchPad(host="mongodb01",name="tractor_fireworks",username="******",password="******")
launchpad.reset('', require_password=False)

fns= read_lines(args.file_list)
for cnt,fn in enumerate(fns):
    cmd="python sleep_on_it.py %d" % cnt #(args.script,fn)
    firetask= ScriptTask.from_str(cmd)
    firework= Firework(firetask, name=os.path.basename(fn))
    launchpad.add_wf(firework)
print 'added %d fireworks' % (len(fns))
#os.chdir(os.rundir)
#for i in range(ntasks):
#    outdir=os.path.join(args.outdir,"b%s_zm%d_task%d" % (args.brick,args.zoom,i))
#    #os.removedirs(outdir); os.makedirs(outdir); os.chdir(outdir); bash('ln -s %s legacypipe' % args.rundir)
#    name="task-"+str(i)
#    script="python legacypipe/runbrick.py \
#                --zoom 1 %d 1 %d \
#                --force-all --no-write \
#                --pipe \
#                --threads %d \
#                --skip \
#                --skip-calibs \
예제 #33
0
파일: nosier.py 프로젝트: adiv2/tf2jan
def processfile(runfile):
    """Function to process testopia run yaml file and create workflows, add them 
    to run in fireworks"""
    with open(runfile, 'r') as f:
        run_details = yaml.load(f)
    testcases = run_details['test_run']['cases']
    print 'testcases:\n'
    print testcases
    testcasetype = type(testcases)
    print testcasetype
    run_id = int(run_details['test_run']['run_id'])
    print run_id
    environment_id = int(run_details['test_run']['environment_id'])
    print environment_id
    tcms = Testopia.from_config('/var/dt/tf/etc/testopia.cfg')
    environment_details = tcms.environment_get(environment_id)
    print environment_details
    rundetailsfromtcms = tcms.testrun_get(run_id)
    product_version = rundetailsfromtcms['product_version']
    build_id = rundetailsfromtcms['build_id']
    buildinfo = tcms.build_get(build_id)
    print buildinfo
    build_name = buildinfo['name']
    print "build name: " + build_name
    print "product_version " + product_version
    environment_name = environment_details['name']
    print environment_name
    environment_file = '/var/dt/tf/etc/environments/' + environment_name + '.py'
    environment_filepyc = environment_file + 'c'
    if os.path.isfile(environment_filepyc):
        print "environment pyc file is present, deleting it"
        os.remove(environment_filepyc)
    else:
        print "No cached environment pyc file found"
    print environment_file
    testsonfire = []
    fwsequence = {}
    fwkey = ''
    fwvalue = ''
    for testcase in testcases.keys():
        case_id = int(testcase)
        testcase_name = run_details['test_run']['cases'][testcase]['summary']
        argsf = [
            run_id, case_id, build_id, environment_id, environment_name,
            environment_file, testcase_name, product_version, build_name
        ]
        fw_test = Firework(PyTask(func='HookFW.runCase', args=argsf))
        print "argsf are:"
        print argsf
        testsonfire.append(fw_test)
        if fwvalue:
            fwsequence[fwvalue] = fw_test
            fwvalue = fw_test
        else:
            fwvalue = fw_test

    #To be run as last firework in the workflow, to compile logs for the entire set of testcases

    rebotcmd = "cd /var/dt/tf/logs/" + str(
        run_id
    ) + '; rebot -N "DTTF" -R */*.xml; ln -s report.html index.html; echo ok '
    fw_test = Firework(ScriptTask.from_str(rebotcmd))
    testsonfire.append(fw_test)
    fwsequence[fwvalue] = fw_test
    print "tests on fire:"
    print testsonfire
    print "test sequence:"
    print fwsequence
    workflow = Workflow(testsonfire, fwsequence)
    launchpad = LaunchPad()
    launchpad.add_wf(workflow)
예제 #34
0
파일: example.py 프로젝트: olcf/athena
 def add(self, id, command, **kwargs):
     '''Add a task to the dictionary of fireworks.'''
     name = kwargs.pop('name', 'unspecified_task') 
     task = ScriptTask.from_str(command)
     firework = Firework(task, name=name, spec=self.spec) 
     self.fireworks[id] = firework