gym-csle-stopping-game 0.6.1__py3-none-any.whl → 0.6.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gym-csle-stopping-game might be problematic. Click here for more details.

@@ -1 +1 @@
1
- __version__ = '0.6.1'
1
+ __version__ = '0.6.3'
@@ -7,24 +7,10 @@ import math
7
7
  import csle_common.constants.constants as constants
8
8
  from csle_common.dao.simulation_config.base_env import BaseEnv
9
9
  from csle_common.dao.simulation_config.simulation_trace import SimulationTrace
10
- from csle_common.dao.training.policy import Policy
11
- from csle_common.dao.emulation_config.emulation_env_state import EmulationEnvState
12
- from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
13
- from csle_common.dao.simulation_config.simulation_env_config import SimulationEnvConfig
14
- from csle_common.dao.emulation_config.emulation_simulation_trace import EmulationSimulationTrace
15
- from csle_common.dao.emulation_action.attacker.emulation_attacker_stopping_actions \
16
- import EmulationAttackerStoppingActions
17
- from csle_common.dao.emulation_action.attacker.emulation_attacker_action import EmulationAttackerAction
18
- from csle_common.dao.emulation_action.defender.emulation_defender_stopping_actions \
19
- import EmulationDefenderStoppingActions
20
- from csle_common.metastore.metastore_facade import MetastoreFacade
21
- from csle_common.logging.log import Logger
22
- from csle_system_identification.emulator import Emulator
23
10
  from gym_csle_stopping_game.util.stopping_game_util import StoppingGameUtil
24
11
  from gym_csle_stopping_game.dao.stopping_game_config import StoppingGameConfig
25
12
  from gym_csle_stopping_game.dao.stopping_game_state import StoppingGameState
26
13
  import gym_csle_stopping_game.constants.constants as env_constants
27
- from csle_common.dao.emulation_config.emulation_trace import EmulationTrace
28
14
 
29
15
 
30
16
  class StoppingGameEnv(BaseEnv):
@@ -42,7 +28,6 @@ class StoppingGameEnv(BaseEnv):
42
28
 
43
29
  # Initialize environment state
44
30
  self.state = StoppingGameState(b1=self.config.b1, L=self.config.L)
45
-
46
31
  # Setup spaces
47
32
  self.attacker_observation_space = self.config.attacker_observation_space()
48
33
  self.defender_observation_space = self.config.defender_observation_space()
@@ -73,7 +58,7 @@ class StoppingGameEnv(BaseEnv):
73
58
  a1, a2_profile = action_profile
74
59
  pi2, a2 = a2_profile
75
60
  assert pi2.shape[0] == len(self.config.S)
76
- assert pi2.shape[1] == len(self.config.A1)
61
+ assert pi2.shape[1] == len(self.config.A2)
77
62
  done = False
78
63
  info: Dict[str, Any] = {}
79
64
 
@@ -84,8 +69,7 @@ class StoppingGameEnv(BaseEnv):
84
69
  else:
85
70
  # Compute r, s', b',o'
86
71
  r = self.config.R[self.state.l - 1][a1][a2][self.state.s]
