Skip to content
Merged
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
44 changes: 36 additions & 8 deletions example/cpp-exchange/redis/driver.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,63 @@
import os
import pathlib
import shutil
import textwrap
import time

from smartsim import Experiment

HERE = pathlib.Path(__file__).parent.absolute()
HERE = pathlib.Path(__file__).resolve().parent
ROOT = HERE.parent.parent.parent
BUILD = ROOT / "build"
EXAMPLES_BIN_DIR = ROOT / "install" / "bin" / "examples"


def main() -> int:
exp = Experiment("cpp-sr-client-exchange")
exp_name = "cpp-sr-client-exchange"
producer_name = "producer"
consumer_name = "consumer"

db = exp.create_database(db_nodes=1, interface="hsn0")
os.environ["SR_LOG_LEVEL"] = "QUIET"
if (HERE / exp_name).exists():
shutil.rmtree(HERE / exp_name)

producer_settings = exp.create_run_settings(os.fspath(BUILD / "redis-cpp-producer"))
exp = Experiment(exp_name, launcher="local")

db = exp.create_database(db_nodes=1, interface="lo")

producer_settings = exp.create_run_settings(
os.fspath(EXAMPLES_BIN_DIR / "redis-cpp-producer")
)
producer = exp.create_model("producer", producer_settings)

consumer_settings = exp.create_run_settings(os.fspath(BUILD / "redis-cpp-consumer"))
consumer_settings = exp.create_run_settings(
os.fspath(EXAMPLES_BIN_DIR / "redis-cpp-consumer")
)
consumer = exp.create_model("consumer", consumer_settings)

exp.generate(db, producer, consumer)
exp.start(db, block=False)
time.sleep(3)

try:
exp.start(producer, block=True)
exp.start(consumer, block=True)
print("SmartSim is running the producer")
exp.start(producer, block=True, monitor=False)
print("SmartSim is running the consumer")
exp.start(consumer, block=True, monitor=False)
finally:
exp.stop(db)

print("PRODUCER OUTPUT:")
with open(
HERE / exp_name / producer_name / f"{producer_name}.out", "r", encoding="utf-8"
) as f:
print(textwrap.indent(f.read(), " "))

print("CONSUMER OUTOUT:")
with open(
HERE / exp_name / consumer_name / f"{consumer_name}.out", "r", encoding="utf-8"
) as f:
print(textwrap.indent(f.read(), " "))

return 0


Expand Down
1 change: 1 addition & 0 deletions example/cpp-exchange/redis/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smartsim @ git+https://github.com/CrayLabs/SmartSim.git@1e0ce3a
24 changes: 24 additions & 0 deletions example/cpp-exchange/redis/result.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SmartSim is running the producer
SmartSim is running the consumer
PRODUCER OUTPUT:
===========================
Hello World from Producer!!
---------------------------
---------------------------
Goodbye from Producer
===========================

CONSUMER OUTOUT:
===========================
Hello World from Consumer!!
---------------------------
Some Int: 123
Some Float: 1.23
Some Int Tensor: [ 1, 2, 3, 4, 5, 6, 7, 8, ]
\ -> Dims: [ 2, 4, ]
Some Float Tensor: [ 0.120000, 3.450000, 6.780000, 9.123000, ]
\ -> Dims: [ 4, ]
---------------------------
Goodbye from Consumer!!
===========================

1 change: 1 addition & 0 deletions tests/examples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _run(self, cwd, out, err) -> int:
pytest.param(example, id=example.test_id, marks=example.marks)
for example in [
LocalExample(EXAMPLES_DIR / "cpp-exchange/in-mem"),
LocalExample(EXAMPLES_DIR / "cpp-exchange/redis"),
DragonExample(EXAMPLES_DIR / "cpp-exchange/dragon", num_nodes=None),
DragonExample(
EXAMPLES_DIR / "py-cpp-exchange/dragon",
Expand Down
Loading