Skip to content

Commit

Permalink
release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Limmen committed Apr 30, 2023
1 parent 2e56faa commit 30ab139
Show file tree
Hide file tree
Showing 362 changed files with 110,817 additions and 3,219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<![endif]-->

<script data-url_root="../../../../" id="documentation_options" src="../../../../_static/documentation_options.js"></script>
<script src="../../../../_static/jquery.js"></script>
<script src="../../../../_static/underscore.js"></script>
<script src="../../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../../../../_static/doctools.js"></script>
<script src="../../../../_static/sphinx_highlight.js"></script>
<script src="../../../../_static/js/theme.js"></script>
Expand All @@ -23,15 +26,11 @@
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >



<a href="../../../../index.html" class="icon icon-home">
csle-agents
<a href="../../../../index.html" class="icon icon-home"> csle-agents
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
Expand All @@ -57,7 +56,7 @@
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li><a href="../../../../index.html" class="icon icon-home"></a></li>
<li class="breadcrumb-item"><a href="../../../index.html">Module code</a></li>
<li class="breadcrumb-item active">csle_agents.agents.base.base_agent</li>
<li class="wy-breadcrumbs-aside">
Expand All @@ -81,13 +80,13 @@ <h1>Source code for csle_agents.agents.base.base_agent</h1><div class="highlight


<div class="viewcode-block" id="BaseAgent"><a class="viewcode-back" href="../../../../csle_agents.agents.base.html#csle_agents.agents.base.base_agent.BaseAgent">[docs]</a><span class="k">class</span> <span class="nc">BaseAgent</span><span class="p">(</span><span class="n">ABC</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Abstract class representing an RL agent</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">simulation_env_config</span><span class="p">:</span> <span class="n">SimulationEnvConfig</span><span class="p">,</span>
<span class="n">emulation_env_config</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="n">EmulationEnvConfig</span><span class="p">],</span> <span class="n">experiment_config</span><span class="p">:</span> <span class="n">ExperimentConfig</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Initializes the agent</span>

<span class="sd"> :param simulation_env_config: the configuration of the simulation environment</span>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<h1>Source code for csle_agents.agents.dqn.dqn_agent</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Union</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Optional</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">gym</span>
<span class="kn">import</span> <span class="nn">gymnasium</span> <span class="k">as</span> <span class="nn">gym</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">stable_baselines3</span> <span class="kn">import</span> <span class="n">DQN</span>
Expand All @@ -93,6 +93,7 @@ <h1>Source code for csle_agents.agents.dqn.dqn_agent</h1><div class="highlight">
<span class="kn">from</span> <span class="nn">csle_common.dao.simulation_config.state</span> <span class="kn">import</span> <span class="n">State</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.simulation_config.action</span> <span class="kn">import</span> <span class="n">Action</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.training.player_type</span> <span class="kn">import</span> <span class="n">PlayerType</span>
<span class="kn">from</span> <span class="nn">csle_common.util.general_util</span> <span class="kn">import</span> <span class="n">GeneralUtil</span>
<span class="kn">from</span> <span class="nn">csle_agents.agents.base.base_agent</span> <span class="kn">import</span> <span class="n">BaseAgent</span>
<span class="kn">import</span> <span class="nn">csle_agents.constants.constants</span> <span class="k">as</span> <span class="nn">agents_constants</span>

