Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executable version of odld using the MPI work-manager. #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions odld_exe_MPI-WM/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Set up environment for dynamics
module purge
module load gcc/8.2.0
module load openmpi/4.0.3

# Set WESTPA-related variables
export WEST_SIM_ROOT="$PWD"
export SIM_NAME=$(basename $WEST_SIM_ROOT)

14 changes: 14 additions & 0 deletions odld_exe_MPI-WM/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Set up simulation environment
source env.sh

# Clean up from previous/ failed runs
rm -rf traj_segs seg_logs istates west.h5
mkdir seg_logs traj_segs istates

# Set bstate
BSTATES="--bstate initial,1.0"

# Run w_init
w_init $BSTATES --work-manager=serial "$@"
75 changes: 75 additions & 0 deletions odld_exe_MPI-WM/odld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python

import numpy as np
from numpy.random import normal as random_normal

SEG_STATUS_COMPLETE = 2

PI = np.pi

coord_len = 21
coord_dtype = np.float32

A = 2
B = 10
C = 0.5
x0 = 1

# Implement a reflecting boundary at this x value
# (or None, for no reflection)
reflect_at = 10.0

coords = np.empty(coord_len, dtype=coord_dtype)

f = open('odld.crd', 'r')
coords[0] = f.readline()
f.close

twopi_by_A = 2 * PI / A
half_B = B / 2
sigma = 0.001 ** (0.5)
gradfactor = sigma * sigma / 2
all_displacements = np.zeros(coord_len, dtype=coord_dtype)

for istep in range(1, coord_len):
x = coords[istep - 1]

xarg = twopi_by_A * (x - x0)

eCx = np.exp(C * x)
eCx_less_one = eCx - 1.0

all_displacements[istep] = displacements = random_normal(scale=sigma, size=(1,))
grad = half_B / (eCx_less_one * eCx_less_one) * (twopi_by_A * eCx_less_one * np.sin(xarg) + C * eCx * np.cos(xarg))

newx = x - gradfactor * grad + displacements

if reflect_at is not None:
# Anything that has moved beyond reflect_at must move back that much

# boolean array of what to reflect
to_reflect = newx > reflect_at

# how far the things to reflect are beyond our boundary
reflect_by = newx[to_reflect] - reflect_at

# subtract twice how far they exceed the boundary by
# puts them the same distance from the boundary, on the other side
newx[to_reflect] -= 2 * reflect_by

coords[istep] = newx

f = open('odld.rst', 'w')
f.write('{:12.8f}'.format(coords[coord_len-1])+'\n')
f.close

f = open('pcoords.dat', 'w')
for element in coords.flat:
f.write('{:12.8f}'.format(element)+'\n')
f.close

f = open('displacements.dat', 'w')
for element in all_displacements.flat:
f.write('{:12.8f}'.format(element)+'\n')
f.close

24 changes: 24 additions & 0 deletions odld_exe_MPI-WM/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#SBATCH --job-name=odld
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=28
#SBATCH --cluster=mpi
#SBATCH --partition=opa
#SBATCH --time=1:00:00

# Make sure environment is set
source env.sh

# These variable are specific to Pitt CRC HPC cluster
export OMPI_MCA_pml=ob1
export OMPI_MCA_btl="self,tcp"
export OMPI_MCA_opal_warn_on_missing_libcuda=0

which mpirun
echo $SLURM_NTASKS

# Clean up
rm -f west.log

mpirun -n $SLURM_NTASKS \
w_run --work-manager=mpi "$@" &> west.log
69 changes: 69 additions & 0 deletions odld_exe_MPI-WM/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import numpy as np
from westpa.core.binning import RectilinearBinMapper
from westpa.core.propagators import WESTPropagator
from westpa.core.systems import WESTSystem

import logging
log = logging.getLogger(__name__)
log.debug('loading module %r' % __name__)

class System(WESTSystem):
"""
Over-damped Langevin dynamics
"""

