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.
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.