Skip to content

Commit

Permalink
Deploying to gh-pages from @ 1282a0a 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
jjshoots committed Jun 21, 2024
1 parent 35a29db commit 71ad389
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 86 deletions.
2 changes: 1 addition & 1 deletion main/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 160904be004f71623ee83fdc7417f0e7
config: d0b48001e789e75e8e443957b6140b4c
tags: d77d1c0d9ca2f4c8421862c7c5a0d620
20 changes: 0 additions & 20 deletions main/_modules/pettingzoo/utils/env_logger/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,26 +473,6 @@ <h1>Source code for pettingzoo.utils.env_logger</h1><div class="highlight"><pre>
<span class="p">)</span></div>


<div class="viewcode-block" id="EnvLogger.warn_close_unrendered_env">
<a class="viewcode-back" href="../../../../api/utils/#pettingzoo.utils.env_logger.EnvLogger.warn_close_unrendered_env">[docs]</a>
<span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">warn_close_unrendered_env</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;Warns: ``[WARNING]: Called close on an unrendered environment.``.&quot;&quot;&quot;</span>
<span class="n">EnvLogger</span><span class="o">.</span><span class="n">_generic_warning</span><span class="p">(</span>
<span class="s2">&quot;[WARNING]: Called close on an unrendered environment.&quot;</span>
<span class="p">)</span></div>


<div class="viewcode-block" id="EnvLogger.warn_close_before_reset">
<a class="viewcode-back" href="../../../../api/utils/#pettingzoo.utils.env_logger.EnvLogger.warn_close_before_reset">[docs]</a>
<span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">warn_close_before_reset</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;Warns: ``[WARNING]: reset() needs to be called before close.``.&quot;&quot;&quot;</span>
<span class="n">EnvLogger</span><span class="o">.</span><span class="n">_generic_warning</span><span class="p">(</span>
<span class="s2">&quot;[WARNING]: reset() needs to be called before close.&quot;</span>
<span class="p">)</span></div>


<div class="viewcode-block" id="EnvLogger.warn_on_illegal_move">
<a class="viewcode-back" href="../../../../api/utils/#pettingzoo.utils.env_logger.EnvLogger.warn_on_illegal_move">[docs]</a>
<span class="nd">@staticmethod</span>
Expand Down
60 changes: 19 additions & 41 deletions main/_modules/pettingzoo/utils/wrappers/order_enforcing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,49 +413,26 @@ <h1>Source code for pettingzoo.utils.wrappers.order_enforcing</h1><div class="hi
<span class="k">class</span> <span class="nc">OrderEnforcingWrapper</span><span class="p">(</span><span class="n">BaseWrapper</span><span class="p">[</span><span class="n">AgentID</span><span class="p">,</span> <span class="n">ObsType</span><span class="p">,</span> <span class="n">ActionType</span><span class="p">]):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Checks if function calls or attribute access are in a disallowed order.</span>

<span class="sd"> * error on getting rewards, terminations, truncations, infos, agent_selection before reset</span>
<span class="sd"> * error on calling step, observe before reset</span>
<span class="sd"> * error on iterating without stepping or resetting environment.</span>
<span class="sd"> * warn on calling close before render or reset</span>
<span class="sd"> * warn on calling step after environment is terminated or truncated</span>
<span class="sd"> The following are raised:</span>
<span class="sd"> * AttributeError if any of the following are accessed before reset():</span>
<span class="sd"> rewards, terminations, truncations, infos, agent_selection,</span>
<span class="sd"> num_agents, agents.</span>
<span class="sd"> * An error if any of the following are called before reset:</span>
<span class="sd"> render(), step(), observe(), state(), agent_iter()</span>
<span class="sd"> * A warning if step() is called when there are no agents remaining.</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">env</span><span class="p">:</span> <span class="n">AECEnv</span><span class="p">[</span><span class="n">AgentID</span><span class="p">,</span> <span class="n">ObsType</span><span class="p">,</span> <span class="n">ActionType</span><span class="p">]):</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span>
<span class="n">env</span><span class="p">,</span> <span class="n">AECEnv</span>
<span class="p">),</span> <span class="s2">&quot;OrderEnforcingWrapper is only compatible with AEC environments&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_has_reset</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_has_rendered</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_has_updated</span> <span class="o">=</span> <span class="kc">False</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">env</span><span class="p">)</span>

<span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Any</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Raises an error message when data is gotten from the env.</span>

