-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from pypr/generalize-cluster-manager
Generalize cluster manager
- Loading branch information
Showing
10 changed files
with
182 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
include MANIFEST.in *.py *.rst *.txt *.yml | ||
recursive-include docs *.* | ||
recursive-include examples *.py | ||
recursive-include examples *.py *.yml *.txt *.md | ||
recursive-exclude examples/tutorial/.automan *.* | ||
recursive-exclude docs/build *.* | ||
recursive-exclude docs/build *.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Conda cluster manager example | ||
|
||
This uses the example from the tutorial but shows how it can be used | ||
with the remote computers running conda. The `environments.yml` is used | ||
to create the environment and there is also an optional | ||
`requirements.txt` which will install packages using `pip`. | ||
|
||
The example assumes that the remote computer has its conda root in `~/miniconda3`. | ||
|
||
To run the example, let us say you have a remote computer running Linux/Mac OS | ||
with password-less SSH setup, let us call this computer `remote_host`, then | ||
you can do the following: | ||
|
||
``` | ||
$ python automate.py -a remote_host | ||
[...] | ||
Bootstrapping remote_host succeeded! | ||
$ python automate.py | ||
[...] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from automan.api import Problem, Automator, Simulation | ||
from automan.conda_cluster_manager import CondaClusterManager | ||
from matplotlib import pyplot as plt | ||
import numpy as np | ||
|
||
|
||
class Squares(Problem): | ||
def get_name(self): | ||
return 'squares' | ||
|
||
def get_commands(self): | ||
commands = [(str(i), 'python square.py %d' % i, None) | ||
for i in range(1, 8)] | ||
return commands | ||
|
||
def run(self): | ||
self.make_output_dir() | ||
data = [] | ||
for i in range(1, 8): | ||
stdout = self.input_path(str(i), 'stdout.txt') | ||
with open(stdout) as f: | ||
values = [float(x) for x in f.read().split()] | ||
data.append(values) | ||
|
||
data = np.asarray(data) | ||
plt.plot(data[:, 0], data[:, 1], 'o-') | ||
plt.xlabel('x') | ||
plt.ylabel('y') | ||
plt.savefig(self.output_path('squares.pdf')) | ||
|
||
|
||
class Powers(Problem): | ||
def get_name(self): | ||
return 'powers' | ||
|
||
def setup(self): | ||
base_cmd = 'python powers.py --output-dir $output_dir' | ||
self.cases = [ | ||
Simulation( | ||
root=self.input_path(str(i)), | ||
base_command=base_cmd, | ||
power=float(i) | ||
) | ||
for i in range(1, 5) | ||
] | ||
|
||
def run(self): | ||
self.make_output_dir() | ||
for case in self.cases: | ||
data = np.load(case.input_path('results.npz')) | ||
plt.plot( | ||
data['x'], data['y'], | ||
label=r'$x^{{%.2f}}$' % case.params['power'] | ||
) | ||
plt.grid() | ||
plt.xlabel('x') | ||
plt.ylabel('y') | ||
plt.legend() | ||
plt.savefig(self.output_path('powers.pdf')) | ||
|
||
|
||
if __name__ == '__main__': | ||
automator = Automator( | ||
simulation_dir='outputs', | ||
output_dir='manuscript/figures', | ||
all_problems=[Squares, Powers], | ||
cluster_manager_factory=CondaClusterManager | ||
) | ||
automator.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: conda_cluster | ||
dependencies: | ||
- numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import argparse | ||
import os | ||
|
||
import numpy as np | ||
|
||
|
||
def compute_powers(r_max, power): | ||
"""Compute the powers of the integers upto r_max and return the result. | ||
""" | ||
result = [] | ||
for i in range(0, r_max + 1): | ||
result.append((i, i**power)) | ||
x = np.arange(0, r_max + 1) | ||
y = np.power(x, power) | ||
return x, y | ||
|
||
|
||
def main(): | ||
p = argparse.ArgumentParser() | ||
p.add_argument( | ||
'--power', type=float, default=2.0, | ||
help='Power to calculate' | ||
) | ||
p.add_argument( | ||
'--max', type=int, default=10, | ||
help='Maximum integer that we must raise to the given power' | ||
) | ||
p.add_argument( | ||
'--output-dir', type=str, default='.', | ||
help='Output directory to generate file.' | ||
) | ||
opts = p.parse_args() | ||
|
||
x, y = compute_powers(opts.max, opts.power) | ||
|
||
fname = os.path.join(opts.output_dir, 'results.npz') | ||
np.savez(fname, x=x, y=y) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from __future__ import print_function | ||
import sys | ||
x = float(sys.argv[1]) | ||
print(x, x*x) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Tutorial examples | ||
|
||
This directory contains the scripts and automation scripts that are | ||
discussed in the tutorials available here: | ||
https://automan.readthedocs.io/en/latest/tutorial.html |