diff --git a/simulation-system/libs/csle-common/src/csle_common/controllers/installation_controller.py b/simulation-system/libs/csle-common/src/csle_common/controllers/installation_controller.py index b96eb9147..4d9f66950 100644 --- a/simulation-system/libs/csle-common/src/csle_common/controllers/installation_controller.py +++ b/simulation-system/libs/csle-common/src/csle_common/controllers/installation_controller.py @@ -17,15 +17,16 @@ def install_all_emulations() -> None: cmd = "cd $CSLE_HOME/emulation-system/envs/ && make install" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_emulation(emulation_name: str) -> None: @@ -39,15 +40,16 @@ def install_emulation(emulation_name: str) -> None: cmd = f"cd $CSLE_HOME/emulation-system/envs/ && make install_{emulation_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_emulation(emulation_name: str) -> None: @@ -61,16 +63,16 @@ def uninstall_emulation(emulation_name: str) -> None: cmd = f"cd $CSLE_HOME/emulation-system/envs/ && make uninstall_{emulation_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() - + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_all_emulations() -> None: """ @@ -81,15 +83,16 @@ def uninstall_all_emulations() -> None: cmd = "cd $CSLE_HOME/emulation-system/envs/ && make uninstall" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_all_simulations() -> None: @@ -101,15 +104,16 @@ def install_all_simulations() -> None: cmd = "cd $CSLE_HOME/simulation-system/envs/ && make install" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_simulation(simulation_name: str) -> None: @@ -122,15 +126,16 @@ def install_simulation(simulation_name: str) -> None: cmd = f"cd $CSLE_HOME/simulation-system/envs/ && make install_{simulation_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_simulation(simulation_name: str) -> None: @@ -143,15 +148,16 @@ def uninstall_simulation(simulation_name: str) -> None: cmd = f"cd $CSLE_HOME/simulation-system/envs/ && make uninstall_{simulation_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_all_simulations() -> None: @@ -163,15 +169,16 @@ def uninstall_all_simulations() -> None: cmd = "cd $CSLE_HOME/simulation-system/envs/ && make uninstall" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_derived_images() -> None: @@ -183,15 +190,16 @@ def install_derived_images() -> None: cmd = "cd $CSLE_HOME/emulation-system/derived_images/ && make build" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_derived_image(image_name: str) -> None: @@ -204,15 +212,16 @@ def install_derived_image(image_name: str) -> None: cmd = f"cd $CSLE_HOME/emulation-system/derived_images/ && make {image_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_derived_images() -> None: @@ -224,15 +233,16 @@ def uninstall_derived_images() -> None: cmd = "cd $CSLE_HOME/emulation-system/derived_images/ && make rm_image" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_derived_image(image_name: str) -> None: @@ -245,15 +255,16 @@ def uninstall_derived_image(image_name: str) -> None: cmd = f"cd $CSLE_HOME/emulation-system/derived_images/ && make rm_{image_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_base_images() -> None: @@ -265,15 +276,16 @@ def install_base_images() -> None: cmd = "cd $CSLE_HOME/emulation-system/base_images/ && make build" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_base_image(image_name: str) -> None: @@ -286,15 +298,16 @@ def install_base_image(image_name: str) -> None: cmd = f"cd $CSLE_HOME/emulation-system/base_images/ && make {image_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_base_images() -> None: @@ -306,15 +319,16 @@ def uninstall_base_images() -> None: cmd = "cd $CSLE_HOME/emulation-system/base_images/ && make rm_image" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_base_image(image_name: str) -> None: @@ -327,15 +341,16 @@ def uninstall_base_image(image_name: str) -> None: cmd = f"cd $CSLE_HOME/emulation-system/base_images/ && make rm_{image_name}" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def uninstall_metastore() -> None: @@ -347,15 +362,16 @@ def uninstall_metastore() -> None: cmd = "cd $CSLE_HOME/metastore/ && make clean" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() @staticmethod def install_metastore() -> None: @@ -367,12 +383,13 @@ def install_metastore() -> None: cmd = "cd $CSLE_HOME/metastore/ && make build" p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) while True: - out = p.stdout.read(1) - if p.poll() is not None: - break - if out != '': - try: - sys.stdout.write(out.decode("utf-8")) - except Exception: - pass - sys.stdout.flush() + if p.stdout is not None: + out = p.stdout.read(1) + if p.poll() is not None: + break + if out != b'': + try: + sys.stdout.write(out.decode("utf-8")) + except Exception: + pass + sys.stdout.flush() diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/state.py b/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/state.py index 21b8ca4d2..a0220637b 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/state.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/state.py @@ -35,7 +35,7 @@ def from_dict(d: Dict[str, Any]) -> "State": ) return obj - def to_dict(self) -> Dict[str, Any]: + def to_dict(self):# -> Dict[str, Any]: """ Converts the object to a dict representation diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/transition_operator_config.py b/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/transition_operator_config.py index 16509e138..5bc3bad2b 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/transition_operator_config.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/simulation_config/transition_operator_config.py @@ -7,7 +7,7 @@ class TransitionOperatorConfig(JSONSerializable): DTO representing the transition operator definition of a simulation """ - def __init__(self, transition_tensor: List): + def __init__(self, transition_tensor: List[Any]): """ Initializes the DTO diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/empirical_conditional.py b/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/empirical_conditional.py index 9c8fb1bea..1cf7c47cf 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/empirical_conditional.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/empirical_conditional.py @@ -37,7 +37,7 @@ def from_dict(d: Dict[str, Any]) -> "EmpiricalConditional": sample_space=d["sample_space"], probabilities=d["probabilities"] ) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self):# -> Dict[str, Any]: """ :return: a dict representation of the DTO """ diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/mcmc_posterior.py b/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/mcmc_posterior.py index 1a3165007..dfd5af180 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/mcmc_posterior.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/system_identification/mcmc_posterior.py @@ -33,7 +33,7 @@ def from_dict(d: Dict[str, Any]) -> "MCMCPosterior": return MCMCPosterior(posterior_name=d["posterior_name"], samples=d["samples"], densities=d["densities"], sample_space=d["sample_space"]) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self):# -> Dict[Any, Any]: """ :return: a dict representation of the DTO """ diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/training/hparam.py b/simulation-system/libs/csle-common/src/csle_common/dao/training/hparam.py index 3e2e8b672..4122a449d 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/training/hparam.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/training/hparam.py @@ -7,7 +7,7 @@ class HParam(JSONSerializable): DTO class representing a hyperparameter """ - def __init__(self, value: Union[int, float, str, List], name: str, descr: str): + def __init__(self, value: Union[int, float, str, List[Any]], name: str, descr: str): """ Initializes the DTO diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/training/policy.py b/simulation-system/libs/csle-common/src/csle_common/dao/training/policy.py index 55cea1641..884f02728 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/training/policy.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/training/policy.py @@ -1,4 +1,4 @@ -from typing import Union, List, Dict +from typing import Union, List, Dict, Any from abc import abstractmethod from csle_common.dao.training.agent_type import AgentType from csle_common.dao.training.player_type import PlayerType @@ -31,7 +31,7 @@ def action(self, o: Union[List[Union[int, float]], int, float]) -> Union[int, fl pass @abstractmethod - def to_dict(self) -> Dict: + def to_dict(self) -> Dict[Any, Any]: """ Converts the object to a dict representation @@ -51,7 +51,7 @@ def stage_policy(self, o: Union[List[Union[int, float]], int, float]) -> List[Li @staticmethod @abstractmethod - def from_dict(d: Dict) -> "Policy": + def from_dict(d: Dict[Any, Any]) -> "Policy": """ Converts a dict representation of the object to an instance