def initialize(self):
self.pcoord_ndim = 1
self.pcoord_len = 21
self.pcoord_dtype = np.float32

self.bin_mapper = RectilinearBinMapper([ list(np.arange(0.0, 10.1, 0.1)) ])
self.bin_target_counts = np.empty((self.bin_mapper.nbins,), np.int_)
self.bin_target_counts[...] = 10

def displacement_loader(fieldname, coord_filename, segment, single_point=False):
"""
Loads and stores coordinates

**Arguments:**
:*fieldname*: Key at which to store dataset
:*coord_filename*: Temporary file from which to load coordinates
:*segment*: WEST segment
:*single_point*: Data to be stored for a single frame
(should always be false)
"""

# Load coordinates
n_frames = 21
coord = np.loadtxt(coord_filename, dtype = np.float32)
coord = np.reshape(coord, (n_frames))

# Save to hdf5
segment.data[fieldname] = coord

def seg_status_loader(fieldname, log_filename, segment, single_point=False):
"""
Loads and stores log

**Arguments:**
:*fieldname*: Key at which to store dataset
:*log_filename*: Temporary file from which to load log
:*segment*: WEST segment
:*single_point*: Data to be stored for a single frame
(should always be false)
"""

# Load log
# with open(log_filename, 'r') as log_file:
# raw_text = [line.strip() for line in log_file.readlines()]

# Save to hdf5

f = open(log_filename, 'r')
seg_status = f.read()
f.close

with open(log_filename, 'r') as log_file:
for line in log_file:
segment.status = int(line)

87 changes: 87 additions & 0 deletions odld_exe_MPI-WM/west.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# The master WEST configuration file for a simulation.
# vi: set filetype=yaml :
---
west:
system:
driver: system.System
module_path: $WEST_SIM_ROOT
propagation:
max_total_iterations: 50
max_run_wallclock: 24:00:00
propagator: executable
gen_istates: true
block_size: 10000
data:
west_data_file: west.h5
aux_compression_threshold: 16384 # data sets bigger than this are compressed
# unless overridden by an entry in ``datasets`` below
datasets:
- name: pcoord
scaleoffset: 4
- name: displacement
dtype: float32
scaleoffset: 4

data_refs: # how to convert segments and states to paths, etc
segment: $WEST_SIM_ROOT/traj_segs/{segment.n_iter:06d}/{segment.seg_id:06d}
basis_state: $WEST_SIM_ROOT/bstates/{basis_state.auxref}
initial_state: $WEST_SIM_ROOT/istates/{initial_state.iter_created}/{initial_state.state_id}.crd
plugins:
executable:
environ:
PROPAGATION_DEBUG: 1
datasets:
- name: displacement
loader: system.displacement_loader
enabled: true
- name: seg_status
loader: system.seg_status_loader
enabled: true
propagator:
executable: $WEST_SIM_ROOT/westpa_scripts/runseg.sh
stdout: $WEST_SIM_ROOT/seg_logs/{segment.n_iter:06d}-{segment.seg_id:06d}.log
stderr: stdout
stdin: null
cwd: null
environ:
SEG_DEBUG: 1
get_pcoord:
executable: $WEST_SIM_ROOT/westpa_scripts/get_pcoord.sh
stdout: /dev/null
stderr: stdout
gen_istate:
executable: $WEST_SIM_ROOT/westpa_scripts/gen_istate.sh
stdout: /dev/null
stderr: stdout
post_iteration:
enabled: true
executable: $WEST_SIM_ROOT/westpa_scripts/post_iter.sh
stderr: stdout
pre_iteration:
enabled: false
executable: $WEST_SIM_ROOT/westpa_scripts/pre_iter.sh
stderr: stdout
analysis:
# Settings for w_ipa, an interactive analysis program that can also automate analysis.
directory: ANALYSIS # specify the directory all analysis files should exist in.
postanalysis: True # should the routines for w_reweight be run?
kinetics: # general options for both kinetics routines.
# Command line arguments with values should be specified as key: value (see below)
# Command line arguments that are flags without values should be included as a list value
# in the extra key (extra: [ 'disable-correl', 'disable-bootstrap' ])
# These are global options for each scheme; individual schemes can have different values,
# set in their respective section.
step_iter: 10
evolution: cumulative
extra: [ 'disable-correl' ]
analysis_schemes: # Analysis schemes. Required: name (TEST), states, and bins
TEST:
enabled: True
states:
- label: unbound
coords: [[8.0]]
- label: bound
coords: [[3.99]]
bins:
- type: RectilinearBinMapper
boundaries: [[0.0,4.0,8.00,100000]]
11 changes: 11 additions & 0 deletions odld_exe_MPI-WM/westpa_scripts/gen_istate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ -n "$SEG_DEBUG" ] ; then
set -x
env | sort
fi

