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.
- 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. IfFalse
, will use remove all the lineapy references and instead use the underlying serializer directly. Currently, we use the nativepickle
serializer.keep_lineapy_save – Whether to retain
lineapy.save()
in code slice. Defaults toFalse
.
- 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. IfFalse
, will use remove all the lineapy references and instead use the underlying serializer directly. Currently, we use the nativepickle
serializer.
- name: str
name of the artifact
- 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.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 toFalse
.
- 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 toFalse
.
- 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.