Skip to content

Add axes expansion to the Web API for n-parallel axes #1326

@bonjourmauko

Description

@bonjourmauko

Axes are a useful way of showing how variables interact with each other (for example, for multivariate observation).

OpenFisca's Python API already handles this. See, for example, Replicating a situation along axes.

However, the Web API does not know how to handle this. For example, if you run:

curl -X POST "https://api.demo.openfisca.org/latest/calculate" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"persons\":{\"Thomas\":{},\"Mauko\":{}},\"households\":{\"workshop\":{\"adults\":[\"Thomas\",\"Mauko\"],\"total_taxes\":{\"2025-03\":null}}},\"axes\":[[{\"count\":10,\"name\":\"salary\",\"min\":0,\"max\":10000,\"period\":\"2025-03\"}]]}"

You will get the following error:

Traceback (most recent call last):
  File "/openfisca-core/openfisca_web_api/app.py", line 167, in calculate
    result = handlers.calculate(tax_benefit_system, input_data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openfisca-core/openfisca_web_api/handlers.py", line 26, in calculate
    entity_index = population.get_index(entity_id)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openfisca-core/openfisca_core/populations/_core_population.py", line 258, in get_index
    return self.ids.index(id)
           ^^^^^^^^^^^^^^^^^^
ValueError: 'workshop' is not in list

This happens because, upon expansion, entities are expanded the number of times specified in count, and are given incremental names (in our case, workshop0, workshop1, ..., workshop9).

Modelling a JSON response of calculating axes is not trivial, as it depends on two cases:

  1. Parallel: the results are 1-d or 2-d
  2. Perpendicular: the results are 3d+

This request is to implement the JSON serialisation for n-parallel axes expansion, as the corresponding result vectors can be naturally mapped to the current situation schema: entity_plural/entity_instance_id/openfisca_variable_name/period.

cc @guillett @benjello @Morendil

Metadata

Metadata

Assignees

Labels

kind:featA feature request, a feature deprecation

Type

No type

Projects

Status

Inbox

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions