Skip to content

FloatingPointError in goods_market/func/clearing.py when additional_real_demand_by_country.sum() == 0 #92

Description

@BarojaJordi

Using the same configuration as issue #88, but increasing the number of iterations to 25, the simulation raises the following error

File macro-main\macromodel\markets\goods_market\func\clearing.py:898:
--> 898 self.additionally_available_factor
899 * aggr_real_supply.sum()
900 * additional_real_demand_by_country[country_name].sum()
901 / additional_real_demand.sum()
902 # * safe_ratio(
903 # additional_real_demand_by_country[country_name][g],
904 # additional_real_demand_by_country[country_name].sum(),
905 # )
906 * additional_real_demand_by_country[country_name][g]
907 / additional_real_demand_by_country[country_name].sum()
908 )

FloatingPointError: invalid value encountered in scalar divide

The issue appears to occur because additional_real_demand_by_country[country_name].sum() can be 0.

There is already commented-out code nearby suggesting a safer implementation:

def safe_ratio(num, den):
return 1.0 if den == 0 else num / den

that returns 1 if this happens. It might be more suitable to return 0 instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions