Running mcasopt on Spartan

Include instructions for:

  • Writing Slurm job scripts that use this package.

  • How mcasopt will launch jobs, what their names will be, monitoring their progress, etc.

  • How mcasopt will resume where it left off, if terminated.

In adapting the example presented below, you may want to change the following details:

  • The mapping from parameter vectors to model inputs input_fun.

  • The initial parameter vector x_0.

  • The model parameters in input_file.

  • The target criteria in criteria_file.

  • The path to the MCAS binary mcas_path.

Example mcasopt script

The following Python code demonstrates how to use mcasopt to find parameter values that produce results consistent with a set of target criteria, as specified in the file p+14O-vAmos.crit.

Listing 5 The contents of p_plus_14O_vAmos.py.
#!/usr/bin/env python3

import mcasopt


# Define a function that returns the MCAS input for parameter vector ``x``.
def input_fun(mcas_input, x):
    # Adjust the MCAS input according to the values in ``x``.
    mcas_input.model.v0 = [x[0], 0.0, x[0]]
    mcas_input.model.vll = [x[1], 0.0, x[1]]
    return mcas_input


def main():
    # Define the initial parameter vector.
    x_0 = [-35.16, 0.675]

    # Load the experiment configuration.
    config = mcasopt.load_config('p+14O-vAmos.toml')

    # Define an evaluator that runs MCAS simulations using Slurm.
    evaluator = mcasopt.McasEvaluator.run_with_slurm(config, input_fun)

    # Run the solver and obtain the approximate solution.
    result = mcasopt.minimise(evaluator, x_0, config.solver)

    # Print the solution vector.
    print(f'Solution: {result.x}')


if __name__ == "__main__":
    main()

Example experiment configuration

The following TOML file defines all of the configuration settings required to run mcasopt.

Note

The job-submission settings are defined in the [slurm] settings table (highlighted below).

Listing 6 The contents of p+14O-vAmos.toml.
[experiment]
name = "p+14O-vAmos"
input_file = "p+14O-vAmos.inp"
criteria_file = "p+14O-vAmos.crit"
mcas_path = "./mcas/mcas5.4"
amdc_masses_path = "AMDC-masses.dat"

[solver]
# method = "Nelder-Mead"
method = "BFGS"
# bounds = []
# sleep_duration = 60
cache_file = "p+14O-vAmos.cache"
sleep_duration = 0
log_level = "INFO"
epsilon = 1.5e-8

[slurm]
shebang = "#!/bin/bash"
header.partition = "physical"
header.time = "30-00:00:00"
header.ntasks = "1"
header.job-name = "my-mcas-experiment"
header.output = "my-mcas-experiment.log"
modules = ["iompi"]

Example simulation script

Note

The jobs should be submitted to the "physical" partition.

Each MCAS simulation will be run using a job script such as the one shown below:

Listing 7 The contents of example_job.sh.
#!/bin/bash
#
#SBATCH --partition=physical
#SBATCH --time=30-00:00:00
#SBATCH --ntasks=1
#SBATCH --job-name=my-mcas-experiment
#SBATCH --output=my-mcas-experiment.log

module purge
module load iompi
module load foss
module load scipy-bundle

date
cd "/home/unimelb.edu.au/rgmoss/work/projects/mcasopt/test_mcas_runner_job"
"/home/unimelb.edu.au/rgmoss/work/projects/mcasopt/mcas/mcas5.4" < p+14O-vAmos.inp > p+14O-vAmos.out 2>&1
date

This job can then be scheduled to run with the sbatch command:

sbatch example_job.sh

Example mcasopt script

To start run mcasopt on Spartan, you need to write a shell script that activates the mcasopt virtual environment (see Installation) and runs the p_plus_14O_vAmos.py script:

Listing 8 The contents of run_p+14O-vAmos.sh.
#!/bin/bash
module load foss
module load scipy-bundle
source ~/venv/bin/activate
python3 p_plus_14O_vAmos.py

This job can then be scheduled to run with the sbatch command:

sbatch run_p+14O-vAmos.sh