Represents a simulation, and handles the calculation logic.
Return the value of variable_name
for period
, if this value is alreay in the cache (if it has been set as an input or previously calculated).
Unlike calculate()
, this method does not trigger calculations and does not use any formula.
Build a default simulation.
There are count
persons
There are count
of each group entity, containing one person
Every person has, in each entity, the first role
Build a simulation from an input dictionary.
This method uses SimulationBuilder.build_from_entities()
if
entities are fully specified, or
SimulationBuilder.build_from_variables()
if they are not.
tax_benefit_system (TaxBenefitSystem
) – The system to use.
input_dict (Union
[dict
[str
, Iterable
[Iterable
[Axis
]]], dict
[str
, Union
[dict
[str
, object
], dict
[str
, dict
[str
, object
]]]], dict
[str
, Union
[dict
[str
, Union
[str
, Iterable
[str
]]], dict
[str
, Union
[dict
[str
, object
], dict
[str
, dict
[str
, object
]]]]]], dict
[str
, dict
[str
, dict
[str
, Union
[dict
[str
, object
], dict
[str
, dict
[str
, object
]]]]]], dict
[str
, dict
[str
, Union
[dict
[str
, Union
[str
, Iterable
[str
]]], dict
[str
, Union
[dict
[str
, object
], dict
[str
, dict
[str
, object
]]]]]]]]) – The input of the simulation.
Simulation – The built simulation.
Examples
>>> entities = {"person", "household"}
>>> params = {
... "persons": {"Javier": {"salary": {"2018-11": 2000}}},
... "household": {"parents": ["Javier"]},
... "axes": [[{"count": 1, "max": 1, "min": 1, "name": "household"}]],
... }
>>> are_entities_short_form(params, entities)
True
>>> entities = {"persons", "households"}
>>> params = {
... "axes": [
... [
... {
... "count": 2,
... "max": 3000,
... "min": 0,
... "name": "rent",
... "period": "2018-11",
... }
... ]
... ],
... "households": {
... "housea": {"parents": ["Alicia", "Javier"]},
... "houseb": {"parents": ["Tom"]},
... },
... "persons": {
... "Alicia": {"salary": {"2018-11": 0}},
... "Javier": {},
... "Tom": {},
... },
... }
>>> are_entities_short_form(params, entities)
True
>>> params = {"salary": [12000, 13000]}
>>> not are_entities_specified(params, {"salary"})
True
Build a simulation from a Python dict input_dict
fully specifying
entities.
Examples
>>> entities = {"person", "household"}
>>> params = {
... "persons": {"Javier": {"salary": {"2018-11": 2000}}},
... "household": {"parents": ["Javier"]},
... "axes": [[{"count": 1, "max": 1, "min": 1, "name": "household"}]],
... }
>>> are_entities_short_form(params, entities)
True
Build a simulation from a Python dict input_dict
describing
variables values without expliciting entities.
This method uses SimulationBuilder.build_default_simulation()
to
infer an entity structure.
Simulation – The built simulation.
SituationParsingError – If the input is not valid.
Examples
>>> params = {"salary": {"2016-10": 12000}}
>>> are_entities_specified(params, {"salary"})
False
>>> params = {"salary": 12000}
>>> are_entities_specified(params, {"salary"})
False
Preprocess input_dict
to explicit entities defined using the
single-entity shortcut.
dict
[str
, dict
[str
, Union
[dict
[str
, Union
[str
, Iterable
[str
]]], dict
[str
, Union
[dict
[str
, object
], dict
[str
, dict
[str
, object
]]]]]]]
Examples
>>> params = {
... "persons": {
... "Javier": {},
... },
... "household": {"parents": ["Javier"]},
... }
>>> are_entities_fully_specified(params, {"persons", "households"})
False
>>> are_entities_short_form(params, {"person", "household"})
True
>>> params = {
... "persons": {"Javier": {}},
... "households": {"household": {"parents": ["Javier"]}},
... }
>>> are_entities_fully_specified(params, {"persons", "households"})
True
>>> are_entities_short_form(params, {"person", "household"})
False
Check if the input contains entities that are not in the system.
params (ParamsWithoutAxes) – Simulation parameters.
entities (Iterable[str]) – List of entities in plural form.
SituationParsingError – If there are entities that are not in the system.
Examples
>>> entities = {"persons", "households"}
>>> params = {
... "persons": {"Javier": {"salary": {"2018-11": 2000}}},
... "households": {"household": {"parents": ["Javier"]}},
... }
>>> check_unexpected_entities(params, entities)
>>> params = {"dogs": {"Bart": {"damages": {"2018-11": 2000}}}}
>>> check_unexpected_entities(params, entities)
Traceback (most recent call last):
openfisca_core.errors.situation_parsing_error.SituationParsingError
Check if the input contains entities that are not in the system.
params (ParamsWithoutAxes) – Simulation parameters.
entities (Iterable[str]) – List of entities in plural form.
bool – True if the input contains entities that are not in the system.
Examples
>>> entities = {"persons", "households"}
>>> params = {
... "persons": {"Javier": {"salary": {"2018-11": 2000}}},
... "households": {"household": {"parents": ["Javier"]}},
... }
>>> has_unexpected_entities(params, entities)
False
>>> params = {"dogs": {"Bart": {"damages": {"2018-11": 2000}}}}
>>> has_unexpected_entities(params, entities)
True