Skip to content

Commit

Permalink
Merge pull request #2 from pypr/docs
Browse files Browse the repository at this point in the history
Docs
  • Loading branch information
prabhuramachandran committed Aug 29, 2018
2 parents 3043553 + 7990e38 commit 728e610
Show file tree
Hide file tree
Showing 20 changed files with 1,430 additions and 90 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
build/
dist/
*.egg-info/
*.pytest_cache/
examples/tutorial/config.json
examples/tutorial/outputs
examples/tutorial/manuscript
examples/tutorial/.automan
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include MANIFEST.in *.py *.rst *.txt *.yml
recursive-include docs *.*
recursive-include examples *.py
recursive-exclude examples/tutorial/.automan *.*
recursive-exclude docs/build *.*
54 changes: 36 additions & 18 deletions automan/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class TaskRunner(object):
def __init__(self, tasks, scheduler):
"""Constructor.
Parameters
----------
**Parameters**
tasks: iterable of `Task` instances.
scheduler: `automan.jobs.Scheduler` instance
Expand Down Expand Up @@ -176,8 +175,7 @@ class CommandTask(Task):
def __init__(self, command, output_dir, job_info=None):
"""Constructor
Parameters
----------
**Parameters**
command: str or list: command to run $output_dir is substituted.
output_dir: str : path of output directory.
Expand Down Expand Up @@ -215,6 +213,9 @@ def complete(self):
return self._copy_output_and_check_status()

def run(self, scheduler):
# Remove the error status file if it exists and we are going to run.
if os.path.exists(self._error_status_file):
os.remove(self._error_status_file)
self.job_proxy = scheduler.submit(self.job)

def clean(self):
Expand Down Expand Up @@ -297,8 +298,7 @@ class PySPHTask(CommandTask):
def __init__(self, command, output_dir, job_info=None):
"""Constructor
Parameters
----------
**Parameters**
command: str or list: command to run $output_dir is substituted.
output_dir: str : path of output directory.
Expand Down Expand Up @@ -363,8 +363,7 @@ class Problem(object):
def __init__(self, simulation_dir, output_dir):
"""Constructor.
Parameters
----------
**Parameters**
simulation_dir : str : directory where simulation output goes.
output_dir : str : directory where outputs from `run` go.
Expand Down Expand Up @@ -482,8 +481,7 @@ def kwargs_to_command_line(kwargs):
"""Convert a dictionary of keyword arguments to a list of command-line
options. If the value of the key is None, no value is passed.
Examples
--------
**Examples**
>>> sorted(kwargs_to_command_line(dict(some_arg=1, something_else=None)))
['--some-arg=1', '--something-else']
Expand Down Expand Up @@ -549,8 +547,7 @@ class via the job_info kwarg so as to run the command suitably. For
def __init__(self, root, base_command, job_info=None, **kw):
"""Constructor
Parameters
----------
**Parameters**
root: str
Path to simulation output directory.
Expand Down Expand Up @@ -617,8 +614,7 @@ def compare_runs(sims, method, labels, exact=None):
compare and an optional method name for an exact solution, this calls the
methods with the appropriate parameters for each simulation.
Parameters
----------
**Parameters**
sims: sequence
Sequence of `Simulation` objects.
Expand All @@ -645,11 +641,22 @@ def compare_runs(sims, method, labels, exact=None):
method(s, label=s.get_labels(labels), **next(ls))


def filter_cases(runs, **params):
def filter_cases(runs, predicate=None, **params):
"""Given a sequence of simulations and any additional parameters, filter
out all the cases having exactly those parameters and return a list of
them.
One may also pass a callable to filter the cases using the `predicate`
keyword argument. If this is not a callable, it is treated as a parameter.
If `predicate` is passed though, the other keyword arguments are ignored.
"""
if predicate is not None:
if callable(predicate):
return list(filter(predicate, runs))
else:
params['predicate'] = predicate

def _check_match(run):
for param, expected in params.items():
if param not in run.params or run.params[param] != expected:
Expand Down Expand Up @@ -757,8 +764,8 @@ def __init__(self, simulation_dir, output_dir, all_problems,
cluster_manager_factory=None):
"""Constructor.
Parameters
----------
**Parameters**
simulation_dir : str
Root directory to generate simulation results in.
output_dir: str
Expand Down Expand Up @@ -788,7 +795,8 @@ def run(self, argv=None):
self._check_positional_arguments(args.problem)

self.cluster_manager = self.cluster_manager_factory(
config_fname=args.config
config_fname=args.config,
exclude_paths=self._get_exclude_paths()
)

if len(args.host) > 0:
Expand Down Expand Up @@ -821,6 +829,16 @@ def _check_positional_arguments(self, problems):
print("Valid names are %s" % ', '.join(names))
self.parser.exit(1)

def _get_exclude_paths(self):
"""Returns a list of exclude paths suitable for passing on to rsync to exclude
syncing some directories on remote machines.
"""
paths = []
for path in [self.simulation_dir, self.output_dir]:
if not path.endswith('/'):
paths.append(path + '/')
return paths

def _select_problem_classes(self, problems):
if problems == 'all':
return self.all_problems
Expand Down

0 comments on commit 728e610

Please sign in to comment.