Browse Source

prelaunch tasks on demand

Román Cárdenas 2 years ago
parent
commit
60a8fcbcb6
4 changed files with 95 additions and 41 deletions
  1. 3 0
      .gitmodules
  2. 82 7
      devstone_comparative.py
  3. 9 34
      setup.sh
  4. 1 0
      simulators/xdevs.rs-new

+ 3 - 0
.gitmodules

@@ -22,3 +22,6 @@
 [submodule "simulators/pythonpdevs"]
 	path = simulators/pythonpdevs
 	url = https://msdl.uantwerpen.be/git/yentl/PythonPDEVS.git
+[submodule "simulators/xdevs.rs-new"]
+	path = simulators/xdevs.rs-new
+	url = git@github.com:iscar-ucm/xdevs.rs.git

+ 82 - 7
devstone_comparative.py

@@ -12,6 +12,45 @@ DEFAULT_MODEL_TYPES = ("LI", "HI", "HO", "HOmod")
 DEFAULT_MAX_TIME = 1e10
 DEFAULT_NUM_REPS = 30
 
+PRELAUNCH_TASKS = {
+    "adevs": [
+        "cmake -S devstone/adevs/ -B devstone/adevs/build/ -D CMAKE_BUILD_TYPE=Release",
+        "cmake --build devstone/adevs/build/ --target devstone",
+    ],
+    "cadmium": {
+        "v1": [
+            "cmake -S devstone/cadmium/ -B devstone/cadmium/build/ -D CMAKE_BUILD_TYPE=Release",
+            "cmake --build devstone/cadmium/build/ --target devstone",
+        ],
+        "v2": {
+            "sequential": [
+                "cmake -S simulators/cadmium_v2/ -B simulators/cadmium_v2/build/ -D CMAKE_BUILD_TYPE=Release",
+                "cmake --build simulators/cadmium_v2/build/ --target main_devstone",
+            ],
+            "parallel": [
+                "cmake -S simulators/cadmium_v2/ -B simulators/cadmium_v2/build/ -D CMAKE_BUILD_TYPE=Release",
+                "cmake --build simulators/cadmium_v2/build/ --target parallel_main_devstone",
+            ],
+        },
+    },
+    "xdevs": {
+        "c": ["cd simulators/xdevs.c/ && make"],
+        "cpp": ["cd simulators/xdevs.cpp/ && make"],
+        "java": {
+            "sequential": ["cd simulators/xdevs.java/ && mvn clean && mvn compile && mvn package"],
+            "parallel": ["cd simulators/xdevs.java/ && mvn clean && mvn compile && mvn package"],
+        },
+        "rs": {
+            "old": ["cargo build --manifest-path simulators/xdevs.rs/Cargo.toml --release"],
+            "new": {
+                "sequential": ["cargo build --manifest-path simulators/xdevs.rs-new/Cargo.toml --release  --example devstone"],
+                "parallel": ["cargo build --manifest-path simulators/xdevs.rs-new/Cargo.toml --release --features par_all_no_couplings --example devstone"],
+                "fullparallel": ["cargo build --manifest-path simulators/xdevs.rs-new/Cargo.toml --release --features par_all --example devstone"],
+            }
+        },
+    },
+}
+
 COMMANDS = {
     "adevs": "devstone/adevs/bin/devstone {model_type} {width} {depth} {int_cycles} {ext_cycles}",
     "cadmium": {
@@ -40,7 +79,14 @@ COMMANDS = {
             "parallel": "java -cp simulators/xdevs.java/target/xdevs-2.0.3-jar-with-dependencies.jar xdevs.lib.performance.DevStoneSimulation --model={model_type} --width={width} --depth={depth} --delay-distribution=Constant-{int_cycles} --coordinator=CoordinatorParallel",
         },
         "py": "python3 simulators/xdevs.py/xdevs/examples/devstone/devstone.py {model_type} {width} {depth} {int_cycles} {ext_cycles}",
-        "rs": "simulators/xdevs.rs/target/release/xdevs {model_type} {width} {depth} {int_cycles} {ext_cycles}",
+        "rs": {
+            "old": "simulators/xdevs.rs/target/release/xdevs {model_type} {width} {depth} {int_cycles} {ext_cycles}",
+            "new": {
+                "sequential": "simulators/xdevs.rs-new/target/release/examples/devstone {model_type} {width} {depth} {int_cycles} {ext_cycles}",
+                "parallel": "simulators/xdevs.rs-new/target/release/examples/devstone {model_type} {width} {depth} {int_cycles} {ext_cycles}",
+                "fullparallel": "simulators/xdevs.rs-new/target/release/examples/devstone {model_type} {width} {depth} {int_cycles} {ext_cycles}",
+            }
+        },
     },
 }
 
