Setup and Storing Results¶
Here, we describe how to set up quacc with a database of your choosing.
You can store the output of quacc jobs and flows in your database of choice by defining a Maggma data store.
For instance, let's pretend you have decided to make a MongoStore be your database of choice. Instantiating that class might look like the following
from maggma.stores import MongoStore
store = MongoStore(
database="my_db_name",
collection_name="my_collection_name",
username="my_username",
password="my_password",
host="my_hostname",
port=27017,
)
Then, to store results in your database, you can use the following script:
from maggma.stores import MongoStore
from monty.json import jsanitize
# Let `results` be of type `list[dict]` containing outputs from quacc recipes
# Define your database details
store = MongoStore(
database="my_db_name",
collection_name="my_collection_name",
username="my_username",
password="my_password",
host="my_hostname",
port=27017,
)
# Store the results
sanitized_results = [
jsanitize(result, enum_values=True, recursive_msonable=True) for result in results
]
for result in sanitized_results:
result["uuid"] = str(uuid.uuid4())
with store:
store.update(sanitized_results, key="uuid")
Covalent automatically stores all the inputs and outputs in an SQLite database, which you can find at the "db_path" when you run covalent config, and the results can be queried using the ct.get_result(<dispatch ID>) syntax.
To use a database with Prefect, read the Database section of the Prefect documentation as well as how to persist results.
If you are using Jobflow to construct your workflows, it will automatically store the results in the database you defined during the setup process. No additional steps are needed.