pik-copan / pycopancore

reference implementation of the copan:CORE World-Earth modelling framework
http://www.pik-potsdam.de/copan
Other
45 stars 10 forks source link

improve RuntimeWarnings and RuntimeErrors in _expressions.py #135

Open mensch72 opened 3 years ago

mensch72 commented 3 years ago

make _expressions.py issue more helpful error messages when encountering RuntimeWarnings and RuntimeErrors by providing information about the affected expression

mensch72 commented 3 years ago

please test

leander-j commented 3 years ago

Tested with my parameter fitting copy: Somewhat lengthy error message and some (like divide by zero) appear double for the same location. But since it tells me even in the first line where my error is, it does its job!

my error message ```RuntimeWarning: divide by zero symbolic expression: SocialSystem.population File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/studies/leanders_model/fit_parameters_example2.py", line 9, in import pycopancore.models.example1 as M File "", line 1007, in _find_and_load File "", line 972, in _find_and_load_unlocked File "", line 228, in _call_with_frames_removed File "", line 1007, in _find_and_load File "", line 972, in _find_and_load_unlocked File "", line 228, in _call_with_frames_removed File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/__init__.py", line 14, in from .data_model import * File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/__init__.py", line 20, in from . import master_data_model File "", line 1058, in _handle_fromlist File "", line 228, in _call_with_frames_removed File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/master_data_model/__init__.py", line 31, in from .social_system import SocialSystem as S File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/master_data_model/social_system.py", line 8, in class SocialSystem: File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/master_data_model/social_system.py", line 12, in SocialSystem population = MET.population.copy() File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/variable.py", line 242, in copy return Variable(self.name, self.desc, **newkwargs) File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/variable.py", line 164, in __init__ super().__init__() File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/private/_expressions.py", line 725, in new_init st = traceback.extract_stack() RuntimeWarning: invalid value symbolic expression: SocialSystem.metabolism.wellbeing_sensitivity_to_consumption File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/__init__.py", line 23, in from .implementation import * File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/__init__.py", line 17, in from .social_system import SocialSystem File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/social_system.py", line 31, in class SocialSystem (I.SocialSystem): File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/social_system.py", line 72, in SocialSystem [B.SocialSystem.metabolism.wellbeing_sensitivity_to_consumption RuntimeWarning: divide by zero symbolic expression: -1/2 File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/__init__.py", line 23, in from .implementation import * File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/__init__.py", line 17, in from .social_system import SocialSystem File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/social_system.py", line 31, in class SocialSystem (I.SocialSystem): File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/social_system.py", line 60, in SocialSystem + B.SocialSystem.metabolism.population_spatial_competition_coefficient RuntimeWarning: invalid value symbolic expression: SocialSystem.metabolism.population_spatial_competition_coefficient File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/__init__.py", line 23, in from .implementation import * File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/__init__.py", line 17, in from .social_system import SocialSystem File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/social_system.py", line 31, in class SocialSystem (I.SocialSystem): File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/copan_global_like_population_growth/implementation/social_system.py", line 60, in SocialSystem + B.SocialSystem.metabolism.population_spatial_competition_coefficient RuntimeWarning: divide by zero symbolic expression: -1 File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/__init__.py", line 17, in from .implementation import * File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/__init__.py", line 19, in from .cell import Cell File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 19, in class Cell (I.Cell): File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 32, in Cell [ITE(B.Cell.world.culture.terrestrial_carbon_averaging_time > 0, RuntimeWarning: divide by zero symbolic expression: -1 File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/__init__.py", line 17, in from .implementation import * File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/__init__.py", line 19, in from .cell import Cell File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 19, in class Cell (I.Cell): File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 32, in Cell [ITE(B.Cell.world.culture.terrestrial_carbon_averaging_time > 0, RuntimeWarning: invalid value symbolic expression: SocialSystem.migrant_population File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/studies/leanders_model/fit_parameters_example2.py", line 9, in import pycopancore.models.example1 as M File "", line 1007, in _find_and_load File "", line 972, in _find_and_load_unlocked File "", line 228, in _call_with_frames_removed File "", line 1007, in _find_and_load File "", line 972, in _find_and_load_unlocked File "", line 228, in _call_with_frames_removed File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/__init__.py", line 14, in from .data_model import * File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/__init__.py", line 20, in from . import master_data_model File "", line 1058, in _handle_fromlist File "", line 228, in _call_with_frames_removed File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/master_data_model/__init__.py", line 31, in from .social_system import SocialSystem as S File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/master_data_model/social_system.py", line 8, in class SocialSystem: File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/master_data_model/social_system.py", line 14, in SocialSystem migrant_population = MET.migrant_population.copy() File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/variable.py", line 242, in copy return Variable(self.name, self.desc, **newkwargs) File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/data_model/variable.py", line 164, in __init__ super().__init__() File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/private/_expressions.py", line 725, in new_init st = traceback.extract_stack() RuntimeWarning: divide by zero symbolic expression: Cell.world.culture.terrestrial_carbon_averaging_time**(-1) File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/__init__.py", line 17, in from .implementation import * File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/__init__.py", line 19, in from .cell import Cell File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 19, in class Cell (I.Cell): File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 26, in Cell (I.Cell.terrestrial_carbon - I.Cell.mean_past_terrestrial_carbon) RuntimeWarning: invalid value symbolic expression: Cell.world.culture.terrestrial_carbon_averaging_time**(-1) File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/__init__.py", line 17, in from .implementation import * File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/__init__.py", line 19, in from .cell import Cell File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 19, in class Cell (I.Cell): File "/home/leander/Dokumente/Studium/13/Masterthesis/pycopancore/pycopancore/model_components/environmental_awareness/implementation/cell.py", line 26, in Cell (I.Cell.terrestrial_carbon - I.Cell.mean_past_terrestrial_carbon) capi_return is NULL Call-back cb_fcn_in___user__routines failed. ```