How to use the fireworks.LaunchPad function in FireWorks

To help you get started, we’ve selected a few FireWorks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hackingmaterials / rocketsled / old / examples / ABC_task / test_code.py View on Github external
from ABC_workflow_creator import workflow_creator
from fireworks.core.rocket_launcher import rapidfire
from fireworks import FWorker, LaunchPad
from turboworks.optdb import OptDB
from fireworks.core.rocket_launcher import launch_rocket
import matplotlib.pyplot as plt

"""
This is the top level script for this turboworks example, and is used primarily for debugging/tuning.
"""

launchpad = LaunchPad()
manageDB = OptDB()

# Sample data
A = 50
B = 50
C = 50
input1 = {"A":A, "B":B, "C":C}
dimensions = {"A_range":(1,100),"B_range":(1,100), "C_range":(1,100)}

# Define the initial input
input_dict = {'input':input1, 'dimensions':dimensions}

# How many times to run the workflow + optimization loop
run_num = 30

# Or dynamically call till within a max_val
github hackingmaterials / rocketsled / turboworks / testing_vector.py View on Github external
dimensions = [(1,100), (1,100), (1,100)]
    spec = {'A':inputs[0], 'B':inputs[1], 'C':inputs[2], 'dimensions':dimensions}

    ft1 = CalculateTask()
    ft2 = OptimizeTaskFromVector(workflow_creator)
    firework = Firework([ft1, ft2], spec=spec)


if __name__ == "__main__":
    # mdb = ManageDB()
    # mdb.nuke()

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

    # create the Firework consisting of a single task
    print type(OptimizeTaskFromVector)
    ft1 = OptimizeTaskFromVector(input = [1,2,3,4])
    fw1 = Firework(ft1)
    launchpad.add(fw1)
    launch_rocket(launchpad)
github materialsproject / mpmorph / mpmorph / workflow / old_temp_mdtasks.py View on Github external
def run_task(self, fw_spec):
        copy_calcs = self["copy_calcs"]
        calc_home = self["calc_home"]
        n = self.get("n_snapshots", 1)
        priority_spec = self.get("priority_spec", {})

        current_dir = os.getcwd()
        xdatcar_file = os.path.join(current_dir, 'XDATCAR')
        wfs = get_wf_structure_sampler(xdatcar_file=xdatcar_file, sim_anneal=True, copy_calcs=copy_calcs,
                                       calc_home=calc_home, n=10, db_file=None, priority_spec=priority_spec)
        lp = LaunchPad.auto_load()
        for _wf in wfs:
            lp.add_wf(_wf)
        return FWAction()
github hackingmaterials / rocketsled / rocketsled / examples / basic.py View on Github external
However, FireWorks and rocketsled are capable of handling more complex
workflows including multiple jobs and advanced dependencies. Please see the
complex example, or the Fireworks and rocketsled documentation pages for more
information:

https://hackingmaterials.github.io/rocketsled/
https://materialsproject.github.io/fireworks/
"""
from fireworks import FireTaskBase, Firework, FWAction, LaunchPad, Workflow
from fireworks.core.rocket_launcher import rapidfire
from fireworks.utilities.fw_utilities import explicit_serialize

from rocketsled import MissionControl, OptTask

# Setting up the FireWorks LaunchPad
launchpad = LaunchPad(name="rsled")
opt_label = "opt_default"
db_info = {"launchpad": launchpad, "opt_label": opt_label}

# We constrain our dimensions to 3 integers, each between 1 and 5
x_dim = [(1, 5), (1, 5), (1, 5)]


@explicit_serialize
class ObjectiveFuncTask(FireTaskBase):
    """
    An example task which just evaluates the following simple function:

    f(x) = x[0] * x[1] / x[2]

    Replace this code with your objective function if your objective function
    is relatively simple (i.e., only needs one Firework).
github hackingmaterials / rocketsled / old / perovskites / turboworks_implementation.py View on Github external
# Return a workflow
        new_fw = Firework([CalculateTask(), SkoptimizeTask()], spec=self.tw_spec)
        return FWAction(additions=new_fw)





