Automating alphaMELTS runs

pyrolite includes some utilities to help you run alphaMELTS with a little less hassle, especially for established workflows or repetitive calculations. Here we run multiple experiments at different conditions for a single MORB composition. Once we have the data in a DataFrame, we configure the default alphaMELTS environment before running the batch of experiments.

import os
import sys
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from pyrolite_meltsutil.automation import MeltsBatch
from pyrolite_meltsutil.util.synthetic import isobaricGaleMORBexample

MORB = isobaricGaleMORBexample(title="Gale2013MORB")
MORB.T
0
SiO2 50.41
Al2O3 14.95
FeO 10.07
MnO 0.173
MgO 7.69
CaO 11.35
Na2O 2.76
TiO2 1.54
K2O 0.144
P2O5 0.169
Title Gale2013MORB
Initial Temperature 1300
Final Temperature 800
Initial Pressure 5000
Final Pressure 5000
Log fO2 Path FMQ
Increment Temperature -5
Increment Pressure 0


from pyrolite_meltsutil.env import MELTS_Env

env = MELTS_Env()
env.VERSION = "MELTS"
env.MODE = "isobaric"
env.MINP = 5000
env.MAXP = 10000
env.MINT = 500
env.MAXT = 1500
env.DELTAT = -10
env.DELTAP = 0

Let’s create a directory to run this experiment in - here we use an example folder:

from pyrolite_meltsutil.util.general import get_data_example

experiment_dir = get_data_example("batch")

Now we can set up the experiment. We’re going to run a MeltsBatch, and we’ll provide:

  • The dataframe of compositions

  • The default configuration

  • The configuration grid with lists of parameter values - which overrides the default.

  • The MELTS_Env or environment file to be used

  • The directory to be used (defaults to the current working directory)

  • Optionally, specify a logger for output

batch = MeltsBatch(
    MORB,
    default_config={  # things that won't change between experiments
        "Initial Temperature": 1400,
        "Final Temperature": 800,
        "modes": ["isobaric", "fractionate solids"],
    },
    config_grid={  # things that change between experiments
        "Initial Pressure": [5000, 7000],
        "Log fO2 Path": [None, "FMQ"],
        "modifychem": [None, {"H2O": 0.5}],
    },
    env=env,
    fromdir=experiment_dir,
)

Now the experiment is configured, we can run it:

batch.run(overwrite=False)  # overwrite=True if you want to update existing exp folders

Total running time of the script: (0 minutes 0.030 seconds)

Gallery generated by Sphinx-Gallery