Expand Down Expand Up @@ -126,7 +127,8 @@ <h1>Source code for csle_agents.agents.dqn.dqn_agent</h1><div class="highlight">
<span class="n">progress_percentage</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">pid</span><span class="o">=</span><span class="n">pid</span><span class="p">,</span> <span class="n">experiment_result</span><span class="o">=</span><span class="n">exp_result</span><span class="p">,</span>
<span class="n">emulation_env_name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">emulation_env_config</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">simulation_traces</span><span class="o">=</span><span class="p">[],</span>
<span class="n">num_cached_traces</span><span class="o">=</span><span class="n">agents_constants</span><span class="o">.</span><span class="n">COMMON</span><span class="o">.</span><span class="n">NUM_CACHED_SIMULATION_TRACES</span><span class="p">,</span>
<span class="n">log_file_path</span><span class="o">=</span><span class="n">Logger</span><span class="o">.</span><span class="fm">__call__</span><span class="p">()</span><span class="o">.</span><span class="n">get_log_file_path</span><span class="p">(),</span> <span class="n">descr</span><span class="o">=</span><span class="n">descr</span><span class="p">)</span>
<span class="n">log_file_path</span><span class="o">=</span><span class="n">Logger</span><span class="o">.</span><span class="fm">__call__</span><span class="p">()</span><span class="o">.</span><span class="n">get_log_file_path</span><span class="p">(),</span> <span class="n">descr</span><span class="o">=</span><span class="n">descr</span><span class="p">,</span>
<span class="n">physical_host_ip</span><span class="o">=</span><span class="n">GeneralUtil</span><span class="o">.</span><span class="n">get_host_ip</span><span class="p">())</span>
<span class="n">training_job_id</span> <span class="o">=</span> <span class="n">MetastoreFacade</span><span class="o">.</span><span class="n">save_training_job</span><span class="p">(</span><span class="n">training_job</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">training_job</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">training_job</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="n">training_job_id</span>
<span class="k">else</span><span class="p">:</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h1>Source code for csle_agents.agents.dynasec.dynasec_agent</h1><div class="hig
<span></span><span class="kn">import</span> <span class="nn">random</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Tuple</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">gym</span>
<span class="kn">import</span> <span class="nn">gymnasium</span> <span class="k">as</span> <span class="nn">gym</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
Expand Down Expand Up @@ -102,17 +102,18 @@ <h1>Source code for csle_agents.agents.dynasec.dynasec_agent</h1><div class="hig
<span class="kn">import</span> <span class="nn">EmulationAttackerStoppingActions</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.emulation_action.defender.emulation_defender_stopping_actions</span> \
<span class="kn">import</span> <span class="nn">EmulationDefenderStoppingActions</span>
<span class="kn">import</span> <span class="nn">csle_agents.constants.constants</span> <span class="k">as</span> <span class="nn">agents_constants</span>
<span class="kn">from</span> <span class="nn">csle_system_identification.expectation_maximization.expectation_maximization_algorithm</span> \
<span class="kn">import</span> <span class="nn">ExpectationMaximizationAlgorithm</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.system_identification.gaussian_mixture_system_model</span> <span class="kn">import</span> <span class="n">GaussianMixtureSystemModel</span>
<span class="kn">from</span> <span class="nn">csle_agents.agents.t_spsa.t_spsa_agent</span> <span class="kn">import</span> <span class="n">TSPSAAgent</span>
<span class="kn">import</span> <span class="nn">csle_system_identification.constants.constants</span> <span class="k">as</span> <span class="nn">system_identification_constants</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.system_identification.system_identification_config</span> <span class="kn">import</span> <span class="n">SystemIdentificationConfig</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.training.policy</span> <span class="kn">import</span> <span class="n">Policy</span>
<span class="kn">from</span> <span class="nn">csle_common.util.read_emulation_statistics_util</span> <span class="kn">import</span> <span class="n">ReadEmulationStatisticsUtil</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.emulation_config.static_emulation_attacker_type</span> <span class="kn">import</span> <span class="n">StaticEmulationAttackerType</span>
<span class="kn">from</span> <span class="nn">csle_common.dao.emulation_config.emulation_statistics_windowed</span> <span class="kn">import</span> <span class="n">EmulationStatisticsWindowed</span>
<span class="kn">from</span> <span class="nn">csle_common.util.general_util</span> <span class="kn">import</span> <span class="n">GeneralUtil</span>
<span class="kn">import</span> <span class="nn">csle_system_identification.constants.constants</span> <span class="k">as</span> <span class="nn">system_identification_constants</span>
<span class="kn">from</span> <span class="nn">csle_system_identification.expectation_maximization.expectation_maximization_algorithm</span> \
<span class="kn">import</span> <span class="nn">ExpectationMaximizationAlgorithm</span>
<span class="kn">from</span> <span class="nn">csle_agents.agents.t_spsa.t_spsa_agent</span> <span class="kn">import</span> <span class="n">TSPSAAgent</span>
<span class="kn">import</span> <span class="nn">csle_agents.constants.constants</span> <span class="k">as</span> <span class="nn">agents_constants</span>


<div class="viewcode-block" id="DataCollectorProcess"><a class="viewcode-back" href="../../../../csle_agents.agents.dynasec.html#csle_agents.agents.dynasec.dynasec_agent.DataCollectorProcess">[docs]</a><span class="k">class</span> <span class="nc">DataCollectorProcess</span><span class="p">(</span><span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">):</span>
Expand Down Expand Up @@ -161,7 +162,7 @@ <h1>Source code for csle_agents.agents.dynasec.dynasec_agent</h1><div class="hig
<span class="n">traces</span><span class="o">=</span><span class="p">[],</span>
<span class="n">num_sequences_completed</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">save_emulation_traces_every</span><span class="o">=</span><span class="mi">1000000</span><span class="p">,</span>
<span class="n">num_cached_traces</span><span class="o">=</span><span class="n">emulation_traces_to_save_with_data_collection_job</span><span class="p">,</span>
<span class="n">log_file_path</span><span class="o">=</span><span class="n">Logger</span><span class="o">.</span><span class="fm">__call__</span><span class="p">()</span><span class="o">.</span><span class="n">get_log_file_path</span><span class="p">())</span>
<span class="n">log_file_path</span><span class="o">=</span><span class="n">Logger</span><span class="o">.</span><span class="fm">__call__</span><span class="p">()</span><span class="o">.</span><span class="n">get_log_file_path</span><span class="p">(),</span> <span class="n">physical_host_ip</span><span class="o">=</span><span class="n">GeneralUtil</span><span class="o">.</span><span class="n">get_host_ip</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">job_id</span> <span class="o">=</span> <span class="n">MetastoreFacade</span><span class="o">.</span><span class="n">save_data_collection_job</span><span class="p">(</span>
<span class="n">data_collection_job</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_collection_job</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data_collection_job</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">job_id</span>
Expand Down Expand Up @@ -930,7 +931,8 @@ <h1>Source code for csle_agents.agents.dynasec.dynasec_agent</h1><div class="hig
<span class="n">progress_percentage</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">pid</span><span class="o">=</span><span class="n">pid</span><span class="p">,</span> <span class="n">experiment_result</span><span class="o">=</span><span class="n">exp_result</span><span class="p">,</span>
<span class="n">emulation_env_name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">emulation_env_config</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">simulation_traces</span><span class="o">=</span><span class="p">[],</span>
<span class="n">num_cached_traces</span><span class="o">=</span><span class="n">agents_constants</span><span class="o">.</span><span class="n">COMMON</span><span class="o">.</span><span class="n">NUM_CACHED_SIMULATION_TRACES</span><span class="p">,</span>
<span class="n">log_file_path</span><span class="o">=</span><span class="n">Logger</span><span class="o">.</span><span class="fm">__call__</span><span class="p">()</span><span class="o">.</span><span class="n">get_log_file_path</span><span class="p">(),</span> <span class="n">descr</span><span class="o">=</span><span class="n">descr</span><span class="p">)</span>
<span class="n">log_file_path</span><span class="o">=</span><span class="n">Logger</span><span class="o">.</span><span class="fm">__call__</span><span class="p">()</span><span class="o">.</span><span class="n">get_log_file_path</span><span class="p">(),</span> <span class="n">descr</span><span class="o">=</span><span class="n">descr</span><span class="p">,</span>
<span class="n">physical_host_ip</span><span class="o">=</span><span class="n">GeneralUtil</span><span class="o">.</span><span class="n">get_host_ip</span><span class="p">())</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">save_to_metastore</span><span class="p">:</span>
<span class="n">training_job_id</span> <span class="o">=</span> <span class="n">MetastoreFacade</span><span class="o">.</span><span class="n">save_training_job</span><span class="p">(</span><span class="n">training_job</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">training_job</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">training_job</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="n">training_job_id</span>
Expand Down
Loading

0 comments on commit 30ab139

Please sign in to comment.