Skip to content

Commit

Permalink
Deploying to gh-pages from @ 47f5bdf 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Aug 8, 2024
1 parent 9fc9e9b commit 6137816
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
5 changes: 5 additions & 0 deletions _downloads/621e2c7711e8623173875c33222eddb6/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,8 @@
removed:
- Removed nptyping, migrated to numpy.typing
date: 2024-08-08 15:16:12
- bump: patch
changes:
fixed:
- fixed bug where uprating was causing nan.
date: 2024-08-08 15:17:05
65 changes: 31 additions & 34 deletions _modules/policyengine_core/simulations/simulation.html
Original file line number Diff line number Diff line change
Expand Up @@ -907,43 +907,40 @@ <h1>Source code for policyengine_core.simulations.simulation</h1><div class="hig
<span class="k">if</span> <span class="n">array</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># Check if the variable has a previously defined value</span>
<span class="n">known_periods</span> <span class="o">=</span> <span class="n">holder</span><span class="o">.</span><span class="n">get_known_periods</span><span class="p">()</span>
<span class="k">if</span> <span class="n">variable</span><span class="o">.</span><span class="n">uprating</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">known_periods</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">start_instants</span> <span class="o">=</span> <span class="p">[</span>
<span class="nb">str</span><span class="p">(</span><span class="n">known_period</span><span class="o">.</span><span class="n">start</span><span class="p">)</span>
<span class="k">for</span> <span class="n">known_period</span> <span class="ow">in</span> <span class="n">known_periods</span>
<span class="k">if</span> <span class="n">known_period</span><span class="o">.</span><span class="n">unit</span> <span class="o">==</span> <span class="n">variable</span><span class="o">.</span><span class="n">definition_period</span>
<span class="ow">and</span> <span class="n">known_period</span><span class="o">.</span><span class="n">start</span> <span class="o">&lt;</span> <span class="n">period</span><span class="o">.</span><span class="n">start</span>
<span class="n">start_instants</span> <span class="o">=</span> <span class="p">[</span>
<span class="nb">str</span><span class="p">(</span><span class="n">known_period</span><span class="o">.</span><span class="n">start</span><span class="p">)</span>
<span class="k">for</span> <span class="n">known_period</span> <span class="ow">in</span> <span class="n">known_periods</span>
<span class="k">if</span> <span class="n">known_period</span><span class="o">.</span><span class="n">unit</span> <span class="o">==</span> <span class="n">variable</span><span class="o">.</span><span class="n">definition_period</span>
<span class="ow">and</span> <span class="n">known_period</span><span class="o">.</span><span class="n">start</span> <span class="o">&lt;</span> <span class="n">period</span><span class="o">.</span><span class="n">start</span>
<span class="p">]</span>
<span class="k">if</span> <span class="n">variable</span><span class="o">.</span><span class="n">uprating</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">start_instants</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">latest_known_period</span> <span class="o">=</span> <span class="n">known_periods</span><span class="p">[</span>
<span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">start_instants</span><span class="p">)</span>
<span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">start_instants</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">latest_known_period</span> <span class="o">=</span> <span class="n">known_periods</span><span class="p">[</span>
<span class="n">np</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">start_instants</span><span class="p">)</span>
<span class="p">]</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">uprating_parameter</span> <span class="o">=</span> <span class="n">get_parameter</span><span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">tax_benefit_system</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span>
<span class="n">variable</span><span class="o">.</span><span class="n">uprating</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Could not find uprating parameter </span><span class="si">{</span><span class="n">variable</span><span class="o">.</span><span class="n">uprating</span><span class="si">}</span><span class="s2"> when trying to uprate </span><span class="si">{</span><span class="n">variable_name</span><span class="si">}</span><span class="s2">.&quot;</span>
<span class="p">)</span>
<span class="n">value_in_last_period</span> <span class="o">=</span> <span class="n">uprating_parameter</span><span class="p">(</span>
<span class="n">latest_known_period</span><span class="o">.</span><span class="n">start</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">uprating_parameter</span> <span class="o">=</span> <span class="n">get_parameter</span><span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">tax_benefit_system</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span>
<span class="n">variable</span><span class="o">.</span><span class="n">uprating</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">value_in_this_period</span> <span class="o">=</span> <span class="n">uprating_parameter</span><span class="p">(</span><span class="n">period</span><span class="o">.</span><span class="n">start</span><span class="p">)</span>
<span class="k">if</span> <span class="n">value_in_last_period</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">uprating_factor</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">uprating_factor</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">value_in_this_period</span> <span class="o">/</span> <span class="n">value_in_last_period</span>
<span class="p">)</span>

<span class="n">array</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">holder</span><span class="o">.</span><span class="n">get_array</span><span class="p">(</span>
<span class="n">latest_known_period</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">branch_name</span>
<span class="p">)</span>
<span class="o">*</span> <span class="n">uprating_factor</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Could not find uprating parameter </span><span class="si">{</span><span class="n">variable</span><span class="o">.</span><span class="n">uprating</span><span class="si">}</span><span class="s2"> when trying to uprate </span><span class="si">{</span><span class="n">variable_name</span><span class="si">}</span><span class="s2">.&quot;</span>
<span class="p">)</span>
<span class="n">value_in_last_period</span> <span class="o">=</span> <span class="n">uprating_parameter</span><span class="p">(</span>
<span class="n">latest_known_period</span><span class="o">.</span><span class="n">start</span>
<span class="p">)</span>
<span class="n">value_in_this_period</span> <span class="o">=</span> <span class="n">uprating_parameter</span><span class="p">(</span><span class="n">period</span><span class="o">.</span><span class="n">start</span><span class="p">)</span>
<span class="k">if</span> <span class="n">value_in_last_period</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">uprating_factor</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">uprating_factor</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">value_in_this_period</span> <span class="o">/</span> <span class="n">value_in_last_period</span>
<span class="p">)</span>

<span class="n">array</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">holder</span><span class="o">.</span><span class="n">get_array</span><span class="p">(</span><span class="n">latest_known_period</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">branch_name</span><span class="p">)</span>
<span class="o">*</span> <span class="n">uprating_factor</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">tax_benefit_system</span><span class="o">.</span><span class="n">auto_carry_over_input_variables</span>
<span class="ow">and</span> <span class="n">variable</span><span class="o">.</span><span class="n">calculate_output</span> <span class="ow">is</span> <span class="kc">None</span>
Expand Down

0 comments on commit 6137816

Please sign in to comment.