lineapy.utils package
Subpackages
Submodules
lineapy.utils.benchmarks module
Utilities for computing statistics on benchmark data.
Translated from https://github.com/jupyterlab/jupyterlab/blob/82df0b635dae2c1a70a7c41fe7ee7af1c1caefb2/galata/src/benchmarkReporter.ts#L150-L244 which was originally added in https://github.com/jupyterlab/benchmarks/blob/f55db969bf4d988f9d627ba187e28823a50153ba/src/compare.ts#L136-L213
- lineapy.utils.benchmarks.distribution_change(old_measures: List[float], new_measures: List[float], confidence_interval: float = 0.95) DistributionChange [source]
Compute the performance change based on a number of old and new measurements.
Based on the work by Tomas Kalibera and Richard Jones. See their paper “Quantifying Performance Changes with Effect Size Confidence Intervals”, section 6.2, formula “Quantifying Performance Change”.
Note: The measurements must have the same length. As fallback, you could use the minimum size of the two measurement sets.
- Parameters
old_measures – The list of timings from the old system
new_measures – The list of timings from the new system
confidence_interval – The confidence interval for the results. The default is a 95% confidence interval (95% of the time the true mean will be between the resulting mean +- the resulting CI)
# Test against the example in the paper, from Table V, on pages 18-19
>>> res = distribution_change( ... old_measures=[ ... round(mean([9, 11, 5, 6]), 1), ... round(mean([16, 13, 12, 8]), 1), ... round(mean([15, 7, 10, 14]), 1), ... ], ... new_measures=[ ... round(mean([10, 12, 6, 7]), 1), ... round(mean([9, 1, 11, 4]), 1), ... round(mean([8, 5, 3, 2]), 1), ... ], ... confidence_interval=0.95 ... ) >>> from math import isclose >>> assert isclose(res.mean, 68.3 / 74.5, rel_tol=0.05) >>> assert isclose(res.confidence_interval, 60.2 / 74.5, rel_tol=0.05)
lineapy.utils.config module
lineapy.utils.constants module
- lineapy.utils.constants.VERSION_DATE_STRING = '%Y-%m-%dT%H:%M:%S'
sqlalchemy defaults to a type of Optional[str] even when a column is set to be not nullable. This is per their documentation. One option is to add type:ignore for python objects that should not be nulls and are mapped to sqlalchemy ORM objects. Alternately, as is here, we can add a placeholder. This will be used like
obj.property = ormobject.property or placeholder
. This should separate out the ORM objects and their policy of setting all columns to be Optional vs app objects that should reflect the app’s expectation of not allowing nulls. The app object’s property does not get set to None and the ORM object doesn’t need to worry about knowing what the app is doing.
lineapy.utils.deprecation_utils module
- lineapy.utils.deprecation_utils.get_source_segment(source, node, padded=False)[source]
Get source code segment of the source that generated node.
Note
This is a polyfill for the ast.get_source_segment function that was introduced in python 3.8.
If some location information (lineno, end_lineno, col_offset, or end_col_offset) is missing, return None.
If padded is True, the first line of a multi-line statement will be padded with spaces to match its original position.
lineapy.utils.lineabuiltins module
- lineapy.utils.lineabuiltins.l_dict(*keys_and_values: Union[Tuple[K, V], Tuple[_DictKwargsSentinel, Mapping[K, V]]]) Dict[K, V] [source]
Build a dict from a number of key value pairs.
There is a special case for dictionary unpacking. In this case, the key will be an instance of _DictKwargsSentinel.
For example, if the user creates a dict like
{1: 2, **d, 3: 4}
, then it will create a call like:l_dict((1, 2), (l_dict_kwargs_sentinel(), d), (3, 4))
We use a sentinel value instead of None, because None can be a valid dictionary key.
- lineapy.utils.lineabuiltins.l_exec_expr(code: str) object [source]
Executes code expressions. These typically are ast nodes that inherit from ast.expr. Examples include ast.ListComp, ast.Lambda
Execute the code with input_locals set as locals, and returns a list of the output_locals pulled from the environment.
- Returns
it will return the result as well as the last argument.
- lineapy.utils.lineabuiltins.l_exec_statement(code: str) None [source]
Executes code statements. These typically are ast nodes that inherit from ast.stmt. Examples include ast.ClassDef, ast.If, ast.For, ast.FunctionDef, ast.While, ast.Try, ast.With
Execute the code with input_locals set as locals, and returns a list of the output_locals pulled from the environment.
- Returns
None. Since the code is a statement, it will not return anything
- lineapy.utils.lineabuiltins.l_import(name: str, base_module: Optional[module] = None) module [source]
Imports and returns a module. If the base_module is provided, the module will be a submodule of the base.
If a base_module is provided, the base_module will be flagged as ‘mutated’ by our annotations.
- lineapy.utils.lineabuiltins.l_unpack_ex(xs: Iterable[T], before: int, after: int) List[Union[T, List[T]]] [source]
Slits the iterable xs into three pieces and then joins them [*first, middle, *list] The first of length before, the last of length after, and the middle whatever is remaining.
Modeled after the UNPACK_EX bytecode to be used in unpacking.
- lineapy.utils.lineabuiltins.l_unpack_sequence(xs: Iterable[T], n: int) List[T] [source]
Asserts the iterable xs is of length n and turns it into a list.
The same as l_list but asserts the length. This was modeled after the UNPACK_SEQUENCE bytecode to be used in unpacking
The result should be a view of the input.
lineapy.utils.logging_config module
Setup logging config for CLI and debugging.
We don’t do this in our init, because if imported as a library we don’t want to mess up others logging configuration.
lineapy.utils.tree_logger module
Logging util for outputting function calls as trees!
This is currently exposed through the –tree-log pytest command, which will log each test case to stdout.
We log every method of the CLASSES, so to change what is logged, modify that list. Also, we color the statements, based on the class, using the CLASS_TO_COLOR mapping.
lineapy.utils.utils module
- lineapy.utils.utils.get_value_type(val: Any) Optional[ValueType] [source]
Got a little hacky so as to avoid dependency on external libraries. Current method is to check if the dependent library is already imported, if they are, then we can reference them.
Note: - Watch out for error here if the Executor tests fail. TODO - We currently just silently ignore cases we cant handle
- lineapy.utils.utils.listify(fn: CALLABLE) CALLABLE [source]
TODO: Once we switch to Python 3.10, we can type this properly https://www.python.org/dev/peps/pep-0612/