PolicyEngine / PolicyEngine/policyengine-core
Proposal: versioned computation trace export for household calculations
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 22
- Forks
- 30
- Avg merge
- 14h 33m
- Merged PRs (30d)
- 7
Description
I have been testing PolicyEngine's existing tracing machinery for downstream audit and conformance workflows. The current FullTracer/FlatTrace API already exposes the core information needed for a deterministic trace export: calculation nodes, dependencies, parameter reads, values, branches, periods, and timings.
Would maintainers consider a small, versioned export API over the existing trace data, for example:
sim = Simulation(situation=situation, trace=True)
sim.calculate("snap", "2024-01")
trace = sim.tracer.to_trace(format="policyengine.trace.v1")
Minimum useful fields
format: a stable format/version string, such aspolicyengine.trace.v1engine:policyengine-coreversion, model package name/version, and optionally git revisioncalculation: requested variable, period, branch, and entity/count metadatanodes: dependency-ordered calculation nodes withid,variable,period,branch,dependencies,parameters,value, and optional timing fieldsparameters: accessed parameter names, instants/effective dates, scalar/vector values or summaries, and source/version metadata where available
Why this may be useful
- Audit trails for household-level calculations
- Debugging and reproducible explanation of why a calculation changed
- Cross-engine comparison where result equality is not enough and users need to compare calculation paths
- Downstream documentation or conformance formats without requiring PolicyEngine to adopt those formats directly
Local evidence (SNAP household)
policyengine-core==3.28.0@f761573c2a13adecc3826be04af1980d13657e1dpolicyengine-us==1.755.5@fc64cef64ab55c3c48309c7fb304c35e5f3c9184- Household SNAP result:
snap [291.0] - Trace shape: one root tree, 2,833 serialized flat-trace nodes
- Root dependencies:
takes_up_snap_if_eligible,snap_normal_allotment,snap_emergency_allotment, anddc_snap_temporary_local_benefit
I also built a small external prototype that projects sim.tracer.get_serialized_flat_trace() into a dependency-ordered trace document and validates it against a downstream JSON Schema (2,833 steps / 164 inferred leaf inputs). That is evidence the existing tracer already has enough structure for a stable export; it is not a request that PolicyEngine support that downstream schema.
Questions
- Would a versioned
FullTracer.to_trace()orSimulation.to_trace()helper be welcome inpolicyengine-core? - Should this live as a JSON-compatible export only, or should PolicyEngine expose a typed Python dataclass layer first?
- What model/package version metadata should be considered stable enough for a trace export?
- Is parameter source/version metadata available today in a form maintainers would be comfortable exposing?
Out of scope
- No runtime AI or explanation generation
- No replacement for PolicyEngine's native formulas or tests
- No normative external schema dependency
- No claim that microsimulation traces are cheap enough for population-scale use
Evidence packet (external): https://github.com/edithatogo/rulesandprocesses/tree/main/external/policyengine
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing FullTracer, FlatTrace, and get_serialized_flat_trace() interfaces described in the issue, then compare them with the external prototype and its downstream JSON Schema validation. The open design questions are the export format, metadata stability, typed versus JSON-compatible API, and parameter source/version exposure; maintainers would need to define these before implementation can be considered done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100