cd $WEST_SIM_ROOT

mkdir -p $(dirname $WEST_ISTATE_DATA_REF)
echo 8.0 > $WEST_ISTATE_DATA_REF
15 changes: 15 additions & 0 deletions odld_exe_MPI-WM/westpa_scripts/get_pcoord.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

if [ -n "$SEG_DEBUG" ] ; then
set -x
env | sort
fi

cd $WEST_SIM_ROOT

# Get progress coordinate
echo 8.0 > $WEST_PCOORD_RETURN

if [ -n "$SEG_DEBUG" ] ; then
head -v $WEST_PCOORD_RETURN
fi
12 changes: 12 additions & 0 deletions odld_exe_MPI-WM/westpa_scripts/post_iter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

if [ -n "$SEG_DEBUG" ] ; then
set -x
env | sort
fi

cd $WEST_SIM_ROOT || exit 1

ITER=$(printf "%06d" $WEST_CURRENT_ITER)
tar -cf seg_logs/$ITER.tar seg_logs/$ITER-*.log
rm -f seg_logs/$ITER-*.log
43 changes: 43 additions & 0 deletions odld_exe_MPI-WM/westpa_scripts/runseg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

if [ -n "$SEG_DEBUG" ] ; then
set -x
env | sort
fi

cd $WEST_SIM_ROOT

# Set up the run
mkdir -pv $WEST_CURRENT_SEG_DATA_REF
cd $WEST_CURRENT_SEG_DATA_REF

case $WEST_CURRENT_SEG_INITPOINT_TYPE in
SEG_INITPOINT_CONTINUES)
# A continuation from a prior segment
# $WEST_PARENT_DATA_REF contains the reference to the
# parent segment
ln -sv $WEST_PARENT_DATA_REF/odld.log ./parent.log
ln -sv $WEST_PARENT_DATA_REF/odld.rst ./odld.crd
;;

SEG_INITPOINT_NEWTRAJ)
# Initiation of a new trajectory
# $WEST_PARENT_DATA_REF contains the reference to the
# appropriate basis or initial state
ln -sv $WEST_PARENT_DATA_REF ./odld.crd
;;

*)
echo "unknown init point type $WEST_CURRENT_SEG_INITPOINT_TYPE"
exit 2
;;
esac

# Propagate segment
python $WEST_SIM_ROOT/odld.py >& odld.log

# Calculate progress coordinate
cat pcoords.dat > $WEST_PCOORD_RETURN

cat displacements.dat > $WEST_DISPLACEMENT_RETURN

16 changes: 16 additions & 0 deletions odld_exe_MPI-WM/westpa_scripts/tar_segs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

[ -z "$WEST_SIM_ROOT" ] &&
exit 1
[ ! -d $WEST_SIM_ROOT/traj_segs ] &&
exit 1

cd $WEST_SIM_ROOT/traj_segs

ITERS=($(ls | grep '^[0-9][0-9][0-9][0-9][0-9][0-9]$'))
ITERS=("${ITERS[@]:0:${#ITERS[@]}-1}")
for ITER in ${ITERS[@]}; do
[ ! -f $ITER.tar ] &&
tar -cvf $ITER.tar $ITER
done