<span class="sd"> Should only be gotten after reset</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">value</span> <span class="o">==</span> <span class="s2">&quot;unwrapped&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">unwrapped</span>
<span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="s2">&quot;render_mode&quot;</span> <span class="ow">and</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">,</span> <span class="s2">&quot;render_mode&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">render_mode</span> <span class="c1"># pyright: ignore[reportGeneralTypeIssues]</span>
<span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="s2">&quot;possible_agents&quot;</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">possible_agents</span>
<span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
<span class="n">EnvLogger</span><span class="o">.</span><span class="n">error_possible_agents_attribute_missing</span><span class="p">(</span><span class="s2">&quot;possible_agents&quot;</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="s2">&quot;observation_spaces&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span>
<span class="s2">&quot;The base environment does not have an possible_agents attribute. Use the environments `observation_space` method instead&quot;</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="s2">&quot;action_spaces&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span>
<span class="s2">&quot;The base environment does not have an possible_agents attribute. Use the environments `action_space` method instead&quot;</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="n">value</span> <span class="o">==</span> <span class="s2">&quot;agent_order&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span>
<span class="s2">&quot;agent_order has been removed from the API. Please consider using agent_iter instead.&quot;</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="p">(</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Raises an error if certain data is accessed before reset.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="p">(</span>
<span class="n">value</span>
<span class="ow">in</span> <span class="p">{</span>
<span class="s2">&quot;rewards&quot;</span><span class="p">,</span>
Expand All @@ -469,13 +446,11 @@ <h1>Source code for pettingzoo.utils.wrappers.order_enforcing</h1><div class="hi
<span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_has_reset</span>
<span class="p">):</span>
<span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s2"> cannot be accessed before reset&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__getattr__</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__getattr__</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span> <span class="o">|</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span> <span class="o">|</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">list</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_has_reset</span><span class="p">:</span>
<span class="n">EnvLogger</span><span class="o">.</span><span class="n">error_render_before_reset</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_has_rendered</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">render</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">action</span><span class="p">:</span> <span class="n">ActionType</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
Expand All @@ -484,7 +459,6 @@ <h1>Source code for pettingzoo.utils.wrappers.order_enforcing</h1><div class="hi
<span class="k">elif</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">agents</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_has_updated</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">EnvLogger</span><span class="o">.</span><span class="n">warn_step_after_terminated_truncated</span><span class="p">()</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_has_updated</span> <span class="o">=</span> <span class="kc">True</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">step</span><span class="p">(</span><span class="n">action</span><span class="p">)</span>
Expand Down Expand Up @@ -518,8 +492,7 @@ <h1>Source code for pettingzoo.utils.wrappers.order_enforcing</h1><div class="hi
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span> <span class="ow">is</span> <span class="n">OrderEnforcingWrapper</span>
<span class="k">else</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span><span class="si">}</span><span class="s2">&lt;</span><span class="si">{</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">)</span><span class="si">}</span><span class="s2">&gt;&quot;</span>
<span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>
<span class="k">return</span> <span class="nb">repr</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>



Expand All @@ -529,11 +502,16 @@ <h1>Source code for pettingzoo.utils.wrappers.order_enforcing</h1><div class="hi


<span class="k">class</span> <span class="nc">AECOrderEnforcingIterator</span><span class="p">(</span><span class="n">AECIterator</span><span class="p">[</span><span class="n">AgentID</span><span class="p">,</span> <span class="n">ObsType</span><span class="p">,</span> <span class="n">ActionType</span><span class="p">]):</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">env</span><span class="p">:</span> <span class="n">OrderEnforcingWrapper</span><span class="p">[</span><span class="n">AgentID</span><span class="p">,</span> <span class="n">ObsType</span><span class="p">,</span> <span class="n">ActionType</span><span class="p">],</span> <span class="n">max_iter</span><span class="p">:</span> <span class="nb">int</span>
<span class="p">):</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span>
<span class="n">env</span><span class="p">,</span> <span class="n">OrderEnforcingWrapper</span>
<span class="p">),</span> <span class="s2">&quot;env must be wrapped by OrderEnforcingWrapper&quot;</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">max_iter</span><span class="p">)</span>

<span class="k">def</span> <span class="fm">__next__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">AgentID</span><span class="p">:</span>
<span class="n">agent</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__next__</span><span class="p">()</span>
<span class="k">assert</span> <span class="nb">hasattr</span><span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">,</span> <span class="s2">&quot;_has_updated&quot;</span>
<span class="p">),</span> <span class="s2">&quot;env must be wrapped by OrderEnforcingWrapper&quot;</span>
<span class="k">assert</span> <span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">_has_updated</span> <span class="c1"># pyright: ignore[reportGeneralTypeIssues]</span>
<span class="p">),</span> <span class="s2">&quot;need to call step() or reset() in a loop over `agent_iter`&quot;</span>
Expand Down
Loading

0 comments on commit 71ad389

Please sign in to comment.