本文整理汇总了Python中fireworks.LaunchPad类的典型用法代码示例。如果您正苦于以下问题:Python LaunchPad类的具体用法?Python LaunchPad怎么用?Python LaunchPad使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LaunchPad类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args, **kwargs):
super(OptTask, self).__init__(*args, **kwargs)
# Configuration attrs
lp = self.get("launchpad", LaunchPad.auto_load())
if isinstance(lp, LaunchPad):
lp = lp.to_dict()
self.lpad = LaunchPad.from_dict(lp)
self.opt_label = self.get("opt_label", "opt_default")
self.c = getattr(self.lpad.db, self.opt_label)
self.config = self.c.find_one({"doctype": "config"})
if self.config is None:
raise NotConfiguredError("Please use MissionControl().configure to "
"configure the optimization database "
"({} - {}) before running OptTask."
"".format(self.lpad.db, self.opt_label))
self.wf_creator = deserialize(self.config["wf_creator"])
self.x_dims = self.config["dimensions"]
self._xdim_types = self.config["dim_types"]
self.is_discrete_all = self.config["is_discrete_all"]
self.is_discrete_any = self.config["is_discrete_any"]
self.wf_creator_args = self.config["wf_creator_args"] or []
self.wf_creator_kwargs = self.config["wf_creator_kwargs"] or {}
self.predictor = self.config["predictor"]
self.predictor_args = self.config["predictor_args"] or []
self.predictor_kwargs = self.config["predictor_kwargs"] or {}
self.maximize = self.config["maximize"]
self.n_search_pts = self.config["n_search_pts"]
self.n_train_pts = self.config["n_train_pts"]
self.n_bootstraps = self.config["n_bootstraps"]
self.acq = self.config["acq"]
self.space_file = self.config["space_file"]
self.onehot_categorical = self.config["onehot_categorical"]
self.duplicate_check = self.config["duplicate_check"]
self.get_z = self.config["get_z"]
if self.get_z:
self.get_z = deserialize(self.config['get_z'])
else:
self.get_z = lambda *ars, **kws: []
self.get_z_args = self.config["get_z_args"] or []
self.get_z_kwargs = self.config["get_z_kwargs"] or {}
self.z_file = self.config["z_file"]
self.enforce_sequential = self.config["enforce_sequential"]
self.tolerances = self.config["tolerances"]
self.batch_size = self.config["batch_size"]
self.timeout = self.config["timeout"]
# Declared attrs
self.n_objs = None
plist = [RandomForestRegressor, GaussianProcessRegressor,
ExtraTreesRegressor, GradientBoostingRegressor]
self.builtin_predictors = {p.__name__: p for p in plist}
self._n_cats = 0
self._encoding_info = []
# Query formats
self._completed = {'x': {'$exists': 1}, 'y': {'$exists': 1,
'$ne': 'reserved'},
'z': {'$exists': 1}}
self._manager = {'lock': {'$exists': 1}, 'queue': {'$exists': 1}}
示例2: lp
def lp(request):
lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
lp.reset(password=None, require_password=False)
def fin():
lp.connection.drop_database(TESTDB_NAME)
request.addfinalizer(fin)
return lp
示例3: __init__
def __init__(self, *args, **kwargs):
'''
:param args: (VaspFirework objects) objects to create Workflow from. No limit
on the amount of VaspInputInterface objects to be given. Entered as just
comma separated objects passed to class.
:param deps_dict: (dict) specifies the dependency of the VaspInputInterface objects given.
If no dependency is given, Firworks are assumed to be
sequentially dependent.
:param name (str) Name given to Workflow
'''
self.fws = []
self.name = kwargs.get('name', 'Sequential WF')
self.deps_dict = kwargs.get('deps_dict', {})
self.dependency = {}
if self.deps_dict:
for i in self.deps_dict.keys():
fw_deps = []
for j in self.deps_dict[i]:
fw_deps.append(j.Firework)
self.dependency[i.Firework]=fw_deps
self.deps = True if self.dependency else False
for id, fw_task in enumerate(args):
self.fws.append(fw_task.Firework)
if not self.deps and id != 0:
self.dependency[self.fws[id-1]]=[fw_task.Firework]
self.wf = Workflow(self.fws, self.dependency, name=self.name)
# Try to establish connection with Launchpad
try:
self.LaunchPad=LaunchPad.from_file(os.path.join(os.environ["HOME"], ".fireworks", "my_launchpad.yaml"))
except:
self.LaunchPad = None
示例4: test_get_lp_and_fw_id_from_task
def test_get_lp_and_fw_id_from_task(self):
"""
Tests the get_lp_and_fw_id_from_task. This test relies on the fact that the LaunchPad loaded from auto_load
will be different from what is defined in TESTDB_NAME. If this is not the case the test will be skipped.
"""
lp = LaunchPad.auto_load()
if not lp or lp.db.name == TESTDB_NAME:
raise unittest.SkipTest("LaunchPad lp {} is not suitable for this test. Should be available and different"
"from {}".format(lp, TESTDB_NAME))
task = LpTask()
# this will pass the lp
fw1 = Firework([task], spec={'_add_launchpad_and_fw_id': True}, fw_id=1)
# this will not have the lp and should fail
fw2 = Firework([task], spec={}, fw_id=2, parents=[fw1])
wf = Workflow([fw1, fw2])
self.lp.add_wf(wf)
rapidfire(self.lp, self.fworker, m_dir=MODULE_DIR, nlaunches=1)
fw = self.lp.get_fw_by_id(1)
assert fw.state == "COMPLETED"
rapidfire(self.lp, self.fworker, m_dir=MODULE_DIR, nlaunches=1)
fw = self.lp.get_fw_by_id(2)
assert fw.state == "FIZZLED"
示例5: launch
def launch():
descr = "Smart rocket launcher."\
"Uses the execution termination emails send by the batch system to "\
"launch fireworks that depend on other fireworks i.e fireworks that "\
"have 'cal_objs' in their spec."\
"Takes in fw_ids of fireworks to be launched. "\
"Range specification of fw_ids is also supported."\
"All the jobs are launched to hipergator remotely using fabric."\
"Note: Ensure that the submit scripts have the appropriate email settings and "\
"that the mail daemon is fetching emails to the folder polled by this script."\
"Note: All rocket launches take place in the home directory. If "\
"_launch_dir spec is set for the firework the job files will be written to "\
"that folder and jobs to the batch system will be done from there."
parser = ArgumentParser(description=descr)
parser.add_argument('-f', '--fw_ids', help='one or more of fw_ids to run',
default=None, type=int, nargs='+')
parser.add_argument('-r', '--r_fw_ids',
help='start and end fw_ids of the range of fw_ids to run',
default=None, type=int, nargs=2)
args = parser.parse_args()
fw_ids = args.fw_ids
if args.r_fw_ids is not None:
fw_ids += range(args.r_fw_ids[0], args.r_fw_ids[1])
job_ids = None
lp = LaunchPad.from_file(LAUNCHPAD_LOC)
print('Firework ids: ',fw_ids)
if fw_ids is None:
print('No fw ids given')
return
for fid in fw_ids:
m_fw = lp._get_a_fw_to_run(fw_id=fid, checkout=False)
if m_fw is None:
print('No firework with that id')
return
fw_spec = dict(m_fw.spec)
done = []
if fw_spec.get('cal_objs',None) is not None:
for calparams in fw_spec['cal_objs']:
if calparams.get('job_ids', None) is not None:
job_ids = calparams.get('job_ids', None)
print(fid,' depends on jobs with ids : ',job_ids)
if job_ids is not None:
for jid in job_ids:
done.append(check_done(jid))
else:
print('job_ids not set')
else:
print('This firework doesnt depend on any other fireworks.')
done.append(True)
if done and all(done):
print('Launching ', fid, ' ...')
with settings(host_string='[email protected]'):
run("ssh dev1 rlaunch singleshot -f "+str(fid))
else:
print("Haven't recieved execution termination confirmation for the jobs in the firework from hipergator resource manager")
time.sleep(3)
return
示例6: setUp
def setUp(self):
if os.path.exists(self.scratch_dir):
shutil.rmtree(self.scratch_dir)
os.makedirs(self.scratch_dir)
os.chdir(self.scratch_dir)
try:
self.lp = LaunchPad.from_file(os.path.join(db_dir, "my_launchpad.yaml"))
self.lp.reset("", require_password=False)
except:
raise unittest.SkipTest(
'Cannot connect to MongoDB! Is the database server running? '
'Are the credentials correct?')
示例7: main
def main():
# set up the LaunchPad and reset it
launchpad = LaunchPad()
launchpad.reset('', require_password=False)
# Build the flow
nflows = 2
for i in range(nflows):
flow = build_flow("flow_" + str(i))
flow.build_and_pickle_dump()
# create the Firework consisting of a single task
firework = Firework(FireTaskWithFlow(flow=flow))
# store workflow
launchpad.add_wf(firework)
#launch it locally
#launch_rocket(launchpad)
return 0
示例8: setUp
def setUp(self, lpad=True):
"""
Create scratch directory(removes the old one if there is one) and change to it.
Also initialize launchpad.
"""
if not SETTINGS.get("PMG_VASP_PSP_DIR"):
SETTINGS["PMG_VASP_PSP_DIR"] = os.path.abspath(os.path.join(MODULE_DIR, "..", "vasp", "test_files"))
print('This system is not set up to run VASP jobs. '
'Please set PMG_VASP_PSP_DIR variable in your ~/.pmgrc.yaml file.')
self.scratch_dir = os.path.join(MODULE_DIR, "scratch")
if os.path.exists(self.scratch_dir):
shutil.rmtree(self.scratch_dir)
os.makedirs(self.scratch_dir)
os.chdir(self.scratch_dir)
if lpad:
try:
self.lp = LaunchPad.from_file(os.path.join(DB_DIR, "my_launchpad.yaml"))
self.lp.reset("", require_password=False)
except:
raise unittest.SkipTest('Cannot connect to MongoDB! Is the database server running? '
'Are the credentials correct?')
示例9: LaunchPad
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)
示例10: LaunchPad
"""
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)
示例11: open
from fireworks.core.firework import FireTaskBase
from fireworks.scripts.rlaunch_run import launch_multiprocess
from fireworks.utilities.fw_utilities import explicit_serialize
from fw_tutorials.firetask.addition_task import AdditionTask
from rocketsled import OptTask, MissionControl
from rocketsled.utils import ExhaustedSpaceError
__author__ = "Alexander Dunn"
__email__ = "[email protected]"
lp_filedir = os.path.dirname(os.path.realpath(__file__))
with open(lp_filedir + '/tests_launchpad.yaml', 'r') as lp_file:
yaml = YAML()
lp_dict = dict(yaml.load(lp_file))
launchpad = LaunchPad.from_dict(lp_dict)
opt_label = "test"
db_info = {"launchpad": launchpad, "opt_label": opt_label}
test_db_name = launchpad.db
common_kwargs = {"predictor": "RandomForestRegressor", "acq": None}
@explicit_serialize
class BasicTestTask(FireTaskBase):
_fw_name = "BasicTestTask"
def run_task(self, fw_spec):
x = fw_spec['_x']
y = np.sum(x[:-1]) # sum all except the final string element
return FWAction(update_spec={'_y': y})
示例12: range
'KPOINTS': [k for k in range(20, 30, 10)]
}
job_dir = 'calBulk'
job_cmd = ['mpirun', '/home/km468/Software/VASP/vasp.5.3.5/vasp']
qparams= dict(nnodes='1', ppnode='16',
job_name='vasp_job', pmem='1000mb',
walltime='24:00:00',
rocket_launch=''.join(job_cmd))
# set qadapter to None to launch via qlaunch
# reserve and launch offline
# qlaunch -r singleshot
# lpad recover_offline
qadapter = None #CommonAdapter(q_type="PBS",**qparams)
cal = Calibrate(incar, poscar, potcar, kpoints,
turn_knobs = turn_knobs,
qadapter = qadapter,
job_dir = job_dir, job_cmd=job_cmd)
caltask = MPINTCalibrateTask(cal.as_dict())
#firework with launch directory set to $FW_JOB_DIR, an environment variable
#spec={'_launch_dir':'$FW_JOB_DIR'},
fw_calibrate = Firework([caltask],
name="fw_test")
wf = Workflow([fw_calibrate], name="mpint_wf_test")
lp = LaunchPad.from_file(LAUNCHPAD_LOC)
print('fireworks in the database before adding the workflow: \n',
lp.get_fw_ids())
lp.add_wf(wf)
print('fireworks in the database: \n', lp.get_fw_ids())
示例13: types
objective function is multi-objective. Additionally, the objective function
has dimensions of differing data types (int, float, categorical), which is
automatically handled by rocketsled as long as the dimensions are passed into
MissionControl.configure(...).
Finally, we add some arguments to the MissionControl configuration before
launching.
"""
from fireworks.utilities.fw_utilities import explicit_serialize
from fireworks.core.rocket_launcher import rapidfire
from fireworks import Workflow, Firework, LaunchPad, FireTaskBase, FWAction
from rocketsled import OptTask, MissionControl
launchpad = LaunchPad(name='rsled')
opt_label = "opt_complex"
db_info = {"launchpad": launchpad, "opt_label": opt_label}
x_dim = [(16, 145), (0.0, 90.0),
["industry standard", "shark fin", "dolphin fin"]]
@explicit_serialize
class ComplexMultiObjTask(FireTaskBase):
"""
An example of a complex, multiobjective task with directly competing
objectives. The input vector is defined on a search space with numerical
and categorical inputs.
This task accepts a 3-vector of the form [int, float, str].
"""
示例14: get_wf_density
"""
# Parameters:
box_scale = 8.9 # edge length of MD box in Angstroms, can also be a numpy array that scales the lattice
packmol_path = "~/packmol/packmol/packmol" # Revise as appropriate
structure = {'H2O':20} # "structure" in this context can be a dict of number of atoms or molecules.
temperature = 320
# Note one can use a pymatgen Structure object also
# E.g. p = Poscar.from_file("POSCAR")
# structure = p.structure
copy_calcs = True # MD runs can be backed up in a desired location
calc_home = '~/test_H2O_wflows' # This is the location to copy the calculations if copy_calcs=True
# Since we specified a molecule, we must also give the path to xyz
# file of a single sample molecule.
xyz_paths = ['H2O.xyz']
name = 'H2O_df_'+str(temperature)
from mpmorph.workflow.workflows import get_wf_density
from fireworks import LaunchPad
amorphous_maker_params = {'box_scale':box_scale, 'packmol_path':packmol_path, 'xyz_paths': xyz_paths, 'tol': 2.0}
wf = get_wf_density(structure, temperature=temperature, pressure_threshold=0.5, nsteps=1000, wall_time=19200, max_rescales=5,
amorphous_maker_params=amorphous_maker_params, copy_calcs=copy_calcs, calc_home=calc_home, name=name)
lp = LaunchPad.auto_load()
lp.add_wf(wf)
示例15: TaskB
@explicit_serialize
class TaskB(FireTaskBase):
def run_task(self, fw_spec):
print("This is task B")
return FWAction(update_spec={"param_B": 20})
@explicit_serialize
class TaskC(FireTaskBase):
def run_task(self, fw_spec):
print("This is task C.")
print("Task A gave me: {}".format(fw_spec["param_A"]))
print("Task B gave me: {}".format(fw_spec["param_B"]))
if __name__ == "__main__":
# set up the LaunchPad and reset it
launchpad = LaunchPad()
# launchpad.reset('', require_password=False)
fw_A = Firework([TaskA()])
fw_B = Firework([TaskB()])
fw_C = Firework([TaskC()], parents=[fw_A, fw_B])
# assemble Workflow from FireWorks and their connections by id
workflow = Workflow([fw_A, fw_B, fw_C])
# store workflow and launch it locally
launchpad.add_wf(workflow)
rapidfire(launchpad)