@@ -57,6 +103,7 @@ def serialize_simengines(res: list[str], prefix: str, flavors: str | dict):
             new_prefix = f'{prefix}-{key}' if prefix else key
             serialize_simengines(res, new_prefix, val)
 
+
 def parse_args():
     parser = argparse.ArgumentParser(description='Script to compare DEVStone implementations with different engines')
     parser.add_argument('-m', '--model-types', help='DEVStone model type (LI, HI, HO, HOmod)')
@@ -97,30 +144,44 @@ def parse_args():
         else:
             raise ValueError(f'invalid number of params ({param})')
 
-    if args.include_engines:
-        args.include_engines = args.include_engines.split(',')
-        # TODO if an engine has more than one flavor, serialize here (e.g., xdevs -> all the xdevs stuff)
-    else:
-        args.include_engines = []
-        serialize_simengines(args.include_engines, '', COMMANDS)
+    engines = args.include_engines.split(',') if args.include_engines else list(COMMANDS.keys())
+    args.include_engines = []
+    for eng in engines:
+        commands = COMMANDS
+        for s in eng.split('-'):
+            commands = commands.get(s, dict())
+        subengines = []
+        serialize_simengines(subengines, '', commands)
+        if not subengines:
+            raise RuntimeError(f'unknown simulation engine {eng}')
+        subengines = [f'{eng}-{x}' if x else f'{eng}' for x in subengines]
+        args.include_engines.extend(subengines)
+
     if args.exclude_engines:
         args.include_engines = [x for x in args.include_engines if x not in args.exclude_engines.split(",")]
 
+    args.prelaunch = {}
     args.commands = {}
     args.regex = {}
     for eng in args.include_engines:
+        prelaunch = PRELAUNCH_TASKS
         cmd = COMMANDS
         regex = CUSTOM_RE
         for s in eng.split('-'):
+            if isinstance(prelaunch, dict):
+                prelaunch = prelaunch.get(s, dict())
             cmd = cmd.get(s, dict())
             if not isinstance(regex, str):
                 regex = regex.get(s, DEFAULT_RE)
+        if isinstance(prelaunch, dict):
+            prelaunch = None
         if not cmd:
             raise RuntimeError(f'unknown simulation engine {eng}')
         if isinstance(cmd, dict):
             # TODO instead of this, serialize all the flavors of the engine
             raise RuntimeError(f'There are more than one flavor for the engine {eng}')
         else:
+            args.prelaunch[eng] = prelaunch
             args.commands[eng] = cmd
             args.regex[eng] = regex
 
@@ -133,6 +194,15 @@ def parse_args():
     return args
 
 
+def execute_prelaunch(cmd):
+    try:
+        result = subprocess.run(cmd.split(), stdout=subprocess.PIPE)
+    except Exception as e:
+        print(f"Error executing prelaunch command. ({str(e)})")
+        return
+    print(result.stdout)
+
+
 def execute_cmd(cmd, regex, csv_writer):
     # Execute simulation
     try:
