diff --git a/example/cpp-exchange/redis/driver.py b/example/cpp-exchange/redis/driver.py index b5411c3..0d06865 100644 --- a/example/cpp-exchange/redis/driver.py +++ b/example/cpp-exchange/redis/driver.py @@ -1,23 +1,37 @@ 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) @@ -25,11 +39,25 @@ def main() -> int: 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 diff --git a/example/cpp-exchange/redis/requirements.txt b/example/cpp-exchange/redis/requirements.txt new file mode 100644 index 0000000..49dba44 --- /dev/null +++ b/example/cpp-exchange/redis/requirements.txt @@ -0,0 +1 @@ +smartsim @ git+https://github.com/CrayLabs/SmartSim.git@1e0ce3a diff --git a/example/cpp-exchange/redis/result.txt b/example/cpp-exchange/redis/result.txt new file mode 100644 index 0000000..8b35b47 --- /dev/null +++ b/example/cpp-exchange/redis/result.txt @@ -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!! + =========================== + diff --git a/tests/examples/conftest.py b/tests/examples/conftest.py index 263b9b3..4d70dda 100644 --- a/tests/examples/conftest.py +++ b/tests/examples/conftest.py @@ -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",