Simulations

class openfisca_core.simulations.Simulation(tax_benefit_system, populations)[source]

Represents a simulation, and handles the calculation logic

calculate(variable_name, period)[source]

Calculate variable_name for period.

get_array(variable_name, period)[source]

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.

get_holder(variable_name)[source]

Get the Holder associated with the variable variable_name for the simulation

get_memory_usage(variables=None)[source]

Get data about the virtual memory usage of the simulation

class openfisca_core.simulations.SimulationBuilder[source]
build_default_simulation(tax_benefit_system, count=1)[source]
Build a simulation where:
  • There are count persons

  • There are count instances of each group entity, containing one person

  • Every person has, in each entity, the first role

build_from_dict(tax_benefit_system, input_dict)[source]

Build a simulation from input_dict

This method uses build_from_entities if entities are fully specified, or build_from_variables if not.

Parameters

input_dict (dict) – A dict represeting the input of the simulation

Returns

A Simulation

build_from_entities(tax_benefit_system, input_dict)[source]

Build a simulation from a Python dict input_dict fully specifying entities.

Examples:

>>> simulation_builder.build_from_entities({
    'persons': {'Javier': { 'salary': {'2018-11': 2000}}},
    'households': {'household': {'parents': ['Javier']}}
    })
build_from_variables(tax_benefit_system, input_dict)[source]

Build a simulation from a Python dict input_dict describing variables values without expliciting entities.

This method uses build_default_simulation to infer an entity structure

Example:

>>> simulation_builder.build_from_variables(
    {'salary': {'2016-10': 12000}}
    )
explicit_singular_entities(tax_benefit_system, input_dict)[source]

Preprocess input_dict to explicit entities defined using the single-entity shortcut

Example:

>>> simulation_builder.explicit_singular_entities(
    {'persons': {'Javier': {}, }, 'household': {'parents': ['Javier']}}
    )
>>> {'persons': {'Javier': {}}, 'households': {'household': {'parents': ['Javier']}}