@@ -192,6 +262,11 @@ if __name__ == "__main__":
         csv_writer.writerow(("engine", "iter", "model", "width", "depth", "int_delay", "ext_delay", "model_time", "runner_time", "sim_time", "total_time"))
 
         for engine, engine_cmd in args.commands.items():
+            engine_prelaunch = args.prelaunch[engine]
+            if engine_prelaunch is not None:
+                print(f'({engine}) executing prelaunch tasks...')
+                for prelaunch_cmd in engine_prelaunch:
+                    execute_prelaunch(prelaunch_cmd)
             engine_regex = args.regex[engine]
             for params in args.params:
                 model_type, width, depth, int_cycles, ext_cycles = params

+ 9 - 34
setup.sh

@@ -2,16 +2,16 @@
 git submodule update --init --recursive
 git submodule update --recursive
 # Set up Cadmium v1 repository
-cd simulators/cadmium
+cd simulators/cadmium || exit
 git checkout b6636f791d3fbff41b6b72e1d9e34ce18152065d
 # Set up Cadmium v2 repository
-cd ../cadmium_v2
+cd ../cadmium_v2 || exit
 git checkout devel # TODO set to a specific commit when available
 # Set up PythonPDEVS repository
-cd ../pythonpdevs
+cd ../pythonpdevs || exit
 git checkout 50164a92c6
 # Set up xDEVS C repository
-cd ../xdevs.c
+cd ../xdevs.c || exit
 git checkout 9c2a54ddd671a790528f6ba4d5a71c2732a431dd
 # Set up xDEVS C++ repository
 cd ../xdevs.cpp || exit
@@ -27,41 +27,16 @@ git checkout b53a6f170350af8296af43d1b2334e173e95990c
 # Set up xDEVS Rust repository
 cd ../xdevs.rs || exit
 git checkout 7d4179e61e44f53bb67e2a32abdb3a1ca41752af
+# Set up xDEVS Rust (new) repository
+cd ../xdevs.rs-new || exit
+git checkout 64670afaeabfbf2bf1d34edd64cbc06bdfaad51d
 # Go back to root directory
 cd ../..
 
-# COMPILE THE DEVSTONE PROJECT FOR ALL THE DIFFERENT ENGINES
-# Compile DEVStone for aDEVS
-cd devstone/adevs || exit
-cmake -S . -B build/ -D CMAKE_BUILD_TYPE=Release
-cmake --build build/ --target devstone
-# Compile DEVStone for Cadmium v1
-cd ../cadmium || exit
-cmake -S . -B build/ -D CMAKE_BUILD_TYPE=Release
-cmake --build build/ --target devstone
-# Compile DEVStone for Cadmium v2
-cd ../../simulators/cadmium_v2 || exit
-cmake -S . -B build/ -D CMAKE_BUILD_TYPE=Release
-cmake --build build/ --target main_devstone parallel_main_devstone
+# COMPILE THE DEVSTONE PROJECT FOR ALL THE PYTHON ENGINES
 # Install PythonPDEVS
-cd ../pythonpdevs/src || exit
+cd simulators/pythonpdevs/src || exit
 python3 setup.py install --user  # TODO this fails
-# Compile DEVStone for xDEVS C
-cd ../../xdevs.c/examples/devstone/ || exit
-make
-# Compile DEVStone for xDEVS C++
-cd ../../../xdevs.cpp/src/xdevs/examples/DevStone/ || exit
-make
-# TODO xDEVS C#
-# TODO xDEVS Go
-# Compile xDEVS java
-cd ../../../../../xdevs.java || exit
-mvn clean
-mvn compile
-mvn package
 # Install xDEVS Python
 cd ../xdevs.py || exit
 python3 setup.py install
-# Compile DEVStone for xDEVS Rust
-cd ../xdevs.rs || exit
-cargo build --release

+ 1 - 0
simulators/xdevs.rs-new

@@ -0,0 +1 @@
+Subproject commit 64670afaeabfbf2bf1d34edd64cbc06bdfaad51d