openfisca / openfisca-core

OpenFisca core engine. See other repositories for countries-specific code & data.
https://openfisca.org
GNU Affero General Public License v3.0
169 stars 75 forks source link

Make explicit input variables temporal inferences #460

Closed MattiSG closed 5 years ago

MattiSG commented 7 years ago

This issue handles a part of #458.

For base_function, the issue rose with the formula rsa, where macrosimulation (where missing values should be the default ones (or raise warnings, @benjello?) and production (where missing values should be inferred) expected behaviours differ.

Default values in input variables are the source of the issue: if a formula needs values that are undefined (e.g. because they are in previous months from the calculation), it won't crash nor log anything because the input variables return their default values. This inference behaviour seems to be fine for macrosimulation, but production would expect a time-based inference, where the value is copied from its closest defined value rather than a global default one. Changing the inference mode means changing the base_function, but that raises conflicts between uses.

There is a consensus between @cbenz @michelbl @fpagnoux that base_function is incomprehensible and counterintuitive. It is at least misnamed and it should be more explicit that it is currently used purely as an extrapolation mechanism.

There is also a consensus that defaulting to the simulation period when requesting to compute a formula is not a proper behaviour: this piece of information should be mandatory to avoid incomprehensible behaviour on omission.

Discussed possible solutions

Candidates

Eliminated

Suggested action plan

benjello commented 7 years ago

Some comments:

I hope this helps and keep on the good work !

MattiSG commented 7 years ago

Choosing the input setter should be possible.

This could be interesting, but is out of the scope of this specific issue on base_function and default simulation period. This is set_input, which will be treated in another issue, and enriches #458.

A backstop date or period of time might also be implemented.

This could be interesting, but is out of the scope of this specific issue on base_function and default simulation period. This is an alternative to max_nb_cycles, which is not an inference and thus won't be treated in #458.

I greatly suggest that the time-based inference should be provided as an option per variable.

Do you have an example of a computing that would be impossible to do without such an inference? If not, a case where it would be very cumbersome? The conclusion of previous discussions seemed to be more that the engine itself should be dumb and leave it to case-specific preprocessing to add the necessary inferred values from the context-specific provided inputs.

benjello commented 7 years ago

I disagree on one point: max_nb_cycles is an implicit inference, since it may block the computation toward the past and thus doesn't allow some values to be computed.

For your last remark, I think of the obvious is_permanent for date_naissance but it seems to be treated by the proposal.

My suggestion was to recognize that the need of extrapolating a value to the past or future without having it permanent may be a good option to replace

base_function = requested_period_last_or_next_value
MattiSG commented 7 years ago

Very clear, thank you! I updated #458 accordingly 🙂

Morendil commented 5 years ago

I think we'll want to look at this again in the context of #749 and https://github.com/openfisca/openfisca-france/issues/1211

In Core 24.9.8 and running the YAML tests for France 32.0.1, I disabled the following two lines (commenting them out): https://github.com/openfisca/openfisca-core/blob/400d82f443ec32d2c8782c9f974dabe06c635d5d/openfisca_core/simulations.py#L174-L175

This results in 21 failures, listed below.

The France model as of 32.0.1 has 18 variables with a base_function explicitly assigned:

However, the reliance on base_function is much broader, as variables of types other than int and float are assigned the base function requested_period_last_value by default.

ERROR:openfisca_core.tools.test_runner:aides_logement_2018.yaml: aides_logement_2018_01 - 2018-01
ERROR:openfisca_core.tools.test_runner:exoneration_cotisations_employeur_apprenti.yaml: exoneration_cotisations_employeur_apprenti - 2015-03
ERROR:openfisca_core.tools.test_runner:exoneration_cotisations_employeur_zrd.yaml: Exonération cotisations employeur zone de restructuration défense (ZRD) : SMIC - 2014
ERROR:openfisca_core.tools.test_runner:exoneration_cotisations_employeur_zrr.yaml: Exonération cotisations employeur zone de revitalisation rurale (ZRR) - 1.4 SMIC - 2014
ERROR:openfisca_core.tools.test_runner:exoneration_is_creation_zrr.yaml: Exonération d'impôt sur les sociétés pour les créations en zone de revitalisation rurale (ZRR) - 2014
ERROR:openfisca_core.tools.test_runner:garde_alternee.yaml: Infer from future values - 2015-04
ERROR:openfisca_core.tools.test_runner:remuneration_apprenti.yaml: remuneration_apprenti - 2015-03
ERROR:openfisca_core.tools.test_runner:rsa.yaml: RSA Cas N°7 - 2018-05
ERROR:openfisca_core.tools.test_runner:rsa.yaml: RSA Cas N°8 - 2018-05
ERROR:openfisca_core.tools.test_runner:rsa_2017.yaml: Parent isolé, majoration et déduction de l'ASF - 2017-01
ERROR:openfisca_core.tools.test_runner:rsa_2017.yaml: Effets figés introduits en 2017 (exemple inspiré du suivi législatif) - 2017-01
ERROR:openfisca_core.tools.test_runner:rsa_couple.yaml: RSA couple, salaire_net = [5000, 0] - 2014
ERROR:openfisca_core.tools.test_runner:test_mes_aides_54212b32fb35830200b31327.yaml: [patrimoine, rsa] Montant soustrait de 50% de la valeur locative des biens immobiliers non loués - 2014-09
ERROR:openfisca_core.tools.test_runner:test_mes_aides_54212b9dfb35830200b3132e.yaml: [patrimoine, rsa] Montant soustrait de 80% de la valeur locative des terrains non loués - 2014-09
ERROR:openfisca_core.tools.test_runner:test_mes_aides_542134d3fb35830200b31345.yaml: [patrimoine, rsa] Base ressource RSA - 2014-09
ERROR:openfisca_core.tools.test_runner:test_mes_aides_5421356afb35830200b3134c.yaml: [patrimoine, rsa] Montant soustrait de 3% des revenus théoriques de l'épargne ne générant pas de revenus - 2014-09
ERROR:openfisca_core.tools.test_runner:test_mes_aides_54367da883a4916e4d5a13a3.yaml: [base ressources, cmu-c/acs, patrimoine] La valeur locative des biens immobiliers non loués est prise en compte à 50% - 2014-10
ERROR:openfisca_core.tools.test_runner:test_mes_aides_5436807f2f6a1b774dad2a71.yaml: [base ressources, cmu-c/acs, patrimoine] La valeur locative des terrains non loués est prise en compte à 80% - 2014-10
ERROR:openfisca_core.tools.test_runner:test_mes_aides_545a3741d550a12d2ae7b68c.yaml: [rsa] 2_Patrimoine sur livret - 2014-11
ERROR:openfisca_core.tools.test_runner:test_mes_aides_546490a716951c7e7065a5a1.yaml: [aspa, base ressources, patrimoine] Prise en compte à 3% de la valeur vénale des résidences secondaires - 2014-11
ERROR:openfisca_core.tools.test_runner:test_mes_aides_54bfdaf4d337b5d372377d30.yaml: [patrimoine, rsa] 119_Immeuble non loué - 2015-01

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'aides_logement@2018: '[293.52] differs from [3522.] with an absolute margin [3228.48] > 1

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'apprenti@2015-01: '[0.] differs from [1.] with an absolute margin [1.] > 0

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'exoneration_cotisations_employeur_zrd@2015-01: '[0.] differs from [409.5622] with an absolute margin [409.5622] > 0.005

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'exoneration_cotisations_employeur_zrr@2015-01: '[0.] differs from [541.759] with an absolute margin [541.759] > 0.005

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'exoneration_is_creation_zrr@2015: '[0.] differs from [1.] with a relative margin [1.] > [1.e-04]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'garde_alternee@2015-04: '[0.] differs from [1.] with an absolute margin [1.] > 0

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'apprenti@2015-01: '[0.] differs from [1.] with an absolute margin [1.] > 0

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'rsa@2018-05: '[444.06046] differs from [560.17] with an absolute margin [116.10953] > 0.03

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'rsa@2018-05: '[335.2269] differs from [521.42] with an absolute margin [186.19308] > 0.03

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2017-01: '[491.26157] differs from [676.3] with a relative margin [185.03842] > [6.7629995]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2017-01: '[217.67842] differs from [376.9] with a relative margin [159.22157] > [7.5379996]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 48, in assert_near
    diff, absolute_error_margin)
