#!/bin/sh
+# Detect number of cores with Python >= 2.6.
+# For Python 2.5, you'll have to hard-code the value (or sed /proc/cpuinfo ;).
+CORES=$(python -c 'from multiprocessing import cpu_count; print cpu_count()' \
+ || exit 1)
+#CORES=1
+
+NOSE="nosetests --with-doctest --doctest-tests --processes $CORES"
+
HAS_MPD=$(which mpdallexit 2>/dev/null)
if [ -n "$HAS_MPD" ]; then
+ echo "Running nosetests with $CORES processes via MPI."
LOCAL_MPD=''
mpdtrace >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
- LOCAL_MPD='1'
- mpd & # start an mpd instance
- sleep 1 # give mpd some time to start up
+ LOCAL_MPD='1'
+ mpd & # start an mpd instance
+ sleep 1 # give mpd some time to start up
fi # otherwise there is an mpd instance already running
- mpiexec -n 1 nosetests --with-doctest --doctest-tests pysawsim
+ mpiexec -n 1 $NOSE pysawsim
RESULT="$?"
if [ -n "$LOCAL_MPD" ]; then
- mpdallexit
+ mpdallexit
fi
if [ "$RESULT" -ne 0 ]; then
- exit 1;
+ exit 1;
fi
else # no MPD
+ echo "Running nosetests with $CORES processes without MPI."
- nosetests --with-doctest --doctest-tests pysawsim || exit 1
+ $NOSE pysawsim || exit 1
fi
import sys
+_multiprocess_shared_ = True
+"""Allow nosetests to share this module between test processes.
+
+This module cannot be split because _log setup is not re-entrant.
+"""
+
__version__ = '0.10' # match sawsim version
+
def log():
return logging.getLogger('pysawsim')
from keyword import iskeyword as _iskeyword
import sys as _sys
+
+_multiprocess_can_split_ = True
+"""Allow nosetests to split tests between processes.
+"""
+
+
def namedtuple(typename, field_names, verbose=False):
"""Returns a new subclass of tuple with named fields.
from . import log
+_multiprocess_can_split_ = True
+"""Allow nosetests to split tests between processes.
+"""
+
+
class Histogram (object):
"""A histogram with a flexible comparison method, `residual()`.
import sys
+_multiprocess_can_split_ = True
+"""Allow nosetests to split tests between processes.
+"""
+
+
class CommandError(Exception):
"""Represent errors in command execution.
from .sawsim import SawsimRunner
+_multiprocess_can_split_ = True
+"""Allow nosetests to split tests between processes.
+"""
+
+
def find_error_bounds(histogram_matcher, param_range, log_scale, threshold):
if log_scale == False:
ps = numpy.linspace(*param_range)
from .sawsim import SawsimRunner
+_multiprocess_can_split_ = True
+"""Allow nosetests to split tests between processes.
+"""
+
FIGURE = pylab.figure() # avoid memory problems.
"""`pylab` keeps internal references to all created figures, so share
a single instance.
from .manager import MANAGERS, get_manager, InvokeJob
+_multiprocess_can_split_ = True
+"""Allow nosetests to split tests between processes.
+"""
+
SAWSIM = 'sawsim' # os.path.expand(os.path.join('~', 'bin', 'sawsim'))
CACHE_DIR = os.path.expanduser(os.path.join('~', '.sawsim-cache'))
DEFAULT_PARAM_STRING = (
from .sawsim import SawsimRunner
+_multiprocess_can_split_ = True
+"""Allow nosetests to split tests between processes.
+"""
+
+
def sawsim_histogram(sawsim_runner, param_string, N=400, bin_edges=None):
"""Run `N` simulations and return a histogram with `bin_edges`.