Fully automate a cluster expansion#

We provide a simple example workflow to run automatic cluster expansion in a Ag-Li alloy on FCC lattice (see other available options in the documentations of preprocessing.py.):

from fireworks import LaunchPad
from jobflow.managers.fireworks import flow_to_workflow
from pymatgen.core import Structure

from WFacer.maker import AutoClusterExpansionMaker

# construct a rock salt Ag-Li structure
agli_prim = Structure(
    lattice=[[0, 2.13, 2.13], [2.13, 0, 2.13], [2.13, 2.13, 0]],
    species=[
        {"Ag": 0.5, "Li": 0.5},
        {"Ag": 0.5, "Li": 0.5},
    ],
    coords=[[0, 0, 0], [0.5, 0.5, 0.5]],
)
# Use default for every option.
ce_flow = AutoClusterExpansionMaker(name="agli_fcc_ce", options={}).make(agli_prim)

# convert the flow to a fireworks WorkFlow object
# If argument "store" is not specified, all documents will be saved to the JOB_STORE
# Defined by the local configuration files where you run THIS script from.
wf = flow_to_workflow(ce_flow)

# submit the workflow to the FireWorks launchpad
lpad = LaunchPad.auto_load()
lpad.add_wf(wf)

After running this script, a workflow with the name agli_fcc_ce should have appeared on Fireworks’ launchpad.

Make sure you have correctly configured Fireworks, Jobflow and atomate2, then submit the workflow to computing cluster by running the following command,

nohup qlaunch rapidfire -m {n_jobs} --sleep {time} > qlaunch.log

where n_jobs is the number of jobs you want to keep in queue, and time is the amount of sleep time in seconds between two queue submission attempts. qlaunch will keep submitting jobs to the queue until no job in the READY state could be found on launchpad.

Note

You may still need to qlaunch manually after every cluster expansion iteration because for Fireworks could occasionally set the enumeration job to the READY state but fails to continue executing the job.

After finishing, use the following code to query the computation results from MongoDB,

Note

Check that the Jobflow installations on the computer cluster and the query terminal are configured to use the same JOB_STORE.

from jobflow import SETTINGS
from pydantic import parse_obj_as

from WFacer.schema import CeOutputsDocument

store = SETTINGS.JOB_STORE
store.connect()

# Just a random example. You have to check what is your maximum iteration on your own.
max_iter = 10
# Find the output of a trigger job, which should be the CeOutputDocument of the final
# iteration.
job_return = store.query_one({"name": f"agli_fcc_ce_iter_{max_iter}_trigger"})
raw_doc = job_return["output"]
# De-serialize everything.
doc = parse_obj_as(CeOutputsDocument, raw_doc)

# See WFacer.schema for more.
print("Cluster subspace:", doc.cluster_subspace)
print("Wrangler:", doc.data_wrangler)
print("coefficients:", doc.coefs_history[-1])