87
- self.state.s = StoppingGameUtil.sample_next_state(l=self.state.l, a1=a1, a2=a2,
88
- T=self.config.T,
72
+ self.state.s = StoppingGameUtil.sample_next_state(l=self.state.l, a1=a1, a2=a2, T=self.config.T,
89
73
  S=self.config.S, s=self.state.s)
90
74
  o = StoppingGameUtil.sample_next_observation(Z=self.config.Z,
91
75
  O=self.config.O, s_prime=self.state.s)
@@ -246,95 +230,6 @@ class StoppingGameEnv(BaseEnv):
246
230
  info[env_constants.ENV_METRICS.TIME_STEP] = self.state.t
247
231
  return (defender_obs, attacker_obs), info
248
232
 
249
- @staticmethod
250
- def emulation_evaluation(env: "StoppingGameEnv", n_episodes: int, intrusion_seq: List[EmulationAttackerAction],
251
- defender_policy: Policy,
252
- attacker_policy: Policy,
253
- emulation_env_config: EmulationEnvConfig,
254
- simulation_env_config: SimulationEnvConfig
255
- ) -> List[EmulationSimulationTrace]:
256
- """
257
- Utility function for evaluating a strategy profile in the emulation environment
258
-
259
- :param env: the environment to use for evaluation
260
- :param n_episodes: the number of evaluation episodes
261
- :param intrusion_seq: the intrusion sequence for the evaluation (sequence of attacker actions)
262
- :param defender_policy: the defender policy for the evaluation
263
- :param attacker_policy: the attacker policy for the evaluation
264
- :param emulation_env_config: configuration of the emulation environment for the evaluation
265
- :param simulation_env_config: configuration of the simulation environment for the evaluation
266
- :return: traces with the evaluation results
267
- """
268
- logger = Logger.__call__().get_logger()
269
- traces = []
270
- s = EmulationEnvState(emulation_env_config=emulation_env_config)
271
- s.initialize_defender_machines()
272
- for i in range(n_episodes):
273
- done = False
274
- defender_obs_space = simulation_env_config.joint_observation_space_config.observation_spaces[0]
275
- b = env.state.b1
276
- o, _ = env.reset()
277
- (d_obs, a_obs) = o
278
- t = 0
279
- s.reset()
280
- emulation_trace = EmulationTrace(initial_attacker_observation_state=s.attacker_obs_state,
281
- initial_defender_observation_state=s.defender_obs_state,
282
- emulation_name=emulation_env_config.name)
283
- simulation_trace = SimulationTrace(simulation_env=env.config.env_name)
284
- while not done:
285
- a1 = defender_policy.action(d_obs)
286
- a2 = attacker_policy.action(a_obs)
287
- o, r, done, info, _ = env.step((a1, a2))
288
- (d_obs, a_obs) = o
289
- r_1, r_2 = r
290
- logger.debug(f"a1:{a1}, a2:{a2}, d_obs:{d_obs}, a_obs:{a_obs}, r:{r}, done:{done}, info: {info}")
291
- if a1 == 0:
292
- defender_action = EmulationDefenderStoppingActions.CONTINUE(index=-1)
293
- else:
294
- defender_action = EmulationDefenderStoppingActions.CONTINUE(index=-1)
295
- if env.state.s == 1:
296
- if t >= len(intrusion_seq):
297
- t = 0
298
- attacker_action = intrusion_seq[t]
299
- else:
300
- attacker_action = EmulationAttackerStoppingActions.CONTINUE(index=-1)
301
- emulation_trace, s = Emulator.run_actions(
302
- s=s,
303
- emulation_env_config=emulation_env_config, attacker_action=attacker_action,
304
- defender_action=defender_action, trace=emulation_trace,
305
- sleep_time=emulation_env_config.kafka_config.time_step_len_seconds)
306
- o_components = [s.defender_obs_state.snort_ids_alert_counters.severe_alerts,
307
- s.defender_obs_state.snort_ids_alert_counters.warning_alerts,
308
- s.defender_obs_state.aggregated_host_metrics.num_failed_login_attempts]
309
- o_components_str = ",".join(list(map(lambda x: str(x), o_components)))
310
- logger.debug(f"o_components:{o_components}")
311
- logger.debug(f"observation_id_to_observation_vector_inv:"
312
- f"{defender_obs_space.observation_id_to_observation_vector_inv}")
313
- logger.debug(f"observation_id_to_observation_vector_inv:"
314
- f"{o_components_str in defender_obs_space.observation_id_to_observation_vector_inv}")
315
- emulation_o = 0
316
- if o_components_str in defender_obs_space.observation_id_to_observation_vector_inv:
317
- emulation_o = defender_obs_space.observation_id_to_observation_vector_inv[o_components_str]
318
- logger.debug(f"o:{emulation_o}")
319
- b = StoppingGameUtil.next_belief(o=emulation_o, a1=a1, b=b, pi2=a2, config=env.config,
320
- l=env.state.l, a2=a2)
321
- d_obs[1] = b[1]
322
- a_obs[1] = b[1]
323
- logger.debug(f"b:{b}")
324
- simulation_trace.defender_rewards.append(r_1)
325
- simulation_trace.attacker_rewards.append(r_2)
326
- simulation_trace.attacker_actions.append(a2)
327
- simulation_trace.defender_actions.append(a1)
328
- simulation_trace.infos.append(info)
329
- simulation_trace.states.append(s)
330
- simulation_trace.beliefs.append(b[1])
331
- simulation_trace.infrastructure_metrics.append(emulation_o)
332
-
333
- em_sim_trace = EmulationSimulationTrace(emulation_trace=emulation_trace, simulation_trace=simulation_trace)
334
- MetastoreFacade.save_emulation_simulation_trace(em_sim_trace)
335
- traces.append(em_sim_trace)
336
- return traces
337
-
338
233
  def render(self, mode: str = 'human'):
339
234
  """
340
235
  Renders the environment. Supported rendering modes: (1) human; and (2) rgb_array
@@ -437,6 +332,8 @@ class StoppingGameEnv(BaseEnv):
437
332
  :param l: the number of stops remaining
438
333
  :return: the observation
439
334
  """
335
+ if not history:
336
+ raise ValueError("History must not be empty")
440
337
  return [history[-1]]
441
338
 
442
339
  def generate_random_particles(self, o: int, num_particles: int) -> List[int]:
@@ -4,12 +4,7 @@ import numpy.typing as npt
4
4
  from csle_common.dao.simulation_config.base_env import BaseEnv
5
5
  from gym_csle_stopping_game.dao.stopping_game_defender_pomdp_config import StoppingGameDefenderPomdpConfig
6
6
  from csle_common.dao.simulation_config.simulation_trace import SimulationTrace
7
- from csle_common.dao.training.policy import Policy
8
- from csle_common.dao.emulation_config.emulation_env_config import EmulationEnvConfig
9
- from csle_common.dao.simulation_config.simulation_env_config import SimulationEnvConfig
10
- from csle_common.dao.emulation_config.emulation_simulation_trace import EmulationSimulationTrace
11
7
  from csle_common.dao.emulation_config.emulation_trace import EmulationTrace
12
- from csle_common.dao.emulation_action.attacker.emulation_attacker_action import EmulationAttackerAction
13
8
  from gym_csle_stopping_game.envs.stopping_game_env import StoppingGameEnv
14
9
  from gym_csle_stopping_game.util.stopping_game_util import StoppingGameUtil
15
10
 
@@ -103,28 +98,6 @@ class StoppingGamePomdpDefenderEnv(BaseEnv):
103
98
  defender_obs = o[0]
104
99
  return defender_obs, r[0], d, info
105
100
 
106
- @staticmethod
107
- def emulation_evaluation(env: "StoppingGamePomdpDefenderEnv",
108
- n_episodes: int, intrusion_seq: List[EmulationAttackerAction],
109
- defender_policy: Policy,
110
- emulation_env_config: EmulationEnvConfig, simulation_env_config: SimulationEnvConfig) \
111
- -> List[EmulationSimulationTrace]:
112
- """
113
- Utility function for evaluating policies in the emulation environment
114
-
115
- :param env: the environment to use for evaluation
116
- :param n_episodes: the number of episodes to use for evaluation
117
- :param intrusion_seq: the sequence of intrusion actions to use for evaluation
118
- :param defender_policy: the defender policy to use for evaluation
119
- :param emulation_env_config: the configuration of the emulation environment to use for evaluation
120
- :param simulation_env_config: the configuration of the simulation environment to use for evaluation
121
- :return: traces with the evaluation results
122
- """
123
- return StoppingGameEnv.emulation_evaluation(
124
- env=env.stopping_game_env, n_episodes=n_episodes, intrusion_seq=intrusion_seq,
125
- defender_policy=defender_policy, attacker_policy=env.static_attacker_strategy,
126
- emulation_env_config=emulation_env_config, simulation_env_config=simulation_env_config)
127
-
128
101
  def is_defense_action_legal(self, defense_action_id: int) -> bool:
129
102
  """
130
103
  Checks whether a defender action in the environment is legal or not
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gym-csle-stopping-game
3
- Version: 0.6.1
3
+ Version: 0.6.3
4
4
  Summary: OpenAI gym reinforcement learning environment of a Dynkin (Optimal stopping) game in CSLE
5
5
  Author: Kim Hammar
6
6
  Author-email: hammar.kim@gmail.com
@@ -15,11 +15,11 @@ Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Intended Audience :: Science/Research
16
16
  Requires-Python: >=3.8
17
17
  Requires-Dist: gymnasium >=0.27.1
18
- Requires-Dist: csle-base >=0.6.1
19
- Requires-Dist: csle-common >=0.6.1
20
- Requires-Dist: csle-attacker >=0.6.1
21
- Requires-Dist: csle-defender >=0.6.1
22
- Requires-Dist: csle-collector >=0.6.1
18
+ Requires-Dist: csle-base >=0.6.3
19
+ Requires-Dist: csle-common >=0.6.3
20
+ Requires-Dist: csle-attacker >=0.6.3
21
+ Requires-Dist: csle-defender >=0.6.3
22
+ Requires-Dist: csle-collector >=0.6.3
23
23
  Provides-Extra: testing
24
24
  Requires-Dist: pytest >=6.0 ; extra == 'testing'
25
25
  Requires-Dist: pytest-cov >=2.0 ; extra == 'testing'
@@ -1,5 +1,5 @@
1
1
  gym_csle_stopping_game/__init__.py,sha256=ooy6TjxvBi1sZMEX3_mVlvfskqI5GqwITWzI882tfk0,657
2
- gym_csle_stopping_game/__version__.py,sha256=gd3s3RotD0_KL90Tua-YkOr60Jm2C2_wvlEhAT08068,22
2
+ gym_csle_stopping_game/__version__.py,sha256=0ICX8PeSmWoiPyIEViMxRYkvCjQE1KvQPJp9o52KRjw,22
3
3
  gym_csle_stopping_game/constants/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  gym_csle_stopping_game/constants/constants.py,sha256=eIoD9eXifZ73kP-lSlvG-IXCpe4n6D-_aDygx0zOr5U,1030
5
5
  gym_csle_stopping_game/dao/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -8,12 +8,12 @@ gym_csle_stopping_game/dao/stopping_game_config.py,sha256=0_CtrFod1NkZ5eqlwIq68I
8
8
  gym_csle_stopping_game/dao/stopping_game_defender_pomdp_config.py,sha256=3FfNi2-R6n1LqjA644EVq-v7wtp6sqyEkEdBN90-2n0,3753
9
9
  gym_csle_stopping_game/dao/stopping_game_state.py,sha256=v9jEG7-reOQTkSyTZH64jCZ8IyixXFEIk4HIcmhBHiw,2828
10
10
  gym_csle_stopping_game/envs/__init__.py,sha256=SQHaqXI0_2HYsC8i9swXEHDFcXKEYpb8GRP9l_S0Sw8,74
11
- gym_csle_stopping_game/envs/stopping_game_env.py,sha256=g3Pxu-zzgBKFLIQioxenzqyV8gLwB3JJP3mOul6-oq4,22753
11
+ gym_csle_stopping_game/envs/stopping_game_env.py,sha256=J9h73alytskNgHxa7LHM83R1PUNIALDoy0PCItA4P9k,16403
12
12
  gym_csle_stopping_game/envs/stopping_game_mdp_attacker_env.py,sha256=bgoddSXUT-TkDN5T8jJljsul4CRYiPRW7VMmtM7QrwU,10877
13
- gym_csle_stopping_game/envs/stopping_game_pomdp_defender_env.py,sha256=sX680Blqqw69NcXTOypBE97LyR9jLZAumBie5iSjPGc,10580
13
+ gym_csle_stopping_game/envs/stopping_game_pomdp_defender_env.py,sha256=cyC2OuJA41aqE84KA9-oJRWsKLIqzekh8A8zyf6Qo5I,8766
14
14
  gym_csle_stopping_game/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  gym_csle_stopping_game/util/stopping_game_util.py,sha256=s3a5jkUlbh_2K6ALz5riE1w9gfdosf4N3yvrNMBxHUg,11363
16
- gym_csle_stopping_game-0.6.1.dist-info/METADATA,sha256=74argq-Wvchtc2bvAZxh3IYnM_QMlKgBi3WMwMQOOYA,2162
17
- gym_csle_stopping_game-0.6.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
18
- gym_csle_stopping_game-0.6.1.dist-info/top_level.txt,sha256=3DBHkAEI00nq0aXZlJUkXJrLiwkcJCfaFoYcaOzEZUU,23
19
- gym_csle_stopping_game-0.6.1.dist-info/RECORD,,
16
+ gym_csle_stopping_game-0.6.3.dist-info/METADATA,sha256=5j9Qu1NsKZodVZRT970CeQ_BIOvc2DNeFENLMb404LQ,2162
17
+ gym_csle_stopping_game-0.6.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
18
+ gym_csle_stopping_game-0.6.3.dist-info/top_level.txt,sha256=3DBHkAEI00nq0aXZlJUkXJrLiwkcJCfaFoYcaOzEZUU,23
19
+ gym_csle_stopping_game-0.6.3.dist-info/RECORD,,