if __name__ == "__main__":

    # mdb = ManageDB()
    # mdb.nuke()

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

    fw_spec = ref_dict

    # create the Firework consisting of a single task
    firetask1 = CalculateTask()
    firetask2 = SkoptimizeTask()

    # firework = Firework([firetask1, firetask2], spec=fw_spec)
    firework = Firework([CalculateTask(), SkoptimizeTask()],  spec=fw_spec)
    # _store workflow and launch it locally
    launchpad.add_wf(firework)


    # Repeatedly execute the optimization loop
    for i in range(1):
github henniggroup / MPInterfaces / examples / workflows / slab_workflow.py View on Github external
hkls = [[1,0,0], [1,1,0], [1,1,1]]
    workflows = []

    for i, sp in enumerate(species):
        structure = get_struct_from_mp(sp, MAPI_KEY="dwvz2XCFUEI9fJiR")
        #primitive --> conventional cell
        sa = SpacegroupAnalyzer(structure)
        structure_conventional = sa.get_conventional_standard_structure()
        structure = structure_conventional.copy()
        structure.sort()
        for j, hkl in enumerate(hkls):
            workflows.append( get_workflow(structure, hkl, wf_id=100*(i+1)+10*j) )
        
    # connect to the fireworks database and add workflow to it
    # use your own account
    launchpad = LaunchPad.from_file(LAUNCHPAD_LOC)

    print('fireworks in the database before adding the workflow: \n',
        launchpad.get_fw_ids())

    for wf in workflows:
        launchpad.add_wf(wf, reassign_all=False)

    wfs = launchpad.get_wf_ids()
    pp = pprint.PrettyPrinter(indent=4)
    for i,fw_id in enumerate(wfs):
        print('Workflow: {}'.format(i+1))
        pp.pprint(launchpad.get_wf_summary_dict(fw_id))
        print('\n')
    print('Total number of workflows in the database: \n', len(wfs))
    print('Total number of fireworks in the database: \n', len(launchpad.get_fw_ids()))
github hackingmaterials / rocketsled / rocketsled / benchmarks / auto_for_bench.py View on Github external
"name='RocketsledFW')\n")
                f.write("    wf = Workflow([fw0, fw1], {fw0: [fw1], fw1: []},"
                        " name='" + wfname + pointstr + ")\n")
                f.write("    return wf\n")
                f.write("\n\nif __name__=='__main__': \n\n")
                f.write("    # Make sure the launchpad below is correct, and "
                        "make changes if necessary if\n    # it does not match "
                        "the OptTask db ^^^:\n")
                if all(s in kwargs for s in ['host', 'port', 'name']):
                    h = kwargs['host']
                    p = kwargs['port']
                    n = kwargs['name']
                    f.write("    lpad = LaunchPad(host='{}', port={}, "
                            "name='{}')\n".format(h, p, n))
                elif 'lpad' in kwargs:
                    if isinstance(kwargs['lpad'], LaunchPad):
                        lpad = kwargs['lpad'].to_dict()
                    else:
                        lpad = kwargs['lpad']
                    f.write("    lpad = LaunchPad.from_dict(" + lpad + ")\n")
                else:
                    f.write("    lpad = LaunchPad.auto_load()\n")
                f.write("    # lpad.reset(password=None, require_password=False"
                        ")\n")
                f.write("\n    # Define your workflow to start...\n")
                f.write("    wf1 = wf_creator(random_guess(" + str(dimensions) +
                        "))\n\n")
                f.write("    # Add it to the launchpad and launch!\n")
                f.write("    lpad.add_wf(wf1)\n")
                if launch_ready:
                    f.write("    rapidfire(lpad, nlaunches=5, sleep_time=0)")
                else:
