From 0bfec97867633cc512ff283ddaa3109ffcc9048d Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff <35577657+nikhilwoodruff@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:29:20 +0000 Subject: [PATCH] Fix bug in required-variables (#306) * Fix Enum bug * Required-variable doesn't recognise input variables Fixes #305 * Versioning --- changelog_entry.yaml | 4 ++++ policyengine_core/simulations/simulation.py | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29b..a9e3f5ba 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: patch + changes: + fixed: + - Bug in labour supply responses. diff --git a/policyengine_core/simulations/simulation.py b/policyengine_core/simulations/simulation.py index 1a4c5d09..a6b5579b 100644 --- a/policyengine_core/simulations/simulation.py +++ b/policyengine_core/simulations/simulation.py @@ -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: