Skip to content

Pipeline viz #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
67d430c
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Jun 25, 2024
e965499
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Jun 26, 2024
ed0baa7
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Jul 3, 2024
ea232ff
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Jul 16, 2024
43c7b3c
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python in…
stellasia Jul 17, 2024
8367daa
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Aug 1, 2024
3c3c00e
Merge remote-tracking branch 'origin/main'
stellasia Aug 1, 2024
7182523
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Aug 6, 2024
212a5a3
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Aug 13, 2024
32364c6
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Aug 29, 2024
f481025
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Sep 3, 2024
56435bf
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Sep 3, 2024
2b21340
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python
stellasia Sep 4, 2024
74f7d0b
Save input configs in the Pipeline class while validating, and reuse …
stellasia Sep 5, 2024
059a302
Split the parameter connection validation and the user input validati…
stellasia Sep 5, 2024
f8696b6
WIP: pipeline visualization
stellasia Sep 5, 2024
195f249
Invalidate the pipeline param mapping if the graph structure changes
stellasia Sep 5, 2024
a9aee54
Hide unused outputs by default but add option to display them
stellasia Sep 5, 2024
77b2eb0
Install graphviz during CI
stellasia Sep 5, 2024
e6c2c10
Install graphviz-dev in CI to fix installation error
stellasia Sep 5, 2024
1202484
Update changelog and doc
stellasia Sep 6, 2024
43d6556
Add a few tests for data validation
stellasia Sep 6, 2024
604fa5f
Merge branch 'main' of https://github.com/neo4j/neo4j-genai-python in…
stellasia Sep 6, 2024
93a11ec
Fix error message
stellasia Sep 6, 2024
7c5b9f9
This is a change of behavior that will be implemented in a separate PR
stellasia Sep 8, 2024
6155341
Merge with main
stellasia Sep 8, 2024
0261788
Add UT for pipeline to pygraphviz format and pipeline draw method
stellasia Sep 9, 2024
ee1a2cd
Fix docstring
stellasia Sep 10, 2024
7a88268
Merge with main
stellasia Sep 10, 2024
4494799
Improve naming and docstrings
stellasia Sep 10, 2024
b9e3c66
Update CHANGELOG.md
stellasia Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pr-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
- 7474:7474

steps:
- name: Install graphviz package
run: sudo apt install graphviz graphviz-dev
- name: Check out repository code
uses: actions/checkout@v4
- name: Docker Prune
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
steps:
- name: Install graphviz package
run: sudo apt install graphviz graphviz-dev
- name: Check out repository code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/scheduled-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}

steps:
- name: Install graphviz package
run: sudo apt install graphviz graphviz-dev
- name: Check out repository code
uses: actions/checkout@v4
- name: Docker Prune
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

## Next

## Fixed
### Added
- Ability to visualise pipeline with `my_pipeline.draw("pipeline.png")`

### Fixed
- Pipelines now return correct results when the same pipeline is run in parallel.

### Changed
- Pipeline run method now return a PipelineResult object.


## 0.5.0

### Added
Expand Down
Binary file added docs/source/images/pipeline_full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions docs/source/user_guide_pipeline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,38 @@ The data flow is illustrated in the diagram below:
asyncio.run(pipe.run({"a": {"number1": 10, "number2": 1}, "b": {"number1": 4, "number2": 42}}))

The result will still be **15** because the user input `"number2": 42` is ignored.


**********************
Visualising a Pipeline
**********************

Pipelines can be visualized using the `draw` method:

.. code:: python

import asyncio
from neo4j_genai.experimental.pipeline import Pipeline

pipe = Pipeline()
# ... define components and connections

pipe.draw("pipeline.png")

Here is an example pipeline rendering:

.. image:: images/pipeline_no_unused_outputs.png
:alt: Pipeline visualisation with hidden outputs if unused


By default, output fields which are not mapped to any component are hidden. They
can be added to the canvas by setting `hide_unused_outputs` to `False`:

.. code:: python

pipe.draw("pipeline.png", hide_unused_outputs=False)

Here is an example of final result:

.. image:: images/pipeline_full.png
:alt: Pipeline visualisation
58 changes: 58 additions & 0 deletions examples/pipeline/visualization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) "Neo4j"
# Neo4j Sweden AB [https://neo4j.com]
# #
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# #
# https://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This example illustrates how to visualize a Pipeline"""

from neo4j_genai.experimental.pipeline import Component, Pipeline
from neo4j_genai.experimental.pipeline.component import DataModel
from pydantic import validate_call


class IntDataModel(DataModel):
value: int
message: str


class Addition(Component):
async def run(self, a: int, b: int) -> IntDataModel:
return IntDataModel(value=a + b, message="addition complete")


class Duplicate(Component):
def __init__(self, factor: int = 2) -> None:
self.factor = factor

async def run(self, number: int) -> IntDataModel:
return IntDataModel(
value=number * self.factor, message=f"multiplication by {self.factor} done"
)


class Save(Component):
@validate_call
async def run(self, number: IntDataModel) -> IntDataModel:
return IntDataModel(value=number.value, message="saved")


if __name__ == "__main__":
pipe = Pipeline()
pipe.add_component(Duplicate(), "times_two")
pipe.add_component(Duplicate(factor=10), "times_ten")
pipe.add_component(Addition(), "addition")
pipe.add_component(Save(), "save")
pipe.connect("times_two", "addition", {"a": "times_two.value"})
pipe.connect("times_ten", "addition", {"b": "times_ten.value"})
pipe.connect("addition", "save", {"number": "addition"})
pipe.draw("graph.png")
pipe.draw("graph_full.png", hide_unused_outputs=False)
1,429 changes: 745 additions & 684 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ pinecone-client = {version = "^4.1.0", optional = true}
types-mock = "^5.1.0.20240425"
eval-type-backport = "^0.2.0"
pypdf = "^4.3.1"
pygraphviz = [
{version = "^1.13.0", python = ">=3.10,<4.0.0"},
{version = "^1.0.0", python = "<3.10"}
]

[tool.poetry.group.dev.dependencies]
pylint = "^3.1.0"
Expand Down
Loading