AssertionError: b'rsa_forfait_logement@2014-06: '[0.] differs from [119.83] with an absolute margin [119.83] > 0.005

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2014-09: '[448.184] differs from [48.18] with a relative margin [400.004] > [0.9636]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2014-09: '[448.184] differs from [128.18] with a relative margin [320.004] > [2.5635998]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2014-09: '[448.184] differs from [364.85] with a relative margin [83.333984] > [7.297]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2014-09: '[448.184] differs from [373.18] with a relative margin [75.004] > [7.4635997]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'cmu_c@2014-10: '[1.] differs from [0.] with a relative margin [1.] > [0.]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'cmu_c@2014-10: '[1.] differs from [0.] with a relative margin [1.] > [0.]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2014-11: '[448.184] differs from [398.18] with a relative margin [50.003998] > [7.9635997]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'aspa@2014-11: '[400.] differs from [0.] with a relative margin [400.] > [0.]

======================================================================
FAIL: unittest.case.FunctionTestCase (check)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 153, in check
    _run_test(period_str, test, verbose, only_variables, ignore_variables, options)
  File "/app/openfisca-core/openfisca_core/tools/test_runner.py", line 250, in _run_test
    relative_error_margin = relative_error_margin,
  File "/app/openfisca-core/openfisca_core/tools/__init__.py", line 52, in assert_near
    diff, abs(relative_error_margin * target_value))
AssertionError: b'rsa@2015-01: '[452.21442] differs from [243.88] with a relative margin [208.33441] > [4.8776]