Skip to content

Commit 6df92a5

Browse files
committed
[WIP] issues 183 and 184
Signed-off-by: Lance Drane <[email protected]>
1 parent 6f02737 commit 6df92a5

24 files changed

+215
-73
lines changed

examples-proposed/001-helloworld/helloworld/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from ipsframework import Component
2+
3+
4+
class hello_driver(Component):
5+
def __init__(self, services, config):
6+
super().__init__(services, config)
7+
print('Created %s' % (self.__class__))
8+
9+
def step(self, timestamp=0.0):
10+
print('hello_driver: beginning step call')
11+
worker_comp = self.services.get_port('WORKER')
12+
self.services.call(worker_comp, 'step', 0.0)
13+
print('hello_driver: finished step call')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from ipsframework import Component
2+
3+
4+
class hello_worker(Component):
5+
def __init__(self, services, config):
6+
super().__init__(services, config)
7+
print('Created %s' % (self.__class__))
8+
9+
def step(self, timestamp=0.0):
10+
print('Hello from hello_worker')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
from setuptools import setup, find_packages
3+
4+
setup(
5+
name="helloworld",
6+
version="1.0.0",
7+
install_requires=["ipsframework"],
8+
packages=find_packages(),
9+
)

examples-proposed/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Examples
2+
3+
This directory is meant to showcase concrete code examples on how to use the IPS framework.
4+
5+
## Running the examples
6+
7+
1) Make sure your environment has the `ipsframework` dependency installed. (To run from the repository, you can run `pip install -e .`)
8+
2) Change directory into the specific folder (i.e. `001-hello-world`)
9+
3) Run `ips.py --config config.conf --platform platform.conf`
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
SIM_NAME = dask_example
2+
SIM_ROOT = $PWD
3+
LOG_FILE = log
4+
LOG_LEVEL = INFO
5+
SIMULATION_MODE = NORMAL
6+
7+
[PORTS]
8+
NAMES = DRIVER WORKER
9+
[[DRIVER]]
10+
IMPLEMENTATION = driver
11+
12+
[[WORKER]]
13+
IMPLEMENTATION = dask_worker
14+
15+
[driver]
16+
CLASS = DRIVER
17+
SUB_CLASS =
18+
NAME = Driver
19+
NPROC = 1
20+
BIN_PATH =
21+
INPUT_FILES =
22+
OUTPUT_FILES =
23+
SCRIPT = $PWD/driver.py
24+
25+
[dask_worker]
26+
CLASS = DASK_WORKER
27+
SUB_CLASS =
28+
NAME = DaskWorker
29+
NPROC = 1
30+
BIN_PATH =
31+
INPUT_FILES =
32+
OUTPUT_FILES =
33+
SCRIPT = $PWD/dask_worker.py
34+
EXECUTABLE = $PWD/sleep

examples-proposed/dask/dask_worker.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import copy
2+
from time import sleep
3+
from ipsframework import Component
4+
5+
6+
def myFun(*args):
7+
print(f"myFun({args[0]})")
8+
sleep(float(args[0]))
9+
return 0
10+
11+
12+
class DaskWorker(Component):
13+
def step(self, timestamp=0.0):
14+
cwd = self.services.get_working_dir()
15+
self.services.create_task_pool('pool')
16+
17+
duration = 0.5
18+
self.services.add_task('pool', 'binary', 1, cwd, self.EXECUTABLE, duration)
19+
self.services.add_task('pool', 'function', 1, cwd, myFun, duration)
20+
self.services.add_task('pool', 'method', 1, cwd, copy.copy(self).myMethod, duration)
21+
22+
ret_val = self.services.submit_tasks('pool',
23+
use_dask=True,
24+
dask_nodes=1)
25+
print('ret_val =', ret_val)
26+
exit_status = self.services.get_finished_tasks('pool')
27+
print('exit_status = ', exit_status)
28+
29+
def myMethod(self, *args):
30+
print(f"myMethod({args[0]})")
31+
sleep(float(args[0]))
32+
return 0

examples-proposed/dask/driver.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from ipsframework import Component
2+
3+
4+
class Driver(Component):
5+
def step(self, timestamp=0.0):
6+
worker_comp = self.services.get_port('WORKER')
7+
self.services.call(worker_comp, 'step', 0.0)

examples-proposed/dask/platform.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
MPIRUN = eval
2+
NODE_DETECTION = manual
3+
CORES_PER_NODE = 1
4+
SOCKETS_PER_NODE = 1
5+
NODE_ALLOCATION_MODE = shared
6+
HOST = localhost
7+
SCRATCH =
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"code": "DASK_WORKER__DaskWorker",
3+
"eventtype": "IPS_LAUNCH_DASK_TASK",
4+
"walltime": "2.33",
5+
"comment": "task_name = method, Target = myMethod(0.5)",
6+
}
7+
{
8+
"code": "DASK_WORKER__DaskWorker",
9+
"eventtype": "IPS_LAUNCH_DASK_TASK",
10+
"walltime": "2.33",
11+
"comment": "task_name = function, Target = myFun(0.5)",
12+
}
13+
{
14+
"code": "DASK_WORKER__DaskWorker",
15+
"eventtype": "IPS_LAUNCH_DASK_TASK",
16+
"walltime": "2.33",
17+
"state": "Running",
18+
"comment": "task_name = binary, Target = sleep 0.5",
19+
}
20+
{
21+
"code": "DASK_WORKER__DaskWorker",
22+
"eventtype": "IPS_TASK_END",
23+
"walltime": "2.83",
24+
"comment": "task_name = method, elapsed time = 0.50s",
25+
}
26+
{
27+
"code": "DASK_WORKER__DaskWorker",
28+
"eventtype": "IPS_TASK_END",
29+
"walltime": "2.83",
30+
"comment": "task_name = function, elapsed time = 0.50s",
31+
}
32+
{
33+
"code": "DASK_WORKER__DaskWorker",
34+
"eventtype": "IPS_TASK_END",
35+
"walltime": "2.85",
36+
"state": "Running",
37+
"comment": "task_name = binary, elapsed time = 0.52s",
38+
}

0 commit comments

Comments
 (0)