Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further adopt simplified simulation initialisation #732

Merged
merged 2 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 24.5.1 [#732](https://github.com/openfisca/openfisca-core/pull/732)

- Further adopt simplified simulation initialisation
- See [#729](https://github.com/openfisca/openfisca-core/pull/729)

## 24.5.0 [#729](https://github.com/openfisca/openfisca-core/pull/729)

- In Python, simplify simulation initialisation:
Expand Down
13 changes: 5 additions & 8 deletions openfisca_core/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ def fill_simulation(self, simulation):
if self.input_variables is not None:
# Note: For set_input to work, handle days, before months, before years => use sorted().
for variable_name, array_by_period in sorted(self.input_variables.items()):
holder = simulation.get_variable_entity(variable_name).get_holder(variable_name)
entity = holder.entity
entity = simulation.get_variable_entity(variable_name)
for period, array in array_by_period.items():
if entity.count == 0:
entity.count = len(array)
entity.ids = range(entity.count)
holder.set_input(period, array)
simulation.set_input(variable_name, period, array)

if persons.count == 0:
persons.count = 1
Expand Down Expand Up @@ -99,8 +98,7 @@ def set_input(variable_name, period, value):
if self.axes is not None:
cache_buffer[variable_name][period] = value
else:
holder = simulation.get_variable_entity(variable_name).get_holder(variable_name)
holder.set_input(period, value)
simulation.set_input(variable_name, period, value)

for entity in simulation.entities.values():
step_size = len(test_case[entity.plural])
Expand Down Expand Up @@ -236,10 +234,9 @@ def set_input(variable_name, period, value):
cache_buffer[axis_name][axis_period] = array

# We pour the buffer in the real cache
for variable, values in cache_buffer.items():
holder = simulation.get_variable_entity(variable).get_holder(variable)
for variable_name, values in cache_buffer.items():
for period, array in values.items():
holder.set_input(period, array)
simulation.set_input(variable_name, period, array)

def init_from_attributes(self, repair = False, **attributes):
conv.check(self.make_json_or_python_to_attributes(repair = repair))(attributes)
Expand Down
2 changes: 1 addition & 1 deletion openfisca_core/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def set_input(self, variable, period, value):
>>> get_array('age', '2018-04')
>>> [12, 14]

If a ``set_input`` property has been set for the variable, this method may accept inputs for periods not matching the ``definition_period`` of the variable. To read more about this, check the `documentation <https://openfisca.org/doc/coding-the-legislation/35_periods.html#automatically-process-variable-inputs-defined-for-periods-not-matching-the-definitionperiod>`.
If a ``set_input`` property has been set for the variable, this method may accept inputs for periods not matching the ``definition_period`` of the variable. To read more about this, check the `documentation <https://openfisca.org/doc/coding-the-legislation/35_periods.html#automatically-process-variable-inputs-defined-for-periods-not-matching-the-definitionperiod>`_.
"""
self.get_holder(variable).set_input(period, value)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

setup(
name = 'OpenFisca-Core',
version = '24.5.0',
version = '24.5.1',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down