Skip to content

Commit

Permalink
Fix bug in required-variables (#306)
Browse files Browse the repository at this point in the history
* Fix Enum bug

* Required-variable doesn't recognise input variables
Fixes #305

* Versioning
  • Loading branch information
nikhilwoodruff authored Nov 4, 2024
1 parent 4316fa3 commit 0bfec97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
fixed:
- Bug in labour supply responses.
19 changes: 12 additions & 7 deletions policyengine_core/simulations/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,20 @@ def _calculate(
return value

if variable.requires_computation_after is not None:
if variable.requires_computation_after not in [
variables_in_stack = [
node.get("name") for node in self.tracer.stack
]:
]
variable_in_stack = (
variable.requires_computation_after in variables_in_stack
)
required_is_known_periods = self.get_holder(
variable.requires_computation_after
).get_known_periods()
if (not variable_in_stack) and (
not len(required_is_known_periods) > 0
):
raise ValueError(
f"Variable {variable_name} requires {variable.requires_computation_after} to be requested first. The full stack is: "
+ "\n".join(
f" - {node.get('name')} {node.get('period')}, {node.get('branch_name')}"
for node in self.tracer.stack
)
f"Variable {variable_name} requires {variable.requires_computation_after} to be requested first. That variable is known in: {required_is_known_periods}. The full stack is: {variables_in_stack}. {variable_in_stack, len(required_is_known_periods) > 0}"
)
alternate_period_handling = False
if variable.definition_period == MONTH and period.unit == YEAR:
Expand Down

0 comments on commit 0bfec97

Please sign in to comment.