Tracer

class openfisca_core.tracers.SimpleTracer[source]

A simple tracer that records a stack of traces.

record_calculation_end()[source]

Record the end of a calculation.

Return type:

None

Examples

>>> from openfisca_core import tracers
>>> tracer = tracers.SimpleTracer()
>>> tracer.record_calculation_start("variable", 2020)
>>> tracer.record_calculation_end()
>>> tracer.stack
[]
record_calculation_result(value)[source]

Ignore calculation result.

Return type:

None

record_calculation_start(variable, period)[source]

Record the start of a calculation.

Parameters:
  • variable (NewType(VariableName, str)) – The variable being calculated.

  • period (Union[NewType(PeriodInt, int), Period]) – The period for which the variable is being calculated.

Return type:

None

Examples

>>> from openfisca_core import tracers
>>> tracer = tracers.SimpleTracer()
>>> tracer.record_calculation_start("variable", 2020)
>>> tracer.stack
[{'name': 'variable', 'period': 2020}]
record_parameter_access(parameter, period, value)[source]

Ignore parameter access.

Return type:

None

property stack: list[SimpleTraceMap]

Return the stack of traces.

class openfisca_core.tracers.TraceNode(name, period, parent=None, children=<factory>, parameters=<factory>, value=None, start=0.0, end=0.0)[source]

A node in the tracing tree.

append_child(node)[source]

Append a child to the node.

Return type:

None

calculation_time(round_=True)[source]

Calculate the time spent in the node.

Parameters:

round – Whether to round the result.

Returns:

float – The time spent in the node.

Return type:

float

Examples

>>> from openfisca_core import tracers
>>> node = tracers.TraceNode("variable", 2020)
>>> node.start = 1.123122313
>>> node.end = 1.12312313123
>>> node.calculation_time()
8.182e-07
>>> node.calculation_time(round_=False)
8.182299999770493e-07
children: list[TraceNode]

The children of the node.

end: float = 0.0

The end time of the node.

formula_time()[source]

Calculate the time spent on the formula.

Returns:

float – The time spent on the formula.

Return type:

float

Examples

>>> from openfisca_core import tracers
>>> node = tracers.TraceNode("variable", 2020)
>>> node.start = 1.123122313 * 11
>>> node.end = 1.12312313123 * 11
>>> child = tracers.TraceNode("variable", 2020)
>>> child.start = 1.123122313
>>> child.end = 1.12312313123
>>> for i in range(10):
...     node.children = [child, *node.children]
>>> node.formula_time()
8.182e-07
name: str

The name of the node.

parameters: list[TraceNode]

The parameters of the node.

parent: None | TraceNode = None

The parent of the node.

period: Union[NewType(PeriodInt, int), Period]

The period of the node.

static round(time)[source]

Keep only 4 significant figures.

Parameters:

time (float) – The time to round.

Returns:

float – The rounded time.

Return type:

float

Examples

>>> from openfisca_core import tracers
>>> tracers.TraceNode.round(0.000123456789)
0.0001235
start: float = 0.0

The start time of the node.

value: None | ndarray[Any, dtype[generic]] = None

The value of the node.