Howto

Table of Contents

This is a root file for howto type things

INBOX

Boxlib

Boxlib iteration over MultiFabs

void runScalarAdvection(GalerkinBoussinesq& solver) {
      solver.state.u.setVal(1.0);
      solver.state.v.setVal(1.0);
      solver.fillBoundaries();


      for (MFIter mfi(solver.state.u); mfi.isValid(); ++mfi){
          // X staggered variables have one more point in the x direction
          // const Box &tbx = mfi.growntilebox(); // This is the ghosted box
          const Box &tbx = mfi.growntilebox(); // This is the ghosted box
          const Box&  bx = mfi.validbox(); // This is the nonghosted box

          std::cout << "Valid Box Low/hi " << bx.loVect()[0] << " " << bx.hiVect()[0] << std::endl;
          std::cout << "Tile Box Low/hi " << tbx.loVect()[0] << " " << tbx.hiVect()[0] << std::endl;
      }


  }

combining images into a grid

montage  -geometry x300  -tile 3x3 squall/*.png  squall.png

MPI run scripts

mvapich and hdf5 with mpi4py

#!/bin/bash
#PBS -N dedalus
#PBS -l nodes=8:ppn=1,walltime=4:00:00

module purge
module load fftw/mvapich2/intel/3.3.4
module load hdf5/intel/1.8.12
source ~/py3k/bin/activate

mpirun -np 4 python ~/dedalus/examples/ivp/2d_rayleigh_benard/rayleigh_benard.py

anaconda and fish shell

Entered on [2016-12-23 Fri 21:13]

file:///home/noah/.config/fish/config.fish

Need to source the anaconda fish script, and add the anaconda binary dir to the path:

. ~/anaconda3/etc/fish/conf.d/conda.fish

set -gx PATH /Users/noah/anaconda3/bin /usr/local/texlive/2014/bin/x86_64-darwin /Applications/Julia-0.5.app/Contents/Resources/julia/bin /Applications/Emacs.app//Contents/MacOS/bin $PATH

Then use

conda activate ...

to activate environments.

dotfile management using git

https://news.ycombinator.com/item?id=11070797

I currently have the following aliases

alias config='/usr/bin/env git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
alias con='config'

magit compatibility

I asked a question on emacs.stackexchange.com.

common error message in org-mode

org-babel-exp-process-buffer: Wrong type argument: stringp, nil

Installation

Dedalus

Install dedalus on hpc

Use mvapich2 for mpi4py and fftw.

module purge
module load fftw/mvapich2/intel/3.3.4

CC=mpicc CXX=mpicxx FFTW_PATH=$FFTW_ROOT MPI_PATH=$MPI_ROOT python setup.py build_ext --inplace

Installing dedalus on cims linux desktop :broken:

This is a complicated processs because of the mpi dependency, and because it needs an older version of mpi4py.

Use these modules

module load fftw-3.3.4
module load openmpi-intel
module load intel

export LD_LIBRARY_PATH=/opt/pkg/intel/current/composerxe/lib/intel64/:$LD_LIBRARY_PATH
  1. Install mpi4py (download from pypi)

    CC=mpicc python setup.py install
    
  2. Compile dedalus. This needs to be done with mpicc

    CFLAGS="-I/usr/local/pkg/fftw/fftw-3.3.4/include $CFLAGS" CC=mpicc python setup.py build_ext --inplace
    

dedalus on macbook

conda install cython docopt h5py matplotlib numpy scipy
conda install -c mpi4py mpich mpi4py
pip install pathlib hgapi

mpi4py on mac

I get an annoying error message when using the default version of mpi4py. According to this thread, the easiest way to fix this is by installing using

conda install --channel mpi4py mpich mpi4py

Install NCL on macbook

See these instructions.

Download ncl binaries from earthsystemgrid, and then download and extract Mac os gcc binaries from http://hpc.sourceforge.net.

The homebrew included version of gcc does not work with openmp, and it takes so long to recompile.

Openmpi/PETSc on mac :working:

Succesfully installed on [2016-11-28 Mon]!

I was getting errors installing hdf5 using homebrew. See this github issue. Needed to run

xcode-select -r

to reset my “DeveloperDirectory”.

After much headache I had to do

brew install hdf5 --with-fortran --c++11
brew uninstall --ignore-dependencies netcdf
brew install petsc

In that specific order. This doesn’t seem very reproducible.

Chombo

Many other changes needed

Had to change line 476 of AMRBoxesAndRanksIO.cpp to

while ((ok = static_cast<bool>(getline(ifs, sline, '\n'))))

Vagrant

Version 1.8.7 was not able to add boxes for some stupid reason. Downgrade to 1.8.6. link

Use vagrant box from ubuntu servers

vagrant box add yakkety64 https://cloud-images.ubuntu.com/yakkety/current/yakkety-server-cloudimg-amd64-vagrant.box
vagrant init yakkety64; vagrant up --provider=virtualbox

Update [2016-11-29 Tue]

Stopped working. use release version rather than the daily build.

vagrant box add yakkety64 https://cloud-images.ubuntu.com/releases/16.10/release/

Zotero

RTFM as usual. There is lots of good stuff in there about tags and related items.

zotfile settings

Use /%T as the naming scheme

Remove orphaned zotfiles

  1. Change attachments directory in zotfile preferences
  2. Close prefs, select all items, right-click and choose “rename attachements”. All the files will be moved to the temporary directory.
  3. Delete the files in the original directory. These are the orgphaned files.
  4. Repeat steps 1 and 2 to move the files back to their original location

Emacs

add company backend for given mode

[2016-11-30 Wed]

See https://github.com/syl20bnr/spacemacs/issues/4878

(setq company-ispell-available t) ; error without this
(setq company-ispell-dictionary "english-word.txt)

(defvar company-backends-text-mode '())
(spacemacs|add-company-hook text-mode)
(push 'company-ispell company-backends-text-mode)

RTAGS

Install rtags using homebrew. Install bear which can be used to generate the

appropriate config files. This doesn’t work, and is too complicated.

Org mode stuff

ipython

(require 'ob-ipython)

Use the py snippet for making a nice python cell with an automatic file name for the image.

#+BEGIN_SRC ipython :session :file /Users/noah/Dropbox/notes/py687968Xx.png :exports both
  %pylab inline



  plot(rand(100))
#+END_SRC

debug errors using org-lint

beamer slide titles in reftex toc

The trick is listed on this website. The reftex-variable can be changed in customize.

Git

Delete remote branch

See this stack overflow answer. The command to run is

git push origin --delete <branchName>

git subtree

See this article for a description of how to use git subtree.

  • To add a remote repo as a subtree:

    git subtree add --prefix .vim/bundle/tpope-vim-surround https://bitbucket.org/vim-plugins-mirror/vim-surround.git master --squash
    
  • To split a directory into it’s own branch

    git subtree split --prefix=path/to/code -b split --squash
    

Troubleshooting

  1. Error message: “Working tree has modifications cannot add”

    Solution is to re-checkout the current branch

    git checkout <branchname>
    

    See stackoverflow.

  2. bad object

    Downloaded git 2.9, which fixed the issue.

Python

Numpy/scipy

scipy.ndimage.correlate1d

The origin parameter of this function is somewhat confusing. For odd-sized filters, the origin specifies the center of the filter. For even-sized stencils, the origin=0 means that the center of the filter is at n/2+1. See the following examples

In [17]: correlate1d(np.arange(5), [0, 1, 0,0], origin=0)
Out[17]: array([0, 0, 1, 2, 3])

In [18]: correlate1d(np.arange(5), [0, 0, 1,0], origin=0)
Out[18]: array([0, 1, 2, 3, 4])

In [19]: correlate1d(np.arange(5), [0, 1,0], origin=0)
Out[19]: array([0, 1, 2, 3, 4])

Jupyter notebook incorrect executable

If jupyter is unable to import packages, be sure to check

sys.executable

See this github issue for more details about how to fix the kernel spec.

Documenting python

This is the numpy documentation style guide https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt

testing python

Use either nosesests or docopt

LaTeX

left justified captions

\usepackage{caption}
\captionsetup{justification=raggedright,
singlelinecheck=false
}

Float barrier before sections

\usepackage{placeins}

\let\Oldsection\section
\renewcommand{\section}{\FloatBarrier\Oldsection}

\let\Oldsubsection\subsection
\renewcommand{\subsection}{\FloatBarrier\Oldsubsection}

\let\Oldsubsubsection\subsubsection
\renewcommand{\subsubsection}{\FloatBarrier\Oldsubsubsection}

Add the layouts package to the preamble, and copy the following text

\usepackage{layouts}
\begin{document}

\noindent {\Large Useful values for making figures}\\
\noindent Text width: \printinunitsof{in}\prntlen{\textwidth}\\
Text height: \printinunitsof{in}\prntlen{\textheight}

Julia

change package path

The homefolder on CIMS machines is so slow so it is better to use scratch. This is accomplished using the JULIAPKGDIR environmental variable.

Adding packages

To find a user module, it needs to be in the path at JULIAPKGDIR. You can use a symbolic link in this directory if you don’t want the source code to actually sit in some hidden folder.

Fortran

Installing and using coarrays

Gfortran

  1. install Open Coarrays
  2. compile using caf
  3. run with runcaf

Intel

https://software.intel.com/en-us/node/532830

  1. source the bin/compilervars.sthermo_mod.f90thermo_mod.f90h file.
  2. compile using ifort -coarray
  3. control number of images with FORCOARRAYNUMIMAGES

Calling Fortran using CFFI

http://scientific-software-diary.com/?p=29

Fortran

Converting fixed source fortran to free

Use ftf.pl, which is a perl script.

Unix

tar

this is useful for making a tar of a folder with a bunch of symlinks and can be accomplished using the -h flag.

tar chzf name.tar.gz some-dir/

Type 3 Fonts

Use the following to remove all Type 3 fonts from the current eps files. This is necessary for submitting to QJRMS.

for f in `ls -1 *.eps`
do
    mv $f $f.bak
    gs -sDEVICE=epswrite -dNOCACHE -sOutputFile=${f} \
       -q -dbatch -dNOPAUSE $f.bak -c quit end
done

See this blog post about Type 3 fonts.

Vignettes

TRMM

TRMM Python

The TRMM 3b42 dataset is available through OpenDap, and can be easily loaded using xray.

%matplotlib inline
import xray
from datetime import datetime

def date2url(date):
    out = date.strftime('http://disc2.nascom.nasa.gov/opendap/TRMM_L3/TRMM_3B42/%Y/%j/3B42.%Y%m%d.%H.7.HDF.Z')

    return out

date = datetime(2015, 5, 10, 6)



url = date2url(date)
remote_data = xray.open_dataset(url)

P = remote_data.precipitation.sel(nlon=slice(150, 200), nlat=slice(-10,10))
P.T.plot()

img

Automatic differentiation

This presentation mentions:

  1. TAF. “Transformation of Algorithms in Fortran”. Used by mitGCM.
    1. TAMC: Supposedly succeeded by TAF
  2. ADIFOR
  3. TAPENADE: mentioned in climate paper
  4. OpenAD

How does automatic differentiation work with randomized codes?

Software Languages Used in AOS
TAF F95 y
Tapenade F90,C y
[Adept](http://www.met.reading.ac.uk/clouds/adept/) C++ y (at reading)
[casadi](https://github.com/casadi/casadi/wiki)    

It seems that TAPENADE and TAF are most used for in AOS, probably because they work with Fortran.

Approaches

  • Operator overloading generally requires rewriting some code.
  • Source code transformation is ideal for the SMCM

How would randomized codes work? Maybe have to fit parameters of the DFMLE.

Sources

  • [@bucker_automatic_2006] a book on automatic differentiation
  • autodiff.org: Has a lot of information, including a list of applications of AD software in AOS

Refs

<~/Dropbox/Papers/zotero.bib>

comments powered by Disqus