github materialsproject / fireworks / fireworks / scripts / lpad_run.py View on Github external
def get_lp(args):
    # TODO add a launchpad_type argument to determine which type of lpad
    # is to be initialized
    try:
        if not args.launchpad_file and os.path.exists(os.path.join(args.config_dir, DEFAULT_LPAD_YAML)):
            args.launchpad_file = os.path.join(args.config_dir, DEFAULT_LPAD_YAML)

        if args.launchpad_file:
            return LaunchPad.from_file(args.launchpad_file)
        else:
            args.loglvl = 'CRITICAL' if args.silencer else args.loglvl
            return LaunchPad(logdir=args.logdir, strm_lvl=args.loglvl)
    except:
        traceback.print_exc()
        err_message = 'FireWorks was not able to connect to MongoDB. Is the server running? ' \
                      'The database file specified was {}.'.format(args.launchpad_file)
        if not args.launchpad_file:
            err_message += ' Type "lpad init" if you would like to set up a file that specifies ' \
                           'location and credentials of your Mongo database (otherwise use default ' \
                           'localhost configuration).'
        raise ValueError(err_message)
github hackingmaterials / atomate / matmethods / vasp / examples / add_vasp_wfs_to_db.py View on Github external
from fireworks import LaunchPad
from matmethods.vasp.examples.vasp_workflows import get_wf_bandstructure_Vasp
from matmethods.vasp.vasp_powerups import decorate_write_name
from pymatgen import Structure

__author__ = 'Anubhav Jain '


if __name__ == "__main__":
    struct_si = {u'lattice': {u'a': 3.839943374653261, u'c': 3.83994338, u'b': 3.839943378813096, u'matrix': [[3.32548851, 0.0, 1.91997169], [1.10849617, 3.13530064, 1.91997169], [0.0, 0.0, 3.83994338]], u'volume': 40.036809671145996, u'beta': 59.99999995393976, u'gamma': 60.00000000512866, u'alpha': 59.99999998977525}, u'sites': [{u'abc': [0.875, 0.875, 0.875], u'xyz': [3.879736595, 2.74338806, 6.719900914999999], u'label': u'Si', u'species': [{u'occu': 1, u'element': u'Si'}]}, {u'abc': [0.125, 0.125, 0.125], u'xyz': [0.554248085, 0.39191258, 0.959985845], u'label': u'Si', u'species': [{u'occu': 1, u'element': u'Si'}]}], u'@class': 'Structure', u'@module': 'pymatgen.core.structure'}#struct_al =
    struct_al = {u'lattice': {u'a': 2.8765103857767107, u'c': 2.87651039, u'b': 2.876510387621576, u'matrix': [[2.49113107, 0.0, 1.43825519], [0.83037702, 2.3486609, 1.43825519], [0.0, 0.0, 2.87651039]], u'volume': 16.82995067829534, u'beta': 60.000000066431895, u'gamma': 60.0000001318988, u'alpha': 60.00000008764776}, u'sites': [{u'abc': [0.0, 0.0, 0.0], u'xyz': [0.0, 0.0, 0.0], u'label': u'Al', u'species': [{u'occu': 1, u'element': u'Al'}]}], u'@class': 'Structure', u'@module': 'pymatgen.core.structure'}
    struct_fe2o3 = {u'lattice': {u'a': 5.08889296704748, u'c': 5.088892940235904, u'b': 5.433876369359943, u'matrix': [[-1.63726303, -4.20120808, 2.3592482], [1.60869519, 4.18168075, 3.07451757], [-2.87170368, 4.20120808, 0.0]], u'volume': 102.51695391433915, u'beta': 119.99999825324359, u'gamma': 117.92116960555998, u'alpha': 62.078837305387026}, u'sites': [{u'abc': [0.35372165, 0.06116494, 0.64627835], u'xyz': [-2.336659551680289, 1.484863824071041, 1.0225698487615258], u'label': u'Fe', u'species': [{u'occu': 1, u'element': u'Fe'}]}, {u'abc': [0.14627835, 0.43883506, 0.85372165], u'xyz': [-1.9851798883197114, 4.807184630928958, 1.6943130362384742], u'label': u'Fe', u'species': [{u'occu': 1, u'element': u'Fe'}]}, {u'abc': [0.64628007, 0.93884022, 0.35371993], u'xyz': [-0.5636015442146127, 2.6968240512458337, 4.41121584365604], u'label': u'Fe', u'species': [{u'occu': 1, u'element': u'Fe'}]}, {u'abc': [0.85371993, 0.56115978, 0.14628007], u'xyz': [-0.9151020557853873, -0.6255110062458334, 3.7394328113439608], u'label': u'Fe', u'species': [{u'occu': 1, u'element': u'Fe'}]}, {u'abc': [0.55410064, 0.75, 0.05410064], u'xyz': [0.14395189275030562, 1.0356565224999998, 3.613149115038848], u'label': u'O', u'species': [{u'occu': 1, u'element': u'O'}]}, {u'abc': [0.25, 0.75, 0.44589936], u'xyz': [-0.4832851980216448, 3.959274536598829, 2.8957002275], u'label': u'O', u'species': [{u'occu': 1, u'element': u'O'}]}, {u'abc': [0.05402801, 0.25, 0.25], u'xyz': [-0.4042101858574703, 1.8687392953416793, 0.896094877842082], u'label': u'O', u'species': [{u'occu': 1, u'element': u'O'}]}, {u'abc': [0.75, 0.25, 0.55402801], u'xyz': [-2.416777750140077, 0.22210107965832115, 2.5380655425], u'label': u'O', u'species': [{u'occu': 1, u'element': u'O'}]}, {u'abc': [0.44597199, 0.25, 0.94597199], u'xyz': [-3.0445508990024526, 3.1460242275, 1.820788007157918], u'label': u'O', u'species': [{u'occu': 1, u'element': u'O'}]}, {u'abc': [0.94589936, 0.75, 0.75], u'xyz': [-2.495942419728661, 2.3132465884011713, 4.537499539961152], u'label': u'O', u'species': [{u'occu': 1, u'element': u'O'}]}], u'@class': 'Structure', u'@module': 'pymatgen.core.structure'}

    lp = LaunchPad.auto_load()

    for s in [struct_si, struct_al, struct_fe2o3]:
        wf = get_wf_bandstructure_Vasp(Structure.from_dict(s), vasp_input_set=None, vasp_cmd=">>vasp_cmd<<",
                                       db_file=">>db_file<<", custodian_powerup=True)
        wf = decorate_write_name(wf)
        lp.add_wf(wf)
