Kedro-Viz Documentation

repository·main·Indexed 20 days ago

https://github.com/kedro-org/kedro-viz

Kedro-Viz is an interactive development tool for visualizing and inspecting Kedro data science pipelines. It provides an interface for exploring pipeline structures, metadata, and execution results. It can be installed as a Kedro plugin, used as a standalone React component via @quantumblack/kedro-viz, or accessed through a Visual Studio Code extension. The tool includes a CLI for launching the visualization server, deploying to cloud platforms, and building static directories.

Tokens
24.3K
Snippets
90
Records
136
Agent score
72%

What's inside Kedro-Viz

  1. Understand the Data Ingestion modular pipeline

    main

    The data_ingestion pipeline is a modular component designed to transform raw data into structured, typed, and aggregated domain-level tables.

    Workflow Steps:

    1. Intermediate Level: Takes raw companies, shuttles, and reviews data and creates typed Parquet mirrors at the intermediate level.
    2. Aggregation: Aggregates companies data to ensure a single row per company.
    3. Primary Domain Level: Merges the three sources to create two specific primary tables:
      • prm_spine_table: Contains only relevant ID columns at the required grain. This table serves as the foundation for all subsequent feature and model_input tables, ensuring they maintain the same row count and column alignment.
      • prm_shuttle_company_reviews: Contains metrics intended for use as features or model inputs later in the pipeline.
  2. Overview of the Backend Architecture

    main

    The Kedro-Viz backend acts as the data provider and API layer for Kedro projects. Its primary responsibilities include:

    • Data Access: The DataAccessManager interfaces with Repositories to fetch and structure data from the Kedro project.
    • REST API: Exposes endpoints for pipeline structures and node-specific metadata to the frontend.
    • CLI & Deployment: Provides a CLI for users to launch the visualization and supports building/deploying to static website hosting platforms.
  3. How Kedro-Viz data loading works

    main

    Kedro-Viz uses a string data token to determine its data source. Depending on the token, it uses different loading strategies:

    1. Bundled Data: Tokens like "test" or "demo" synchronously import mock JSON files from /src/utils/data/. Randomly generated data can be seeded using a seed query string in the URL to ensure reproducible layouts.
    2. Asynchronous/External Data: In production or when using the "json" identifier, the app fetches data from API endpoints:
      • Pipeline Endpoints: Located at /api/pipeline/<id>. Loading a pipeline resets the pipeline state in the Redux store. The app defaults to /api/main (the 'default' pipeline) on first load.
      • Node Endpoints: Located at /api/nodes/<id>. These are called asynchronously when a user selects a node to populate the metadata panel.
  4. Understand the Kedro-Viz Node concept

    main

    In Kedro-Viz, a 'node' is a visual graph element used for rendering the flowchart. It is distinct from a standard Kedro node and can represent one of three types:

    • task: A Kedro node (a Python function wrapper).
    • data: A dataset.
    • parameter: A reusable configuration variable.

    An edge represents the link (input/output) between two of these nodes.

  5. Understand the modelling pipeline structure

    main

    The modelling pipeline in this demo project manages the core machine learning lifecycle, specifically the split, train, and test stages.

    Key architectural patterns used:

    • Parametrized Data Splitting: The split_data method is designed to take parameters to generate a single source for both train and test datasets.
    • Modular Pipeline Pattern: The pipeline uses Kedro's modular pattern to instantiate multiple versions of training and evaluation pipelines. In this example, it instantiates two separate pipelines using different Scikit-learn regressors: Random Forest and Linear Regression.
  6. Understand the Kedro Viz saved data directory structure

    main

    When you use the --save-file <path> option with kedro viz run, or when you use kedro viz build, Kedro Viz generates a specific directory structure. This structure can be reloaded later using the --load-file <path> option in the kedro viz run command.

    The structure consists of:

    • api/main: The main file containing the pipeline structure.
    • api/nodes/: Contains JSON files for individual nodes (e.g., node1, node2).
    • api/pipelines/: Contains JSON files for individual pipelines (e.g., pipeline1, pipeline2).
    api/
    ├── main       # Main file containing pipeline structure
    ├── nodes/
    │   ├── node1           # JSON files for individual nodes
    │   ├── node2
    │   └── ...
    ├── pipelines/
    │   ├── pipeline1      # JSON files for individual pipelines
    │   ├── pipeline2
    │   └── ...
  7. How the Kedro-Viz graph layout engine works

    main

    The Kedro-Viz layout engine treats graph drawing as a constrained optimization problem. It aims to find node positions ($N$) and edge paths ($E$) that satisfy a set of geometric rules while minimizing the distance between connected nodes.

    To maintain performance and flexibility, the engine makes two key architectural simplifications:

    1. Axis Independence: Node positions in the X and Y axes are treated as independent variables. A node can move in X without affecting its Y position.
    2. Decoupled Routing: The problem of determining node positions (layout) is solved independently from the problem of drawing edge paths (routing).

    The engine uses a two-stage solving process to balance speed and accuracy:

    • Loose Solver: A fast, approximate soft-constraint solver that handles hundreds of thousands of constraints using objective/loss functions. It provides a quick initial layout.
    • Strict Solver: A slower, exact hard-constraint solver (based on the kiwi.js / Cassowary library) that handles a reduced set of constraints derived from the loose solver. It ensures a complete, mathematically exact solution for linear constraints.

    By combining both, Kedro-Viz achieves a layout that strongly respects constraints within a short processing time.

  8. Manage permissions and billing for AWS hosting

    main

    When hosting Kedro-Viz on AWS, keep the following in mind:

    • Permissions: Kedro-Viz does not manage access control. You must use AWS IAM policies or S3 Access Control Lists (ACLs) to control who can view your visualization (e.g., restricting access to specific IPs or users).
    • Billing: Kedro-Viz does not handle billing. You are responsible for AWS costs associated with S3 storage, which depend on object size, storage duration, and the chosen storage class.
  9. Apply typography and unit standards

    main

    Typography

    Wrap all text elements in a .kedro class. This class establishes a base font-size of 10px, allowing all other font sizes to be set relatively using em (where 1em = 10px). This ensures consistent typography regardless of the parent application's styles.

    Units

    • Use em for styles dependent on font-size (e.g., text margins).
    • Use % for relative layout positioning.
    • Use px for absolute layout positioning.
    • Do not use rem or viewport units (vh/vw/vmin/vmax) in code intended for the package library, as these can cause side-effects in the host application.
  10. Supported node preview types in Kedro-Viz

    main

    Kedro-Viz supports three distinct types of node previews:

    1. Mermaid preview: Renders Mermaid.js visualizations such as flowcharts, sequence diagrams, and process flows. This is ideal for visualizing internal decision logic or workflows within a node.
    2. Text preview: Displays text summaries, logs, usage examples, or testing information. It supports code snippets and syntax highlighting.
    3. Image preview: Displays static diagrams, charts, or reference images using either URLs or base64-encoded data URIs.
  11. How state and preferences are persisted

    main

    Kedro-Viz uses the browser's window.localStorage API to persist user preferences across sessions. This includes settings such as:

    • Node, tag, layer, sidebar, and label visibility
    • UI flags
    • Selected theme
    • The active pipeline

    The localStorage state is automatically updated via a Redux store subscriber whenever the store changes.