Installing OptClim - optclim/ModelOptimisation GitHub Wiki

Set up the OptClim environment (any model supported - UKESM has extra guidance.)

On ARCHER2:

  1. Either clone the Archer2 branch of this repository (git clone [email protected]:optclim/ModelOptimisation.git; git checkout Archer2) or use existing one, OPTCLIMTOP=/work/n02/shared/mjmn02/OptClim/optclim3/ModelOptimisation
  2. If you cloned to get your own working directory, then set OPTCLIMTOP
  3. Put $OPTCLIMTOP/OptClimVn2 and $OPTCLIMTOP/tools/optFunctions (and DFOLS and what ever else needed by your optimisation algorithm ) in your python search path.
  4. Add $OPTCLIMTOP/tools to your PATH.
  5. UKESM has additional requirements, see that wiki page please.

The usual way to achieve this is in ~/setup_optclim2.sh:

export OPTCLIMTOP=/work/n02/shared/mjmn02/OptClim/optclim3/ModelOptimisation
export PATH=/work/n02/shared/mjmn02/sw/conda/opt_4/bin/:$OPTCLIMTOP/tools:$PATH
export PYTHONPATH=$OPTCLIMTOP:$OPTCLIMTOP/OptClimVn2:$PYTHONPATH

# following are needed only for UKESM:

export OPT_ROSE=/work/n02/shared/mjmn02/OptClim/optclim3/ModelOptimisation/Rose
export OPT_UKESM=/work/n02/shared/mjmn02/OptClim/optclim3/ModelOptimisation/UKESM
export OPT_ST_UKESM=/work/n02/shared/mjmn02/OptClim/st2024  # used to access data for initial case(s) and simulated obs. calculations.
export PATH=$OPT_ST_UKESM/comp_obs:$PATH

(The following text is taken from the README.md in the master branch.)

Works at python 3.8. May work at python 3.7+. Needs dicts that are ordered. You also need the following modules (generally available from conda-forge but could be installed via pip) f90nml pandas matplotlib xarray netCDF4 numpy

to run OptClim

tools/runAlgorithm.py is a python script that runs an optimisation - it is controlled by a JSON file.

Testing

run pytest in OptClimVn2 in OPTCLIMTOP. There are about 120 tests. One in test_Optimise may fail. If so run it again...

To test runAlgorithm.py you need to do the following in ipython in OPTCLIMTOP: import tempfile tdir=tempfile.TemporaryDirectory() # gives you a temp directory. %run -i tools/runAlgorithm --restart --test -d $tdir.name Configurations/dfols14param.json This will run continually run until the algorithm has finished.

For porting you will need to modify (or add new ) code so that it uses the correct submission method & model class. OptClimVN2 provides classes/methods for you. See README in that directory. tools contains some other potentially useful tools...

OptClimVn2/config.py contains a lookup table for models.

Warning

This code is research quality and probably not really suitable for production. I am happy to collaborate with others to make it more useful. All code is available on a GPLv3 license. See License.