github hackingmaterials / rocketsled / rocketsled / benchmarks / ALEXGRAPHER.py View on Github external
def schaffer(x):
    return 0.5 + ((math.sin(x[0]**2 - x[1]**2))**2 - 0.5)/\
           ((1.0 + .001 * (x[0]**2 + x[1]**2)) ** 2)


if __name__ == "__main__":

    # BRANIN 2D RF
    # dim = [(-5.0, 10.0), (0.0, 15.0)] # branin
    # # for i in range(100):
    # #     auto_setup(branin, dim, wfname='bran{}'.format(i), opt_label='ei{}'.format(i), host='localhost', acq='ei', name='bran', port=27017, n_bootstraps=1000, predictor="RandomForestRegressor", n_search_points=10000)
    #
    # # ranx, rany = ran_run(branin, dim, min, runs=10000, comps_per_run=50)
    # pd.DataFrame({'x': ranx, 'y': rany}).to_csv("ran_bran.csv")
    lpad = LaunchPad(host='localhost', port=27017, name='bran')
    df = pd.DataFrame.from_csv("ran_bran.csv")
    ranx = df['x']
    rany = df['y']
    hi_runs = [getattr(lpad.db, "ei{}".format(i)) for i in range(100)]
    bm, bs = visualize([hi_runs], min, labels=['EI'], colors=['blue'], limit=50)
    plt.plot(ranx, rany, color='black')
    print "BEST RANDOM", min(rany)
    print "BEST OPT", bm, "+-", bs
    plt.show()