lineapy.graph_reader package

Submodules

lineapy.graph_reader.api_utils module

lineapy.graph_reader.api_utils.de_lineate_code(code: str, db: RelationalLineaDB) str[source]

De-linealize the code by removing any lineapy api references

lineapy.graph_reader.apis module

User exposed objects through the lineapy.apis.

class lineapy.graph_reader.apis.LineaArtifact(db: RelationalLineaDB, _execution_id: LineaID, _node_id: LineaID, _session_id: LineaID, name: str, _version: int, date_created: Optional[datetime] = None)[source]

exposes functionalities we offer around the artifact.

date_created: Optional[datetime] = None

Optional because date_created cannot be set by the user. it is supposed to be automatically set when the artifact gets saved to the db. so when creating lineaArtifact the first time, it will be unset. When you get the artifact or catalog of artifacts, we retrieve the date from db and it will be set.

execute() object[source]

Executes the artifact graph.

get_code(use_lineapy_serialization: bool = True, keep_lineapy_save: bool = False) str[source]

Return the slices code for the artifact

Parameters
  • use_lineapy_serialization – If True, will use the lineapy serialization to get the code. We will hide the serialization and the value pickler irrespective of the value type. If False, will use remove all the lineapy references and instead use the underlying serializer directly. Currently, we use the native pickle serializer.

  • keep_lineapy_save – Whether to retain lineapy.save() in code slice. Defaults to False.

get_session_code(use_lineapy_serialization=True) str[source]

Return the raw session code for the artifact. This will include any comments and non-code lines.

Parameters

use_lineapy_serialization – If True, will use the lineapy serialization to get the code. We will hide the serialization and the value pickler irrespective of the value type. If False, will use remove all the lineapy references and instead use the underlying serializer directly. Currently, we use the native pickle serializer.

get_value() object[source]

Get and return the value of the artifact

name: str

name of the artifact

visualize(path: Optional[str] = None) None[source]

Displays the graph for this artifact.

If a path is provided, will save it to that file instead.

class lineapy.graph_reader.apis.LineaCatalog(db)[source]

A simple way to access meta data about artifacts in Linea

property export

a dictionary of artifact information, which the user can then manipulate with their favorite dataframe tools, such as pandas, e.g., cat_df = pd.DataFrame(catalog.export()).

Type

return

lineapy.graph_reader.graph_printer module

class lineapy.graph_reader.graph_printer.GraphPrinter(graph: Graph, include_source_location: bool = True, include_id_field: bool = True, include_session: bool = True, include_imports: bool = False, include_timing: bool = True, nest_nodes: bool = True, id_to_attribute_name: Dict[LineaID, str] = <factory>, node_type_to_count: Dict[NodeType, int] = <factory>, source_code_count: int = 0)[source]

Pretty prints a graph, in a similar way as how you would create it by hand.

This representation should be consistent despite UUIDs being different.

lineapy.graph_reader.graph_printer.pretty_print_node_type(type: NodeType) str[source]

Turns a node type into something that can be used as a variable name.

lineapy.graph_reader.graph_printer.pretty_print_str(s: str) str[source]

Pretty prints a string, so that if it has a newline, prints it as a triple quoted string.

lineapy.graph_reader.program_slice module

class lineapy.graph_reader.program_slice.CodeSlice(import_lines: List[str], body_lines: List[str])[source]
lineapy.graph_reader.program_slice.get_program_slice(graph: Graph, sinks: List[LineaID], keep_lineapy_save: bool = False) CodeSlice[source]

Find the necessary and sufficient code for computing the sink nodes.

Parameters
  • graph – The computation graph.

  • sinks – Artifacts to get the code slice for.

  • keep_lineapy_save – Whether to retain lineapy.save() in code slice. Defaults to False.

Returns

String containing the necessary and sufficient code for computing sinks.

lineapy.graph_reader.program_slice.get_slice_graph(graph: Graph, sinks: List[LineaID], keep_lineapy_save: bool = False) Graph[source]

Takes a full graph from the session and produces the subset responsible for the “sinks”.

Parameters
  • graph – A full graph objection from a session.

  • sinks – A list of node IDs desired for slicing.

  • keep_lineapy_save – Whether to retain lineapy.save() in code slice. Defaults to False.

Returns

A subgraph extracted (i.e., sliced) for the desired node IDs.

lineapy.graph_reader.program_slice.get_source_code_from_graph(program: Graph) CodeSlice[source]

Returns the code from some subgraph, by including all lines that are included in the graphs source.

Todo

We need better analysis than just looking at the source code. For example, what if we just need one expression from a line that defines multiple expressions?

We should probably instead regenerate the source from our graph representation.

Module contents