euromod.introspect ================== .. py:module:: euromod.introspect Below are listed the main public classes of the euromod.introspect module. .. list-table:: **Function** :header-rows: 0 :widths: auto :class: summarytable * - :py:obj:`clear_cache `\ () - Drop the cached spine extractions. * - :py:obj:`income_list_components `\ (system, list_name, dataset, extensions) - Effective components of an income list under a dataset and extension set. * - :py:obj:`iter_real_policies `\ (scope) - Yield the policies of a country or system, skipping reference policies. * - :py:obj:`system_constant_names `\ (system) - ``$``-prefixed constants defined via ``DefConst`` in a system. * - :py:obj:`system_constant_params `\ (system) - All ``$``-prefixed parameters overridable via ``run(constantsToOverwrite=...)``, * - :py:obj:`system_extension_names `\ (system) - Extension short names the model accepts in ``run(switches=...)``. Functions --------- .. py:function:: clear_cache() -> None Drop the cached spine extractions. Only needed when a model is reloaded from changed files within one process; the model is otherwise read-only at run time. .. py:function:: income_list_components(system, list_name, dataset=None, extensions=None) -> list Effective components of an income list under a dataset and extension set. Income list membership is not fixed: extensions add and remove components, and a list may be redefined further down the spine. Expanding a list by reading one ``DefIl`` definition therefore gives the wrong variables as soon as an extension is switched. :param system: System whose spine defines the list. :type system: :class:`euromod.System` :param list_name: Income list name, e.g. ``"ils_dispy"``. :type list_name: :obj:`str` :param dataset: Dataset whose switch defaults apply. Default is the system's best match. :type dataset: :obj:`str`, optional :param extensions: Switch overrides on top of the dataset defaults, in the form taken by :meth:`euromod.System.run`. Default is :obj:`None`. :type extensions: :obj:`list` [ :obj:`tuple` [ :obj:`str`, :obj:`bool` ] ], optional :returns: ``(variable, sign)`` pairs, where sign is ``'+'`` or ``'-'``. Nested income lists are expanded recursively with signs multiplied through. :rtype: :obj:`list` [ :obj:`tuple` [ :obj:`str`, :obj:`str` ] ] :raises IncomeListLookupError: If the list is unknown, inactive under this configuration, or cyclic. .. rubric:: Example >>> from euromod.introspect import income_list_components >>> income_list_components(sys, "ils_dispy") # doctest: +SKIP [('yem', '+'), ('yse', '+'), ('tin', '-'), ...] .. py:function:: iter_real_policies(scope) Yield the policies of a country or system, skipping reference policies. :param scope: Element whose ``policies`` container is walked. :type scope: :class:`euromod.Country` or :class:`euromod.System` :Yields: :class:`euromod.Policy` -- Policies excluding :class:`euromod.ReferencePolicy` objects, which carry no functions or comment and raise on naive attribute access. .. py:function:: system_constant_names(system) -> set ``$``-prefixed constants defined via ``DefConst`` in a system. :param system: System to inspect. :type system: :class:`euromod.System` :returns: Constant names, extension-independent (every occurrence, whether or not it is active under a particular configuration). :rtype: :obj:`set` [ :obj:`str` ] .. py:function:: system_constant_params(system) -> dict All ``$``-prefixed parameters overridable via ``run(constantsToOverwrite=...)``, mapped to the groups they are defined with. ``constantsToOverwrite`` is keyed by ``(name, group)``, and uprating factors such as ``$f_cpi`` are parameters of the ``Uprate`` function keyed by year-group rather than ``DefConst`` entries — so validating an override against :func:`system_constant_names` alone would reject them. This walks every function. :param system: System to inspect. :type system: :class:`euromod.System` :returns: Parameter name -> the groups it is defined with (``''`` when ungrouped). :rtype: :obj:`dict` [ :obj:`str`, :obj:`set` [ :obj:`str` ] ] .. rubric:: Example >>> from euromod.introspect import system_constant_params >>> params = system_constant_params(sys) # doctest: +SKIP >>> sorted(params["$f_cpi"])[:3] # doctest: +SKIP ['2021', '2022', '2023'] .. py:function:: system_extension_names(system) -> set Extension short names the model accepts in ``run(switches=...)``. A switch the model does not know is silently dropped by the engine, which only reports "An error occurred during the processing of the ExtensionSwitches" to the console: the simulation then completes normally while the behaviour the caller asked for never happened. Validate against this set before running. :param system: System whose country and dataset defaults are inspected. :type system: :class:`euromod.System` :returns: Short names from the country's extensions (local plus model-wide, i.e. everything declared in ``Config/SWITCHABLEPOLICYCONFIG.xml``, including add-on extensions) unioned with the per-dataset switch defaults observed for this system. Empty when neither can be read, which callers should treat as "cannot validate" rather than "nothing is valid". :rtype: :obj:`set` [ :obj:`str` ] .. rubric:: Example >>> from euromod import Model >>> from euromod.introspect import system_extension_names >>> mod = Model("C:\EUROMOD_RELEASES_I6.0+") >>> "LMA_trans" in system_extension_names(mod.countries['BE'].systems['BE_2025']) True