PolicyEngine / PolicyEngine/policyengine-core

`restore_simulation` silently drops memberless group entities

Open Beginner friendly
#547 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
22
Forks
30
Avg merge
14h 33m
Merged PRs (30d)
7

Description

policyengine_core/tools/simulation_dumper.py (inherited verbatim from openfisca-core) rebuilds entity counts from the members mapping instead of the dumped ids:

person_count = len(population.members_entity_id)
population.count = max(population.members_entity_id) + 1

Consequences, all verified against the equivalent code in openfisca-core:

  1. A group entity with no member is silently dropped from the restored simulation's count, while still listed in its ids — an internally inconsistent state. Calculations on the restored simulation then return arrays with one entity missing, with no error. If a value was stored for the group entity, restoring instead fails with ValueError: length is N while there are N-1 ….
  2. A tax-benefit system with no group entity cannot be restored at all: person_count is never assigned and restore_simulation raises UnboundLocalError.

Upstream report and reference fix (restore each entity's count from its own dumped id.npy, which also removes the person_count plumbing): openfisca/openfisca-core#1387.

Happy to open the twin PR here if useful.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in policyengine_core/tools/simulation_dumper.py at restore_simulation, then compare the inherited implementation with the reference fix in openfisca/openfisca-core#1387. Done means restored entity counts match the dumped ids, memberless group entities remain present, and simulations without group entities restore without UnboundLocalError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.